pub struct SaltCounter(/* private fields */);Expand description
Thread-safe salt counter for shared use across multiple encryptions.
Implementations§
Source§impl SaltCounter
impl SaltCounter
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new salt counter initialized from cryptographic randomness.
Panics if the OS random source is unavailable.
Sourcepub fn from_value(value: u64) -> Self
pub fn from_value(value: u64) -> Self
Create a salt counter initialized to a specific value.
This is primarily for testing purposes.
Sourcepub fn next(&self) -> u64
pub fn next(&self) -> u64
Get the next salt value and increment the counter.
This method never returns zero. Per net-snmp behavior, zero is skipped on wraparound to avoid potential IV reuse issues.
Uses the post-increment value as the salt and a single compare_exchange to skip zero atomically, avoiding the two-fetch_add race that could cause IV reuse under concurrent access.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SaltCounter
impl RefUnwindSafe for SaltCounter
impl Send for SaltCounter
impl Sync for SaltCounter
impl Unpin for SaltCounter
impl UnsafeUnpin for SaltCounter
impl UnwindSafe for SaltCounter
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more