secure_gate/traits/
secure_random.rs

1//! Marker trait for secure random values.
2//!
3//! This trait marks types containing cryptographically fresh random bytes,
4//! ensuring they were generated via secure RNG and provide byte-slice access.
5
6/// Marker trait for cryptographically secure random values.
7///
8/// Extends [] with `Inner = [u8]`, guaranteeing fresh random bytes
9/// with metadata access but no mutation.
10///
11/// Use for generics requiring RNG-sourced data:
12///
13/// ```
14/// # #[cfg(feature = "rand")]
15/// # {
16/// use secure_gate::SecureRandom;
17///
18/// fn derive_key<R: SecureRandom>(r: &R) {
19///     let bytes = r.expose_secret();  // Guaranteed fresh &[u8]
20///     // Derive safely...
21/// }
22/// # }
23/// ```
24#[cfg(feature = "rand")]
25mod inner {
26    use super::super::ExposeSecret;
27
28    pub trait SecureRandom: ExposeSecret<Inner = [u8]> {}
29}
30
31#[cfg(feature = "rand")]
32pub use inner::SecureRandom;
33
34#[cfg(feature = "rand")]
35impl<const N: usize> SecureRandom for crate::random::FixedRandom<N> {}
36
37#[cfg(feature = "rand")]
38impl SecureRandom for crate::random::DynamicRandom {}