pub struct CodePolicy { /* private fields */ }Expand description
Validated policy governing code generation and validation.
Implementations§
Source§impl CodePolicy
impl CodePolicy
Sourcepub fn default_human(ttl: Duration) -> Result<Self, PolicyError>
pub fn default_human(ttl: Duration) -> Result<Self, PolicyError>
The recommended default for human-entered codes: the unambiguous
alphabet, SECURE_MIN_HUMAN_LENGTH symbols, and the given TTL.
§Errors
Returns PolicyError only if the TTL is zero. The built-in alphabet
and length are always valid.
Sourcepub fn new(
alphabet: Alphabet,
length: usize,
ttl: Duration,
) -> Result<Self, PolicyError>
pub fn new( alphabet: Alphabet, length: usize, ttl: Duration, ) -> Result<Self, PolicyError>
Build a policy, enforcing the secure minimum length.
§Errors
Returns PolicyError if the length is zero, below
SECURE_MIN_HUMAN_LENGTH, or the TTL is zero. Use
CodePolicy::short_compat to opt into a shorter length deliberately.
Sourcepub fn short_compat(
alphabet: Alphabet,
length: usize,
ttl: Duration,
) -> Result<Self, PolicyError>
pub fn short_compat( alphabet: Alphabet, length: usize, ttl: Duration, ) -> Result<Self, PolicyError>
Explicitly opt into a short code length below the secure minimum.
This is a deliberately separate, named constructor (NFR-2): a short code is acceptable only with short expiry, single-use semantics, and rate limiting. Hosts choosing this take on that responsibility.
§Errors
Returns PolicyError::ZeroLength if length is zero, or a TTL error
if ttl is zero. Lengths at or above the minimum are also accepted.
Sourcepub fn legacy_ciao_6(ttl: Duration) -> Result<Self, PolicyError>
pub fn legacy_ciao_6(ttl: Duration) -> Result<Self, PolicyError>
The zinnias-ciao compatibility policy: unambiguous alphabet, 6 symbols,
caller-chosen TTL. Equivalent to short_compat with the legacy length.
§Errors
Returns a PolicyError if the TTL is zero.
Sourcepub fn alphabet(&self) -> &Alphabet
pub fn alphabet(&self) -> &Alphabet
The alphabet used for generation and accepted in normalized input.
Sourcepub fn max_raw_len(&self) -> usize
pub fn max_raw_len(&self) -> usize
The maximum accepted raw input length before normalization.
Sourcepub fn approx_entropy_bits(&self) -> f64
pub fn approx_entropy_bits(&self) -> f64
Approximate entropy in bits for this policy: length * log2(alphabet).
Intended for docs/diagnostics, not a security decision input.
Trait Implementations§
Source§impl Clone for CodePolicy
impl Clone for CodePolicy
Source§fn clone(&self) -> CodePolicy
fn clone(&self) -> CodePolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CodePolicy
impl Debug for CodePolicy
impl Eq for CodePolicy
Source§impl PartialEq for CodePolicy
impl PartialEq for CodePolicy
Source§fn eq(&self, other: &CodePolicy) -> bool
fn eq(&self, other: &CodePolicy) -> bool
self and other values to be equal, and is used by ==.