Decryptable

Trait Decryptable 

Source
pub trait Decryptable<'a>: Entity {
    type DecryptableFrom: 'a + Decrypting<'a, DecryptedForm = Self>;
}
Expand description

Helper trait for restoring from an encrypted form of this struct.

This is mainly useful so that the encrypted form does not need to be named, or even nameable.

This is quite likely to be handled automatically by a macro, depending on how annoying it is to implement everywhere.

§Example

Extending the example from Decrypting:

// Foo is an Entity
struct Foo { ... }

#[derive(serde::Serialize)]
struct EncryptedFoo<'de> { ... }

impl<'de> Decrypting<'de> for EncryptedFoo<'de> {
    type DecryptedForm = Foo;
    fn decrypt(self, cipher: &aes_gcm::Aes256Gcm) -> CryptoKeystoreResult<Foo> { ... }
}

impl<'de> Decryptable<'de> for Foo {
    type DecryptableFrom = EncryptedFoo<'de>;
}

EncryptedFoo now no longer needs to appear in external code:

let foo = serde_json::from_str::<Foo::DecryptableFrom>(json)?.decrypt(cipher)?;

Required Associated Types§

Source

type DecryptableFrom: 'a + Decrypting<'a, DecryptedForm = Self>

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.

Implementors§