Skip to main content

CapabilityVerifier

Struct CapabilityVerifier 

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

Builder for verifying Hessra capability tokens with flexible configuration.

By default, capability verification only checks resource + operation. Subject verification is optional via .with_subject().

§Example

use hessra_cap_token::{CapabilityVerifier, HessraCapability};
use hessra_token_core::{KeyPair, TokenTimeConfig};

let keypair = KeyPair::new();
let public_key = keypair.public();
let token = HessraCapability::new(
    "user123".to_string(),
    "resource456".to_string(),
    "read".to_string(),
    TokenTimeConfig::default(),
)
.issue(&keypair)?;

// Basic capability verification (no subject check)
CapabilityVerifier::new(
    token.clone(),
    public_key,
    "resource456".to_string(),
    "read".to_string(),
)
.verify()?;

// With optional subject verification
CapabilityVerifier::new(
    token.clone(),
    public_key,
    "resource456".to_string(),
    "read".to_string(),
)
.with_subject("user123".to_string())
.verify()?;

Implementations§

Source§

impl CapabilityVerifier

Source

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

Creates a new capability verifier for a base64-encoded token.

§Arguments
  • token - The base64-encoded capability token to verify
  • public_key - The public key used to verify the token signature
  • resource - The resource identifier to verify
  • operation - The operation to verify
Source

pub fn with_subject(self, subject: String) -> Self

Adds an optional subject verification check.

When set, the authorizer adds a check that the minted subject matches. This is optional – pure capability verification does not require it.

§Arguments
  • subject - The subject to verify in the token’s right fact
Source

pub fn with_namespace(self, namespace: String) -> Self

Adds a namespace restriction to the verification.

§Arguments
  • namespace - The namespace to verify against (e.g., “example.com”)
Source

pub fn with_designation(self, label: String, value: String) -> Self

Adds a designation fact to the verification.

Each designation provides a designation(label, value) fact that the token’s designation checks will verify against.

§Arguments
  • label - The designation dimension (e.g., “tenant_id”)
  • value - The specific value (e.g., “t-123”)
Source

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

Performs the token verification with the configured parameters.

§Returns
  • Ok(()) - If the token is valid and meets all verification requirements
  • Err(TokenError) - If verification fails for any reason

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more