Skip to main content

EntropySource

Trait EntropySource 

Source
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 of output is filled.
  • On Err, output may have been partially written and must be treated as containing no entropy.

Required Methods§

Source

fn fill_bytes(&mut self, output: &mut [u8]) -> Result<(), EntropyError>

Fills output with random bytes.

Provided Methods§

Source

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".

Implementations on Foreign Types§

Source§

impl<E: EntropySource + ?Sized> EntropySource for &mut E

Source§

fn fill_bytes(&mut self, output: &mut [u8]) -> Result<(), EntropyError>

Source§

fn next_u64(&mut self) -> Result<u64, EntropyError>

Implementors§