pub struct Secret(/* private fields */);Expand description
A master secret. Zeroized on drop; never printed.
Implementations§
Source§impl Secret
impl Secret
pub const MIN_LEN: usize = 32
Sourcepub const MIN_ENTROPY_BITS: f64 = 120.0
pub const MIN_ENTROPY_BITS: f64 = 120.0
The least estimated entropy .build() accepts for a production base_url, as in
Better Auth. See Secret::entropy_bits.
Sourcepub fn entropy_bits(&self) -> f64
pub fn entropy_bits(&self) -> f64
A rough entropy estimate: the bytes a guesser can’t predict, times log2 of the
alphabet. A run of four or more bytes that repeats earlier bytes (changeme again,
aaaa) or counts up or down by one (abcd, 6543) counts as two bytes, where it
starts and what it follows. The alphabet is the smallest of hex digits, letters and
digits, base64, printable ASCII or any byte that holds every byte of the secret, but at
most twice the distinct bytes seen, so a secret drawn from a handful of characters
scores low. A generated secret scores about
440 bits, openssl rand -hex 16 about 128; one repeated byte scores 0.
Sourcepub fn from_bytes(bytes: impl Into<Vec<u8>>) -> Self
pub fn from_bytes(bytes: impl Into<Vec<u8>>) -> Self
Raw bytes. Prefer from_env or from_base64 so the secret never sits in source.
Sourcepub fn from_base64(value: &str) -> Self
pub fn from_base64(value: &str) -> Self
Accepts base64url (what fastauth secret prints) or, failing that, the raw string.