pub trait CompositeEncryptable<Ids: KeySlotIds, Key: KeySlotId, Output> {
// Required method
fn encrypt_composite(
&self,
ctx: &mut KeyStoreContext<'_, Ids>,
key: Key,
) -> Result<Output, CryptoError>;
}Expand description
An encryption operation that takes the input value and encrypts the fields on it recursively. Implementations should generally consist of calling PrimitiveEncryptable::encrypt for all the fields of the type. Sometimes, it is necessary to call CompositeEncryptable::encrypt_composite, if the object is not a flat struct.
Required Methods§
Sourcefn encrypt_composite(
&self,
ctx: &mut KeyStoreContext<'_, Ids>,
key: Key,
) -> Result<Output, CryptoError>
fn encrypt_composite( &self, ctx: &mut KeyStoreContext<'_, Ids>, key: Key, ) -> Result<Output, CryptoError>
§⚠️ IMPORTANT NOTE ⚠️
This is not intended to be used for new designs, and only meant to support old designs.
Composite encryption does not provide integrity over the entire document, just individual
parts of it and is subject to specific tampering attacks where fields can be rearranged
or replaced with fields from other documents. Use crate::safe::DataEnvelope instead!
For a struct made up of many small encstrings, such as a cipher, this takes the struct and recursively encrypts all the fields / sub-structs.
§Contract
The returned value MUST be fully encrypted under key. Implementations MUST NOT reuse
ciphertext embedded in self (for example a still-wrapped per-item key carried over from a
previous decryption); any such key material must be re-derived and re-wrapped under key.
This guarantees that a value produced by Decryptable::decrypt can be re-encrypted under
any valid key and then decrypted with that same key — i.e. decrypt(K) then encrypt(K1)
then decrypt(K1) succeeds.