secure_gate/random/
mod.rs

1//! Cryptographically secure random value generation with encoding conveniences (gated behind `rand` and encoding features).
2//!
3//! Provides [`FixedRandom`] and [`DynamicRandom`] types for generating fresh random bytes.
4//! Includes built-in methods for encoding to Hex, Base64, Bech32, and Bech32m strings
5//! without exposing secret bytes.
6//!
7//! # Examples
8//!
9//! Generate and encode random bytes:
10//! ```
11//! # #[cfg(all(feature = "rand", feature = "encoding-hex"))]
12//! # {
13//! use secure_gate::random::FixedRandom;
14//! let hex = FixedRandom::<32>::generate().into_hex();
15//! # }
16//! ```
17//!
18//! Use with Base64:
19//! ```
20//! # #[cfg(all(feature = "rand", feature = "encoding-base64"))]
21//! # {
22//! use secure_gate::random::FixedRandom;
23//! let base64 = FixedRandom::<32>::generate().into_base64();
24//! # }
25//! ```
26//!
27//! Encode to Bech32 or Bech32m:
28//! ```
29//! # #[cfg(all(feature = "rand", feature = "encoding-bech32"))]
30//! # {
31//! use secure_gate::random::FixedRandom;
32//! let bech32 = FixedRandom::<32>::generate().try_into_bech32("example").unwrap();
33//! let bech32m = FixedRandom::<32>::generate().try_into_bech32m("example").unwrap();
34//! # }
35//! ```
36
37/// Dynamic random bytes generation.
38pub mod dynamic_random;
39
40/// Fixed-size random bytes generation.
41pub mod fixed_random;
42
43// Re-export for API compatibility
44/// Re-export of [`DynamicRandom`].
45pub use dynamic_random::DynamicRandom;
46/// Re-export of [`FixedRandom`].
47pub use fixed_random::FixedRandom;