pub struct NonceSequence<const N: usize> { /* private fields */ }Expand description
A stateful nonce generator that produces sequentially unique nonces.
§Panics
This type does not panic; all errors are returned as CryptoError.
§Example
use oxicrypto_aead::nonce_seq::Nonce12;
let prefix = [0u8; 4]; // 4-byte prefix for a 12-byte nonce
let mut seq = Nonce12::new(&prefix).unwrap();
let n0 = seq.generate().unwrap();
let n1 = seq.generate().unwrap();
assert_ne!(n0, n1);Implementations§
Source§impl<const N: usize> NonceSequence<N>
impl<const N: usize> NonceSequence<N>
Sourcepub fn new(prefix: &[u8]) -> Result<Self, CryptoError>
pub fn new(prefix: &[u8]) -> Result<Self, CryptoError>
Create a new NonceSequence with the given prefix.
prefix must be exactly N - 8 bytes long; otherwise
CryptoError::InvalidNonce is returned.
The initial counter value is 0.
Sourcepub fn generate(&mut self) -> Result<[u8; N], CryptoError>
pub fn generate(&mut self) -> Result<[u8; N], CryptoError>
Return the next nonce and advance the counter.
§Errors
Returns CryptoError::Internal if the counter has wrapped around
u64::MAX (i.e., 2^64 nonces have been generated).
Trait Implementations§
Auto Trait Implementations§
impl<const N: usize> Freeze for NonceSequence<N>
impl<const N: usize> RefUnwindSafe for NonceSequence<N>
impl<const N: usize> Send for NonceSequence<N>
impl<const N: usize> Sync for NonceSequence<N>
impl<const N: usize> Unpin for NonceSequence<N>
impl<const N: usize> UnsafeUnpin for NonceSequence<N>
impl<const N: usize> UnwindSafe for NonceSequence<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more