Skip to main content

Verifier

Struct Verifier 

Source
pub struct Verifier<'a> { /* private fields */ }
Expand description

A configured mandate verifier (spec §9). Verify against one or more candidate keys by trial decryption (spec §9.4); reusable across tokens.

Implementations§

Source§

impl<'a> Verifier<'a>

Source

pub fn new() -> Self

A new verifier with no keys, no audience, and no leeway.

Source

pub fn key(self, key: &'a MandateKey) -> Self

Add a candidate mandate key (trial decryption, spec §9.4).

Source

pub fn keys<I: IntoIterator<Item = &'a MandateKey>>(self, keys: I) -> Self

Add several candidate mandate keys.

use obsigil::{Issuer, MandateKey, NoApp, Verifier};
let token = Issuer::new(MandateKey::from_bytes([42u8; 64])?)
    .mandate(&NoApp::default())
    .exp(4_000_000_000)
    .mint()?;

// Trial decryption: each candidate is tried; the wrong key fails
// closed, the right one authenticates (spec §9.4).
let wrong = MandateKey::from_bytes([1u8; 64])?;
let right = MandateKey::from_bytes([42u8; 64])?;
assert!(Verifier::new()
    .keys([&wrong, &right])
    .now(1_000_000_000)
    .verify::<NoApp>(&token)
    .is_ok());
Source

pub fn audience(self, id: impl Into<String>) -> Self

Set this verifier’s identifier, checked for membership in a present aud clause (spec §11.4).

Source

pub fn leeway(self, leeway: Duration) -> Self

Allow a clock-skew leeway when checking exp (spec §11.1).

Source

pub fn now(self, now: NumericDate) -> Self

Pin “now” (seconds since epoch) instead of reading the system clock — for testing and reproducibility.

use std::time::Duration;
use obsigil::{Issuer, MandateKey, NoApp, Verifier};
let token = Issuer::new(MandateKey::from_bytes([42u8; 64])?)
    .mandate(&NoApp::default())
    .exp(1_000)
    .mint()?;
let key = MandateKey::from_bytes([42u8; 64])?;

// Before exp: accepted. At/after exp: rejected, unless leeway covers it.
assert!(Verifier::new().key(&key).now(500).verify::<NoApp>(&token).is_ok());
assert!(Verifier::new().key(&key).now(1_050).verify::<NoApp>(&token).is_err());
assert!(Verifier::new().key(&key).now(1_050).leeway(Duration::from_secs(100))
    .verify::<NoApp>(&token).is_ok());
Source

pub fn verify<T: DeserializeOwned>( &self, token: &str, ) -> Result<Mandate<T>, Error>

Verify a token’s mandate and return its clauses (spec §8, §9, §11). Accepts a full token or the forwarded .0mandate form; the manifest is never parsed or trusted. On any failure returns one opaque Error (spec §9.5).

use obsigil::{Issuer, Mandate, MandateKey, Verifier};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct Access { role: String }

let token = Issuer::new(MandateKey::from_bytes([42u8; 64])?)
    .mandate(&Access { role: "admin".into() })
    .exp(4_000_000_000)
    .mint()?;

let key = MandateKey::from_bytes([42u8; 64])?;
let mandate: Mandate<Access> = Verifier::new()
    .key(&key)
    .now(1_000_000_000)
    .verify(&token)?;
assert_eq!(mandate.app().role, "admin");

Trait Implementations§

Source§

impl<'a> Default for Verifier<'a>

Source§

fn default() -> Verifier<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Verifier<'a>

§

impl<'a> RefUnwindSafe for Verifier<'a>

§

impl<'a> Send for Verifier<'a>

§

impl<'a> Sync for Verifier<'a>

§

impl<'a> Unpin for Verifier<'a>

§

impl<'a> UnsafeUnpin for Verifier<'a>

§

impl<'a> UnwindSafe for Verifier<'a>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.