Struct DelegationVerifier

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

Verifies JWS tokens using a key registry of public keys.

The verifier holds an internal HashMap<kid, (Algorithm, VerifyingKey)>. When a token is verified, the registry is consulted to find the matching key, and the EdDSA signature is checked cryptographically.

Implementations§

Source§

impl DelegationVerifier

Source

pub fn new() -> Self

Source

pub fn set_clock_skew_seconds(&self, secs: i64)

Set the clock-skew tolerance (seconds) used when comparing exp / nbf to “now”.

Source

pub fn clock_skew_seconds(&self) -> i64

Source

pub fn add_key( &self, kid: impl Into<String>, alg: Algorithm, raw: &[u8], ) -> Result<()>

Add a public key (raw Ed25519 bytes).

Replaces any existing key under the same kid. Returns Err when the key bytes are invalid (wrong length, bad parse) so callers see the failure rather than silently dropping it.

Source

pub fn clear(&self)

Remove all keys.

Source

pub fn key_count(&self) -> usize

Number of registered keys.

Source

pub fn verify( &self, token: &str, expected_aud: &str, now_unix: i64, ) -> Result<VerifiedDelegation>

Verify the JWS signature, then validate standard claims (exp, nbf, aud). Returns the verified claims on success.

This is the secure entry point — unlike DelegationToken::parse, it actually verifies the EdDSA signature, AgentGuard token type, and standard identity/time claims.

§Errors

Returns Error::TokenSignature if the signature is invalid or the kid is unknown. Returns Error::TokenExpired if now_unix is past exp + clock_skew_seconds. Returns Error::TokenNotYetValid if iat or nbf is in the future beyond the configured skew. Returns Error::InvalidToken for any JWS parse / base64 / signature-format error or audience mismatch.

§Examples
use agentguard_core::{DelegationConfig, DelegationSigner, DelegationVerifier,
    auth_keys::Algorithm};
use base64::Engine as _;

let signer = DelegationSigner::generate();
let verifier = DelegationVerifier::new();
let pub_bytes = base64::engine::general_purpose::STANDARD
    .decode(signer.public_key_b64()).unwrap();
verifier.add_key(signer.key_id(), Algorithm::EdDSA, &pub_bytes).unwrap();
let token = signer.mint("alice", "summarizer", "aud",
    vec!["ToolCall::send".into()],
    vec!["Mailbox::*".into()],
    DelegationConfig::default()).unwrap();
let verified = verifier.verify(&token.jws, "aud", chrono::Utc::now().timestamp()).unwrap();
assert_eq!(verified.claims().iss, "alice");
assert_eq!(verified.claims().aud, "aud");
Source

pub async fn verify_with_revocation_store( &self, token: &str, expected_aud: &str, now_unix: i64, store: &dyn DelegationRevocationStore, ) -> Result<VerifiedDelegation>

Verify a token and require a successful shared revocation-state check. Storage errors propagate; callers must never continue with the cryptographically verified grant when the revocation store is unavailable.

Source

pub async fn revoke( &self, verified: &VerifiedDelegation, store: &dyn DelegationRevocationStore, ) -> Result<()>

Revoke a verified grant in the supplied shared store. The retention deadline includes this verifier’s configured expiry clock skew.

Trait Implementations§

Source§

impl Default for DelegationVerifier

Source§

fn default() -> DelegationVerifier

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

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.

§

impl<T> Instrument for T

§

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

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

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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

§

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

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,