Skip to main content

CodePolicy

Struct CodePolicy 

Source
pub struct CodePolicy { /* private fields */ }
Expand description

Validated policy governing code generation and validation.

Implementations§

Source§

impl CodePolicy

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn alphabet(&self) -> &Alphabet

The alphabet used for generation and accepted in normalized input.

Source

pub fn length(&self) -> usize

The exact normalized code length.

Source

pub fn max_raw_len(&self) -> usize

The maximum accepted raw input length before normalization.

Source

pub fn ttl(&self) -> Duration

The code time-to-live.

Source

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

Source§

fn clone(&self) -> CodePolicy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CodePolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for CodePolicy

Source§

impl PartialEq for CodePolicy

Source§

fn eq(&self, other: &CodePolicy) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for CodePolicy

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.