Skip to content

Commit

Permalink
feat: implement scylla traits for StrongSecret (#6500)
Browse files Browse the repository at this point in the history
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
dracarys18 and hyperswitch-bot[bot] authored Nov 14, 2024
1 parent 29be1d4 commit 7d73e90
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 0 deletions.
116 changes: 116 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/masking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ default = ["alloc", "serde", "diesel", "time"]
alloc = ["zeroize/alloc"]
serde = ["dep:serde", "dep:serde_json"]
time = ["dep:time"]
cassandra = ["dep:scylla"]

[package.metadata.docs.rs]
all-features = true
Expand All @@ -27,6 +28,7 @@ subtle = "2.5.0"
time = { version = "0.3.35", optional = true, features = ["serde-human-readable"] }
url = { version = "2.5.0", features = ["serde"] }
zeroize = { version = "1.7", default-features = false }
scylla = { version = "0.14.0", optional = true}

[dev-dependencies]
serde_json = "1.0.115"
Expand Down
50 changes: 50 additions & 0 deletions crates/masking/src/cassandra.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use scylla::{
cql_to_rust::FromCqlVal,
deserialize::DeserializeValue,
frame::response::result::{ColumnType, CqlValue},
serialize::{
value::SerializeValue,
writers::{CellWriter, WrittenCellProof},
SerializationError,
},
};

use crate::{abs::PeekInterface, StrongSecret};

impl<T> SerializeValue for StrongSecret<T>
where
T: SerializeValue + zeroize::Zeroize + Clone,
{
fn serialize<'b>(
&self,
typ: &ColumnType,
writer: CellWriter<'b>,
) -> Result<WrittenCellProof<'b>, SerializationError> {
self.peek().serialize(typ, writer)
}
}

impl<'frame, T> DeserializeValue<'frame> for StrongSecret<T>
where
T: DeserializeValue<'frame> + zeroize::Zeroize + Clone,
{
fn type_check(typ: &ColumnType) -> Result<(), scylla::deserialize::TypeCheckError> {
T::type_check(typ)
}

fn deserialize(
typ: &'frame ColumnType,
v: Option<scylla::deserialize::FrameSlice<'frame>>,
) -> Result<Self, scylla::deserialize::DeserializationError> {
Ok(Self::new(T::deserialize(typ, v)?))
}
}

impl<T> FromCqlVal<CqlValue> for StrongSecret<T>
where
T: FromCqlVal<CqlValue> + zeroize::Zeroize + Clone,
{
fn from_cql(cql_val: CqlValue) -> Result<Self, scylla::cql_to_rust::FromCqlValError> {
Ok(Self::new(T::from_cql(cql_val)?))
}
}
3 changes: 3 additions & 0 deletions crates/masking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ pub mod prelude {
#[cfg(feature = "diesel")]
mod diesel;

#[cfg(feature = "cassandra")]
mod cassandra;

pub mod maskable;

pub use maskable::*;

0 comments on commit 7d73e90

Please sign in to comment.