arsenal-crypto · encryption
Declared module signatures, types, configuration, and source documentation.
Source: arsenal/crates/arsenal-crypto/src/encryption.rs. SHA-256: 0ca517f8ed5758f6c0c4a05cd1e1985c6bebb9c0b52e0135b665d3b8f3e8ecf9.
This source reference follows declared modules and preserves feature attributes. It includes public declarations and implementation methods in those modules. Private-module exports and trait resolution still require the compiler; not every declaration is a crate-root import. Function bodies and constant values are omitted. Source comments describe their implementation context and are not a production deployment claim.
encryption::EncryptionAlgorithm
Encryption algorithm
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum EncryptionAlgorithm {
/// XChaCha20-Poly1305 (recommended)
XChaCha20Poly1305,
/// AES-256-GCM
Aes256Gcm,
}Source line: 20.
encryption::EncryptionAlgorithm::nonce_size
Get the nonce size for this algorithm
#[must_use]
pub const fn nonce_size(&self) -> usize;Source line: 30.
encryption::EncryptionAlgorithm::key_size
Get the key size for this algorithm
#[must_use]
pub const fn key_size(&self) -> usize;Source line: 39.
encryption::EncryptionAlgorithm::tag_size
Get the auth tag size
#[must_use]
pub const fn tag_size(&self) -> usize;Source line: 45.
encryption::EncryptedData
Encrypted data container
#[derive(Clone, Serialize, Deserialize)]
pub struct EncryptedData {
}Source line: 52.
encryption::EncryptedData::ciphertext
Get the ciphertext
#[must_use]
pub fn ciphertext(&self) -> &[u8];Source line: 67.
encryption::EncryptedData::nonce
Get the nonce
#[must_use]
pub fn nonce(&self) -> &[u8];Source line: 73.
encryption::EncryptedData::algorithm
Get the algorithm
#[must_use]
pub fn algorithm(&self) -> EncryptionAlgorithm;Source line: 79.
encryption::EncryptedData::total_size
Get the total size (ciphertext + nonce + overhead)
#[must_use]
pub fn total_size(&self) -> usize;Source line: 85.
encryption::EncryptedData::to_bytes
Serialize to bytes (nonce || ciphertext)
#[must_use]
pub fn to_bytes(&self) -> Vec<u8>;Source line: 91.
encryption::EncryptedData::from_bytes
Deserialize from bytes
Errors
Returns an error if the data is malformed
pub fn from_bytes(bytes: &[u8], algorithm: EncryptionAlgorithm) -> ArsenalResult<Self>;Source line: 102.
encryption::SymmetricKey
Symmetric encryption key (zeroized on drop)
#[derive(Clone)]
pub struct SymmetricKey {
}Source line: 132.
encryption::SymmetricKey::new
Create a new key from bytes
#[must_use]
pub fn new(bytes: [u8; 32], algorithm: EncryptionAlgorithm) -> Self;Source line: 153.
encryption::SymmetricKey::generate
Generate a new random key
Errors
Returns an error if random generation fails
pub fn generate(algorithm: EncryptionAlgorithm) -> ArsenalResult<Self>;Source line: 161.
encryption::SymmetricKey::as_bytes
Get the key bytes (use carefully)
#[must_use]
pub fn as_bytes(&self) -> &[u8; 32];Source line: 168.
encryption::SymmetricKey::algorithm
Get the algorithm
#[must_use]
pub fn algorithm(&self) -> EncryptionAlgorithm;Source line: 174.
encryption::Encryptor
Trait for encryption operations
pub trait Encryptor {
/// Encrypt data
///
/// # Errors
/// Returns an error if encryption fails
fn encrypt(&self, plaintext: &[u8]) -> ArsenalResult<EncryptedData>;
/// Encrypt data with associated data (AEAD)
///
/// # Errors
/// Returns an error if encryption fails
fn encrypt_with_aad(&self, plaintext: &[u8], aad: &[u8]) -> ArsenalResult<EncryptedData>;
}Source line: 189.
encryption::Decryptor
Trait for decryption operations
pub trait Decryptor {
/// Decrypt data
///
/// # Errors
/// Returns an error if decryption fails
fn decrypt(&self, encrypted: &EncryptedData) -> ArsenalResult<Vec<u8>>;
/// Decrypt data with associated data verification
///
/// # Errors
/// Returns an error if decryption fails or AAD doesn't match
fn decrypt_with_aad(&self, encrypted: &EncryptedData, aad: &[u8]) -> ArsenalResult<Vec<u8>>;
}Source line: 204.