pub trait SecureRng:
Rng
+ CryptoRng
+ Send
+ Sync {
// Provided methods
fn fill_bytes_secure(&mut self, dest: &mut [u8]) -> Result<()> { ... }
fn next_u32_secure(&mut self) -> Result<u32> { ... }
fn next_u64_secure(&mut self) -> Result<u64> { ... }
fn initialize(&mut self, entropy: &[u8]) -> Result<()> { ... }
fn is_secure(&self) -> bool { ... }
fn entropy_quality(&self) -> f64 { ... }
fn security_level(&self) -> SecurityLevel { ... }
fn reseed(&mut self) -> Result<()> { ... }
fn state_size(&self) -> usize { ... }
fn reseed_interval(&self) -> Option<usize> { ... }
}Expand description
Enhanced random number generator trait for cryptographic applications
This trait extends the standard Rng and CryptoRng traits with
additional functionality required for secure cryptographic operations.
Provided Methods§
Sourcefn fill_bytes_secure(&mut self, dest: &mut [u8]) -> Result<()>
fn fill_bytes_secure(&mut self, dest: &mut [u8]) -> Result<()>
Fill the buffer with cryptographically secure random bytes
This method provides the same functionality as Rng::fill_bytes
but with additional security guarantees and error handling.
§Arguments
dest- Buffer to fill with random bytes
§Errors
Returns an error if the random number generation fails or if the generated bytes don’t meet security requirements.
Sourcefn next_u32_secure(&mut self) -> Result<u32>
fn next_u32_secure(&mut self) -> Result<u32>
Generate a random u32 with security validation
§Errors
Returns an error if the random number generation fails.
Sourcefn next_u64_secure(&mut self) -> Result<u64>
fn next_u64_secure(&mut self) -> Result<u64>
Generate a random u64 with security validation
§Errors
Returns an error if the random number generation fails.
Sourcefn initialize(&mut self, entropy: &[u8]) -> Result<()>
fn initialize(&mut self, entropy: &[u8]) -> Result<()>
Sourcefn is_secure(&self) -> bool
fn is_secure(&self) -> bool
Check if the RNG is cryptographically secure
Returns true if the RNG provides cryptographically secure randomness,
false otherwise (e.g., for deterministic RNGs used in testing).
Sourcefn entropy_quality(&self) -> f64
fn entropy_quality(&self) -> f64
Get the entropy quality estimate (0.0 to 1.0)
Returns an estimate of the entropy quality, where 1.0 represents perfect entropy and 0.0 represents no entropy.
Sourcefn security_level(&self) -> SecurityLevel
fn security_level(&self) -> SecurityLevel
Get the RNG’s security level
Returns a description of the RNG’s security characteristics.
Sourcefn reseed(&mut self) -> Result<()>
fn reseed(&mut self) -> Result<()>
Reseed the RNG with fresh entropy
This method allows the RNG to be reseeded with fresh entropy, which is important for long-running applications.
§Errors
Returns an error if reseeding fails or is not supported.
Sourcefn state_size(&self) -> usize
fn state_size(&self) -> usize
Get the RNG’s internal state size
Returns the size of the RNG’s internal state in bytes.
Sourcefn reseed_interval(&self) -> Option<usize>
fn reseed_interval(&self) -> Option<usize>
Get the RNG’s reseed interval
Returns the recommended number of bytes to generate before reseeding,
or None if reseeding is not required.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".