Encrypting

Trait Encrypting 

Source
pub trait Encrypting<'a> {
    type EncryptedForm: 'a + Serialize;

    // Required method
    fn encrypt(
        &'a self,
        cipher: &Aes256Gcm,
    ) -> CryptoKeystoreResult<Self::EncryptedForm>;
}
Expand description

This trait produces an encrypted form of this struct, where all sensitive fields have been encrypted using the EncryptData helper.

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::Serialize)]
struct EncryptedFoo<'a> {
    id: &'a Vec<u8>,
    sensitive_data: Vec<u8>,
}

impl<'a> Encrypting<'a> for Foo {
    type EncryptedForm: EncryptedFoo<'a>;

    fn encrypt(&'a self, cipher: &aes_gcm::Aes256Gcm) -> CryptoKeystoreResult<EncryptedFoo<'a>> {
        Ok(EncryptedFoo {
            id: &self.id,
            sensitive_data: self.encrypt_data(cipher, &self.sensitive_data)?,
        })
    }
}

This can then be used like:

let json = serde_json::to_string(&foo.encrypt(cipher)?)?;

Required Associated Types§

Source

type EncryptedForm: 'a + Serialize

This type must be serializable, but can depend on the lifetime of self to reduce copying.

Required Methods§

Source

fn encrypt( &'a self, cipher: &Aes256Gcm, ) -> CryptoKeystoreResult<Self::EncryptedForm>

Make an instance of the encrypted form of this struct, for which all sensitive fields have been encrypted.

Implementors§

Source§

impl<'a> Encrypting<'a> for E2eiCrl

Source§

type EncryptedForm = E2eiCrlEncrypt<'a>

Source§

impl<'a> Encrypting<'a> for E2eiIntermediateCert

Source§

type EncryptedForm = E2eiIntermediateCertEncrypt<'a>

Source§

impl<'a> Encrypting<'a> for PersistedMlsGroup

Source§

type EncryptedForm = PersistedMlsGroupEncrypt<'a>

Source§

impl<'a> Encrypting<'a> for ProteusSession

Source§

type EncryptedForm = ProteusSessionEncrypt<'a>

Source§

impl<'a> Encrypting<'a> for StoredBufferedCommit

Source§

type EncryptedForm = StoredBufferedCommitEncrypt<'a>

Source§

impl<'a> Encrypting<'a> for StoredE2eiEnrollment

Source§

type EncryptedForm = StoredE2eiEnrollmentEncrypt<'a>

Source§

impl<'a> Encrypting<'a> for StoredEpochEncryptionKeypair

Source§

type EncryptedForm = StoredEpochEncryptionKeypairEncrypt<'a>

Source§

impl<'a> Encrypting<'a> for StoredKeypackage

Source§

type EncryptedForm = StoredKeypackageEncrypt<'a>