Struct tindercrypt::metadata::Metadata [−][src]
pub struct Metadata { pub key_deriv_algo: KeyDerivationAlgorithm, pub enc_algo: EncryptionAlgorithm, pub ciphertext_size: usize, }
Expand description
The collection of all encryption-related metadata.
This struct holds all the metadata necessary for the encryption process. The end product of the encryption will contain a serialized version of this struct, so that it can be retrieved during decryption.
Examples
We can serialize the metadata to a buffer and then deserialize them again. The reported size of the serialized metadata and their contents should be the same in both cases:
use tindercrypt::metadata::Metadata; let data = "The cake is a lie"; let meta = Metadata::generate_for_passphrase(data.len()); let (buf, meta_size) = meta.to_buf(); assert_eq!(Metadata::from_buf(&buf)?, (meta, meta_size));
We can also convert the metadata to and from the respective Protocol
Buffers message (proto::metadata::Metadata
):
use tindercrypt::metadata::Metadata; let data = "The cake is a lie"; let meta = Metadata::generate_for_key(data.len()); let proto_meta = meta.to_proto(); assert_eq!(meta, Metadata::from_proto(&proto_meta)?);
Fields
key_deriv_algo: KeyDerivationAlgorithm
The key derivation algorithm to be used.
enc_algo: EncryptionAlgorithm
The encryption algorithm to be used.
ciphertext_size: usize
The size of the ciphertext.
Note that depending on the encryption algorithm used, the ciphertext may also contain its digest. So, this value also takes the digest into account.
Implementations
pub fn new(
key_deriv_algo: KeyDerivationAlgorithm,
enc_algo: EncryptionAlgorithm,
plaintext_size: usize
) -> Self
pub fn new(
key_deriv_algo: KeyDerivationAlgorithm,
enc_algo: EncryptionAlgorithm,
plaintext_size: usize
) -> Self
Create the metadata from user-provided values.
pub fn calculate_ciphertext_size(
plaintext_size: usize,
enc_algo: &EncryptionAlgorithm
) -> usize
pub fn calculate_ciphertext_size(
plaintext_size: usize,
enc_algo: &EncryptionAlgorithm
) -> usize
Calculate the ciphertext size, from the plaintext size and the encryption algorithm.
Generate the necessary metadata for encrypting data with a symmetric key.
The default suggestion for encrypting data with a symmetric key is to forego any key derivation algorithm, and just use the AES-256-GCM encryption algorithm.
Generate the necessary metadata for encrypting data with a passphrase.
The default suggestion for encrypting data with a passphrase is to use the PBKDF2 key derivation algorithm, and the AES-256-GCM encryption algorithm.
Create the metadata from the respective protobuf-generated metadata.
This method may return an error, if the protobuf-generated metadata have any invalid fields.
Convert the metadata to the respective protobuf-generated metadata.
Create a metadata struct from a serialized buffer.
Deserialize the buffer that was created by the .to_buf()
method into
a tuple that contains the Metadata
struct and its serialized size.
If the buffer does not contain a metadata header or the header contains
invalid fields, this method returns an error.
Serialize a metadata struct into a buffer.
Create a buffer that is large enough to hold the serialized metadata and the ciphertext. Then, serialize the metadata and store them at the start of the buffer. Finally, return the new buffer and the size of the serialized metadata.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Metadata
impl UnwindSafe for Metadata
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V