Skip to main content

Algorithm

Trait Algorithm 

Source
pub trait Algorithm: Sized {
    const NONCE_SIZE: u32;

    // Required methods
    fn encrypt(
        &self,
        nonce: &Nonce<Self>,
        payload: &[u8],
    ) -> impl Future<Output = Result<Vec<u8>, EncryptionError>>;
    fn decrypt(
        &self,
        nonce: &Nonce<Self>,
        payload: &[u8],
    ) -> impl Future<Output = Result<Vec<u8>, DecryptionError>>;

    // Provided method
    fn generate_nonce() -> Result<Nonce<Self>, NonceError> { ... }
}
Expand description

Core cryptographic algorithm trait

Required Associated Constants§

Source

const NONCE_SIZE: u32

Required nonce size in bytes for this algorithm

Required Methods§

Source

fn encrypt( &self, nonce: &Nonce<Self>, payload: &[u8], ) -> impl Future<Output = Result<Vec<u8>, EncryptionError>>

Encrypts data using this algorithm

§Arguments
  • nonce - Nonce to use for encryption
  • payload - Data to encrypt
§Returns

Result containing encrypted bytes or an EncryptionError

§Errors
  • EncryptionError::InvalidAccess if operation invalid for provided key
  • EncryptionError::Operation if encryption fails for algorithm-specific reasons
Source

fn decrypt( &self, nonce: &Nonce<Self>, payload: &[u8], ) -> impl Future<Output = Result<Vec<u8>, DecryptionError>>

Decrypts data using this algorithm

§Arguments
  • nonce - Nonce used for encryption
  • payload - Encrypted data to decrypt
§Returns

Result containing decrypted bytes or a DecryptionError

§Errors
  • DecryptionError::InvalidAccess if operation invalid for provided key
  • DecryptionError::Operation if decryption fails for algorithm-specific reasons

Provided Methods§

Source

fn generate_nonce() -> Result<Nonce<Self>, NonceError>

Generates a new random nonce suitable for this algorithm

§Returns

Result containing the generated Nonce or a NonceError

§Errors
  • NonceError::QuotaExceeded if requested length > 65536 bytes
  • NonceError::InvalidSize if nonce size doesn’t match algorithm requirements

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§