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§
Sourceconst NONCE_SIZE: u32
const NONCE_SIZE: u32
Required nonce size in bytes for this algorithm
Required Methods§
Sourcefn encrypt(
&self,
nonce: &Nonce<Self>,
payload: &[u8],
) -> impl Future<Output = Result<Vec<u8>, EncryptionError>>
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 encryptionpayload
- Data to encrypt
§Returns
Result containing encrypted bytes or an EncryptionError
§Errors
EncryptionError::InvalidAccess
if operation invalid for provided keyEncryptionError::Operation
if encryption fails for algorithm-specific reasons
Sourcefn decrypt(
&self,
nonce: &Nonce<Self>,
payload: &[u8],
) -> impl Future<Output = Result<Vec<u8>, DecryptionError>>
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 encryptionpayload
- Encrypted data to decrypt
§Returns
Result containing decrypted bytes or a DecryptionError
§Errors
DecryptionError::InvalidAccess
if operation invalid for provided keyDecryptionError::Operation
if decryption fails for algorithm-specific reasons
Provided Methods§
Sourcefn generate_nonce() -> Result<Nonce<Self>, NonceError>
fn generate_nonce() -> Result<Nonce<Self>, NonceError>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.