pub struct CapabilityToken {
pub id: String,
pub issuer: PublicKey,
pub subject: PublicKey,
pub scope: ChioScope,
pub issued_at: u64,
pub expires_at: u64,
pub delegation_chain: Vec<DelegationLink>,
pub algorithm: Option<SigningAlgorithm>,
pub signature: Signature,
}Expand description
A Chio capability token. Scoped, time-bounded, cryptographically signed.
The signature field covers the canonical JSON of all other fields.
Verification re-serializes the token (excluding the signature), computes
the canonical form, and checks the signature against issuer using the
algorithm declared by the algorithm field (defaulting to Ed25519 when
absent, which preserves backward compatibility with tokens issued prior
to the introduction of SigningAlgorithm).
Fields§
§id: StringUnique token ID (UUIDv7 recommended, used for revocation).
issuer: PublicKeyCapability Authority (or delegating agent) that issued this token.
subject: PublicKeyAgent this capability is bound to (DPoP sender constraint).
scope: ChioScopeWhat this token authorizes.
issued_at: u64Unix timestamp (seconds) when the token was issued.
expires_at: u64Unix timestamp (seconds) when the token expires.
delegation_chain: Vec<DelegationLink>Ordered list of delegation links from the root CA to this token.
algorithm: Option<SigningAlgorithm>Signing algorithm. Absent means Ed25519 for backward compatibility.
signature: SignatureSignature over canonical JSON of all fields above.
Implementations§
Source§impl CapabilityToken
impl CapabilityToken
Sourcepub fn body(&self) -> CapabilityTokenBody
pub fn body(&self) -> CapabilityTokenBody
Extract the body (everything except the signature) for re-verification.
Sourcepub fn sign(
body: CapabilityTokenBody,
keypair: &Keypair,
) -> Result<CapabilityToken, Error>
pub fn sign( body: CapabilityTokenBody, keypair: &Keypair, ) -> Result<CapabilityToken, Error>
Sign a capability token body with the given Ed25519 keypair.
This is the historical signing entry point and produces a
byte-identical artifact to pre-SigningBackend Chio releases: the
algorithm envelope field is omitted from the serialized output.
Sourcepub fn sign_with_backend(
body: CapabilityTokenBody,
backend: &dyn SigningBackend,
) -> Result<CapabilityToken, Error>
pub fn sign_with_backend( body: CapabilityTokenBody, backend: &dyn SigningBackend, ) -> Result<CapabilityToken, Error>
Sign a capability token body with an arbitrary SigningBackend.
Use this entry point to produce FIPS-algorithm (P-256 / P-384) tokens
when operating under the fips feature. The body.issuer field must
equal backend.public_key(); otherwise verification will fail.
The resulting token’s algorithm envelope field is populated with the
backend’s algorithm. It is informational only – verification
dispatches off the signature hex prefix, not this field.
Sourcepub fn verify_signature(&self) -> Result<bool, Error>
pub fn verify_signature(&self) -> Result<bool, Error>
Verify the token’s signature against its issuer key.
Dispatches off the algorithm carried by signature and issuer.
For FIPS algorithms, the fips feature must be enabled at the crate
level or verification returns Ok(false).
Sourcepub fn is_expired_at(&self, now: u64) -> bool
pub fn is_expired_at(&self, now: u64) -> bool
Check whether this token is expired at the given unix timestamp.
Sourcepub fn is_valid_at(&self, now: u64) -> bool
pub fn is_valid_at(&self, now: u64) -> bool
Check whether this token is valid at the given unix timestamp (issued_at <= now < expires_at).
Trait Implementations§
Source§impl Clone for CapabilityToken
impl Clone for CapabilityToken
Source§fn clone(&self) -> CapabilityToken
fn clone(&self) -> CapabilityToken
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more