Skip to main content

ContextVerifier

Struct ContextVerifier 

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

Verifier for context tokens with a fluent builder for exclusion checks.

.verify() always enforces the signature + expiration. Each .excludes(...) asserts a candidate exposure({label}) fact into the authorizer; if the token carries a matching reject if exposure({label}) rule (added by any signer, in any block), that reject fires and authorization fails. No trusting scope is involved – reject rules apply to the whole token.

§Example

use hessra_context_token::{HessraContext, ContextVerifier, add_exposure};
use hessra_token_core::{KeyPair, TokenTimeConfig};

let keypair = KeyPair::new();
let public_key = keypair.public();

let token = HessraContext::new("agent:test".to_string(), TokenTimeConfig::default())
    .issue(&keypair)
    .expect("Failed to mint context token");

let exposed = add_exposure(
    &token,
    &keypair,
    &["PII:email".to_string()],
    "data:user-profile".to_string(),
).expect("Failed to add exposure");

// Passes -- "PII:SSN" is not attested.
ContextVerifier::new(exposed.clone(), public_key)
    .excludes("PII:SSN")
    .verify()
    .expect("clean of PII:SSN");

// Fails -- "PII:email" is attested.
assert!(ContextVerifier::new(exposed, public_key)
    .excludes("PII:email")
    .verify()
    .is_err());

Implementations§

Source§

impl ContextVerifier

Source

pub fn new(token: String, public_key: PublicKey) -> Self

Creates a new context verifier.

Source

pub fn excludes(self, label: impl Into<String>) -> Self

Add an exposure label that must NOT be present in the token.

Chainable. Each call asserts one candidate exposure({label}) fact; if the token rejects any of them, the grant is blocked (OR semantics across all excluded labels).

Source

pub fn verify(self) -> Result<(), TokenError>

Run authorization.

Always enforces signature + expiration. Each .excludes(...) label is asserted as an exposure({label}) fact in a single authorizer pass; a matching reject if exposure({label}) rule anywhere in the token fires the reject and fails verification.

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> 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V