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
impl NonceIssuer
Sourcepub fn new_random() -> Self
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.
Sourcepub fn from_secret(secret: [u8; 32]) -> Self
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).
Sourcepub fn issue(&self, source: SocketAddr, now_unix_secs: u64) -> [u8; 20]
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).
Sourcepub fn check(
&self,
nonce_attr_value: &[u8],
source: SocketAddr,
now_unix_secs: u64,
) -> NonceCheck
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.