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

Create the metadata from user-provided values.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.