pub trait Decrypting<'a>: 'a + Deserialize<'a> {
type DecryptedForm: Entity;
// Required method
fn decrypt(
self,
cipher: &Aes256Gcm,
) -> CryptoKeystoreResult<Self::DecryptedForm>;
}Expand description
This trait restores to a plaintext form of this struct, where all sensitive fields have been decrypted.
This is quite likely to be handled automatically by a macro, depending on how annoying it is to implement everywhere.
§Example
ⓘ
// Foo is an Entity
struct Foo {
id: Vec<u8>,
sensitive_data: Vec<u8>, // sensitive!
}
#[derive(serde::Deserialize)]
struct EncryptedFoo<'a> {
id: Vec<u8>,
sensitive_data: &'a [u8],
}
impl<'a> Decrypting<'a> for EncryptedFoo<'a> {
type DecryptedForm = Foo;
fn decrypt(self, cipher: &aes_gcm::Aes256Gcm) -> CryptoKeystoreResult<Foo> {
let id = self.id;
let sensitive_data = Foo::decrypt_data(cipher, &id, self.sensitive_data)?;
Ok(Foo {
id,
sensitive_data,
})
}
}This can then be used like:
ⓘ
let foo = serde_json::from_str::<EncryptedFoo>(json)?.decrypt(cipher)?;Required Associated Types§
type DecryptedForm: Entity
Required Methods§
fn decrypt( self, cipher: &Aes256Gcm, ) -> CryptoKeystoreResult<Self::DecryptedForm>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.