Skip to main content

NonceIssuer

Struct NonceIssuer 

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

Issues and checks nonces for one DIG-operated UDP STUN server process (SPEC.md §14.4). Holds nothing per-client: every issue/check call is a pure function of the secret, the source address, and the wall-clock second.

Implementations§

Source§

impl NonceIssuer

Source

pub fn new_random() -> Self

Build an issuer with a fresh, randomly generated secret (ring::rand::SystemRandom). The ordinary choice for a single-process deployment (SPEC.md §14.4 “Replicas”).

§Panics

Only on catastrophic OS CSPRNG unavailability — the same posture as crate::new_transaction_id, for the same reason: there is no safe degraded fallback for a secret that must not be predictable.

Source

pub fn from_secret(secret: [u8; 32]) -> Self

Build an issuer from an explicitly supplied secret — for a deployment running several server replicas behind one address that must share one issuer (SPEC.md §14.4 “Replicas”). The caller is responsible for generating and distributing secret safely; this constructor does no validation beyond the type system’s (any 32 bytes are accepted).

Source

pub fn issue(&self, source: SocketAddr, now_unix_secs: u64) -> [u8; 20]

Mint a nonce for source at now_unix_secs, valid at THIS issuer for source alone, during the resulting bucket and the one after it (SPEC.md §14.4). Returns the raw 20 bytes; the caller base64url-encodes them into the wire NONCE attribute (crate::credential::encode_challenge does this).

Source

pub fn check( &self, nonce_attr_value: &[u8], source: SocketAddr, now_unix_secs: u64, ) -> NonceCheck

Check a wire NONCE attribute value (the base64url text, exactly as carried) against source at now_unix_secs (SPEC.md §14.4). Recomputes the tag for the nonce’s OWN bucket (not now’s) before ever looking at freshness, so a forged nonce is Invalid rather than Stale regardless of what bucket number it claims.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.