Skip to main content

Encryptor

Trait Encryptor 

Source
pub trait Encryptor: Sync + Send {
    // Required methods
    fn encrypt_with_aad(
        &self,
        plaintext: &[u8],
        aad: &[u8],
    ) -> Result<EncryptionResult, OperationOutcomeError>;
    fn decrypt_with_aad(
        &self,
        ciphertext: &EncryptionResult,
        aad: &[u8],
    ) -> Result<Vec<u8>, OperationOutcomeError>;

    // Provided methods
    fn encrypt(
        &self,
        plaintext: &[u8],
    ) -> Result<EncryptionResult, OperationOutcomeError> { ... }
    fn decrypt(
        &self,
        ciphertext: &EncryptionResult,
    ) -> Result<Vec<u8>, OperationOutcomeError> { ... }
}
Expand description

Provides symmetric authenticated encryption and decryption of arbitrary byte payloads.

Implementations are expected to encrypt data in a way that ensures both confidentiality and integrity. A value returned by Self::encrypt should be decryptable only by the same implementation initialized with the same keying material.

Required Methods§

Source

fn encrypt_with_aad( &self, plaintext: &[u8], aad: &[u8], ) -> Result<EncryptionResult, OperationOutcomeError>

Encrypts the given plaintext and binds the result to aad, its associated data: what the value belongs to, such as the key of the row that stores it. The associated data is neither secret nor part of the result. Decryption needs the same bytes again, so a result copied to another owner does not decrypt there.

§Errors

Returns an [OperationOutcomeError] if the plaintext cannot be encrypted.

Source

fn decrypt_with_aad( &self, ciphertext: &EncryptionResult, aad: &[u8], ) -> Result<Vec<u8>, OperationOutcomeError>

Decrypts a payload encrypted with the associated data aad.

§Errors

Returns an [OperationOutcomeError] if the ciphertext is invalid, has been tampered with, was encrypted with other associated data, or cannot be decrypted.

Provided Methods§

Source

fn encrypt( &self, plaintext: &[u8], ) -> Result<EncryptionResult, OperationOutcomeError>

Encrypts the given plaintext: Self::encrypt_with_aad with empty associated data.

§Errors

Returns an [OperationOutcomeError] if the plaintext cannot be encrypted.

Source

fn decrypt( &self, ciphertext: &EncryptionResult, ) -> Result<Vec<u8>, OperationOutcomeError>

Decrypts a payload encrypted with empty associated data.

§Errors

Returns an [OperationOutcomeError] if the ciphertext is invalid, has been tampered with, or cannot be decrypted.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§