Module random

Module random 

Source
Expand description

Available macros (exported globally for convenience):

  • dynamic_alias!: Create type aliases for heap-allocated secrets (Dynamic<T>).
  • dynamic_generic_alias!: Create generic heap-allocated secret aliases.
  • fixed_alias!: Create type aliases for fixed-size secrets (Fixed<[u8; N]>).
  • fixed_generic_alias!: Create generic fixed-size secret aliases.
  • fixed_alias_random!: Create type aliases for random-only fixed-size secrets (FixedRandom<N>, requires rand feature). Cryptographically secure random generation (requires the rand feature). Provides RNG-backed secret generation with freshness guarantees. Cryptographically secure random value generation with encoding conveniences (gated behind rand and encoding features).

Provides FixedRandom and DynamicRandom types for generating fresh random bytes. Includes built-in methods for encoding to Hex, Base64, Bech32, and Bech32m strings without exposing secret bytes.

§Examples

Generate and encode random bytes:

use secure_gate::random::FixedRandom;
let hex = FixedRandom::<32>::generate().into_hex();

Use with Base64:

use secure_gate::random::FixedRandom;
let base64 = FixedRandom::<32>::generate().into_base64();

Encode to Bech32 or Bech32m:

use secure_gate::random::FixedRandom;
let bech32 = FixedRandom::<32>::generate().try_into_bech32("example").unwrap();
let bech32m = FixedRandom::<32>::generate().try_into_bech32m("example").unwrap();

Re-exports§

pub use dynamic_random::DynamicRandom;
pub use fixed_random::FixedRandom;

Modules§

dynamic_random
Dynamic random bytes generation.
fixed_random
Fixed-size random bytes generation.