Skip to main content

CapabilityToken

Struct CapabilityToken 

Source
pub struct CapabilityToken {
    pub version: u8,
    pub issuer: Vec<u8>,
    pub audience: Option<Vec<u8>>,
    pub scopes: Vec<String>,
    pub expires_at: u64,
    pub nonce: String,
    pub proofs: Vec<ProofLink>,
    pub signature: Vec<u8>,
}
Expand description

A CLASP capability token.

Token format: cap_<base64url(messagepack(CapabilityToken))>

Tokens form delegation chains where each child can only narrow the parent’s scopes, never widen them.

Fields§

§version: u8

Token version (currently 1)

§issuer: Vec<u8>

Issuer’s public key (Ed25519, 32 bytes)

§audience: Option<Vec<u8>>

Audience public key (None = bearer token)

§scopes: Vec<String>

Scopes granted (same “action:pattern” format as existing CLASP scopes)

§expires_at: u64

Expiration time (Unix timestamp, seconds)

§nonce: String

Unique nonce to prevent replay

§proofs: Vec<ProofLink>

Proof chain: signatures of parent tokens in the delegation chain

§signature: Vec<u8>

Signature over the token payload (by issuer)

Implementations§

Source§

impl CapabilityToken

Source

pub fn create_root( signing_key: &SigningKey, scopes: Vec<String>, expires_at: u64, audience: Option<Vec<u8>>, ) -> Result<Self>

Create and sign a new root capability token (no parent).

Source

pub fn delegate( &self, child_signing_key: &SigningKey, child_scopes: Vec<String>, expires_at: u64, audience: Option<Vec<u8>>, ) -> Result<Self>

Delegate this token to create a child with narrower scopes.

The child token can only have scopes that are a subset of this token’s scopes.

Source

pub fn verify_signature(&self) -> Result<()>

Verify this token’s signature

Source

pub fn is_expired(&self) -> bool

Check if the token is expired

Source

pub fn chain_depth(&self) -> usize

Get the delegation chain depth. Chain depth is bounded at validation time. See pentest CAP-03: Chain Depth Bypass

Source

pub fn encode(&self) -> Result<String>

Encode to the cap_<base64> wire format

Source

pub fn decode(token: &str) -> Result<Self>

Decode from the cap_<base64> wire format

Trait Implementations§

Source§

impl Clone for CapabilityToken

Source§

fn clone(&self) -> CapabilityToken

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CapabilityToken

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for CapabilityToken

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for CapabilityToken

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,