pub struct CryptoSession { /* private fields */ }Expand description
Unified crypto session — works with any supported cipher suite.
Drop-in replacement for AesSession with auto cipher selection.
Unified crypto session — works with any supported cipher suite.
Drop-in replacement for AesSession with auto cipher selection.
Implementations§
Source§impl CryptoSession
impl CryptoSession
Auto-detect best cipher and create session from shared secret. Initiator side.
Auto-detect, peer (responder) side — keys swapped.
Sourcepub fn with_suite(
shared_secret: &[u8; 32],
suite: CipherSuite,
) -> Result<Self, CoreError>
pub fn with_suite( shared_secret: &[u8; 32], suite: CipherSuite, ) -> Result<Self, CoreError>
Create with explicit cipher suite (for negotiation scenarios). Initiator side.
Under --features fips, requesting CipherSuite::ChaCha20Poly1305
returns CoreError::CipherSuiteUnavailable — the wire-format
variant is preserved (enum stable across feature configurations)
but the primitive is not FIPS-approved.
Sourcepub fn with_suite_peer(
shared_secret: &[u8; 32],
suite: CipherSuite,
) -> Result<Self, CoreError>
pub fn with_suite_peer( shared_secret: &[u8; 32], suite: CipherSuite, ) -> Result<Self, CoreError>
Create with explicit cipher suite. Peer side.
Mirrors the fips guard of Self::with_suite.
Sourcepub fn cipher_suite(&self) -> CipherSuite
pub fn cipher_suite(&self) -> CipherSuite
Which cipher suite is active
Sourcepub fn encrypt_in_place(
&self,
aad: &[u8],
buf: &mut Vec<u8>,
) -> Result<(), CryptoError>
pub fn encrypt_in_place( &self, aad: &[u8], buf: &mut Vec<u8>, ) -> Result<(), CryptoError>
Encrypt in place: appends 16-byte tag.
Sourcepub fn encrypt_in_place_offset(
&self,
aad: &[u8],
buf: &mut Vec<u8>,
offset: usize,
) -> Result<usize, CryptoError>
pub fn encrypt_in_place_offset( &self, aad: &[u8], buf: &mut Vec<u8>, offset: usize, ) -> Result<usize, CryptoError>
Encrypt in place with offset: leaves offset bytes untouched at the start
(for prepending frame headers). Encrypts buf[offset..] in place, appends tag.
Returns ciphertext length (data + tag).
Sourcepub fn encrypt(
&self,
aad: &[u8],
plaintext: &[u8],
) -> Result<Vec<u8>, CryptoError>
pub fn encrypt( &self, aad: &[u8], plaintext: &[u8], ) -> Result<Vec<u8>, CryptoError>
Encrypt: allocates a new Vec.
Sourcepub fn decrypt_in_place<'a>(
&self,
aad: &[u8],
buf: &'a mut [u8],
) -> Result<&'a mut [u8], CryptoError>
pub fn decrypt_in_place<'a>( &self, aad: &[u8], buf: &'a mut [u8], ) -> Result<&'a mut [u8], CryptoError>
Decrypt in place: verifies tag and returns plaintext slice.
Sourcepub fn send_invocations(&self) -> u64
pub fn send_invocations(&self) -> u64
Number of encryptions performed on this session (per-direction send counter).
Useful for emitting aead_invocations_total metrics and for rekey-trigger
logic when mid-session key rotation lands.
Sourcepub fn recv_invocations(&self) -> u64
pub fn recv_invocations(&self) -> u64
Number of decryptions performed on this session (per-direction recv counter).
Sourcepub fn decrypt(
&self,
aad: &[u8],
ciphertext: &[u8],
) -> Result<Vec<u8>, CryptoError>
pub fn decrypt( &self, aad: &[u8], ciphertext: &[u8], ) -> Result<Vec<u8>, CryptoError>
Decrypt: allocates a new Vec.
Sourcepub fn encrypt_with_nonce(
&self,
nonce_bytes: [u8; 12],
aad: &[u8],
plaintext: &[u8],
) -> Result<Vec<u8>, CryptoError>
pub fn encrypt_with_nonce( &self, nonce_bytes: [u8; 12], aad: &[u8], plaintext: &[u8], ) -> Result<Vec<u8>, CryptoError>
Encrypt with an explicit caller-supplied nonce. The caller MUST
ensure uniqueness of (key, nonce) — the V2 path derives the nonce
from (nonce_prefix, epoch, stream_id, sequence) so uniqueness
follows from the wire-format invariant that sender never reuses
(stream_id, sequence) within an epoch.
Sourcepub fn decrypt_with_nonce(
&self,
nonce_bytes: [u8; 12],
aad: &[u8],
ciphertext: &[u8],
) -> Result<Vec<u8>, CryptoError>
pub fn decrypt_with_nonce( &self, nonce_bytes: [u8; 12], aad: &[u8], ciphertext: &[u8], ) -> Result<Vec<u8>, CryptoError>
Decrypt with an explicit caller-supplied nonce. Unlike Self::decrypt,
a tag-check failure does NOT advance the internal counter — only
the bounded telemetry counter increments.
Sourcepub fn nonce_prefix(&self) -> [u8; 4]
pub fn nonce_prefix(&self) -> [u8; 4]
Expose the 4-byte nonce prefix for the V2 nonce construction
(prefix || epoch || stream_id_be || sequence_be).
Trait Implementations§
Source§impl Clone for CryptoSession
impl Clone for CryptoSession
Source§fn clone(&self) -> CryptoSession
fn clone(&self) -> CryptoSession
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more