pub trait EntropySource {
// Required method
fn fill_bytes(&mut self, output: &mut [u8]) -> Result<(), EntropyError>;
// Provided method
fn next_u64(&mut self) -> Result<u64, EntropyError> { ... }
}Expand description
A source of cryptographically secure random bytes.
Implementations live in adapters and are injected into the components that need randomness, so protocol crates stay deterministic and testable.
§Contract
- Bytes must be suitable for cryptographic use: unpredictable to an attacker who has observed every previous output.
- On
Ok, the whole ofoutputis filled. - On
Err,outputmay have been partially written and must be treated as containing no entropy.
Required Methods§
Sourcefn fill_bytes(&mut self, output: &mut [u8]) -> Result<(), EntropyError>
fn fill_bytes(&mut self, output: &mut [u8]) -> Result<(), EntropyError>
Fills output with random bytes.
Provided Methods§
Sourcefn next_u64(&mut self) -> Result<u64, EntropyError>
fn next_u64(&mut self) -> Result<u64, EntropyError>
Draws a random u64.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".