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;
let keypair = KeyPair::new();
let public_key = keypair.public();
let token = HessraCapability::new()
.subject("user123")
.resource("resource456")
.operation("read")
.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
impl CapabilityVerifier
Sourcepub fn new(
token: String,
public_key: PublicKey,
resource: String,
operation: String,
) -> Self
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 verifypublic_key- The public key used to verify the token signatureresource- The resource identifier to verifyoperation- The operation to verify
Sourcepub fn with_subject(self, subject: String) -> Self
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
Sourcepub fn with_designation(self, label: String, value: String) -> Self
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”)
Sourcepub fn anchor(self, anchor: impl Into<String>) -> Self
pub fn anchor(self, anchor: impl Into<String>) -> Self
Asserts this verifier’s anchor identity. Sugar for
with_designation("anchor", anchor): proves “I am <anchor>” to satisfy
an anchor-bound capability (see crate::HessraCapability::anchor).
Sourcepub fn with_time(self, time_config: TokenTimeConfig) -> Self
pub fn with_time(self, time_config: TokenTimeConfig) -> Self
Supply a TokenTimeConfig to control verification time. Only
start_time is used: when set it overrides the “now” checked against the
token’s expiry (the seam for deterministic tests). Without this call the
real wall clock applies.