Trait bdrck::crypto::key::AbstractKey

source ·
pub trait AbstractKey: Sized {
    type Error: Error;

    // Required methods
    fn get_digest(&self) -> Digest;
    fn serialize(&self) -> Result<Secret, Self::Error>;
    fn deserialize(data: Secret) -> Result<Self, Self::Error>;
    fn encrypt(
        &self,
        plaintext: &Secret,
        nonce: Option<Nonce>
    ) -> Result<(Option<Nonce>, Vec<u8>), Self::Error>;
    fn decrypt(
        &self,
        nonce: Option<&Nonce>,
        ciphertext: &[u8]
    ) -> Result<Secret, Self::Error>;
}
Expand description

An AbstractKey is any cryptographic structure which supports encryption and decryption.

Required Associated Types§

source

type Error: Error

The Error type this key’s functions can return.

Required Methods§

source

fn get_digest(&self) -> Digest

Return a digest/signature computed from this key.

source

fn serialize(&self) -> Result<Secret, Self::Error>

Serialize this key out as a set of raw bytes.

source

fn deserialize(data: Secret) -> Result<Self, Self::Error>

Construct an instance of this key from a previously serialized instance of the key. In general, deserialize should accept data previously produced by this key’s serialize implementation.

source

fn encrypt( &self, plaintext: &Secret, nonce: Option<Nonce> ) -> Result<(Option<Nonce>, Vec<u8>), Self::Error>

Encrypt the given plaintext with this key. This function optionally takes a nonce as an argument. If this key’s encryption algorithm utilizes a nonce, the provided one will be used.

This function returns the ciphertext, as well as a Nonce (if one was used for encryption). If a Nonce was provided, that same Nonce is returned.

source

fn decrypt( &self, nonce: Option<&Nonce>, ciphertext: &[u8] ) -> Result<Secret, Self::Error>

Decrypt the given ciphertext using this key and the nonce which was generated at encryption time (if any), returning the plaintext.

Implementors§