Skip to main content

CapabilityToken

Struct CapabilityToken 

Source
pub struct CapabilityToken {
    pub id: TokenId,
    pub resource: ResourcePattern,
    pub permissions: Vec<Permission>,
    pub issued_at: Timestamp,
    pub expires_at: Option<Timestamp>,
    pub scope: TokenScope,
    pub issuer: PublicKey,
    pub user_id: [u8; 8],
    pub approval_audit_id: AuditEntryId,
    pub single_use: bool,
    pub signature: Signature,
}
Expand description

A capability token granting permissions for a resource.

Fields§

§id: TokenId

Unique token identifier.

§resource: ResourcePattern

Resource pattern this token applies to.

§permissions: Vec<Permission>

Permissions granted.

§issued_at: Timestamp

When the token was issued.

§expires_at: Option<Timestamp>

When the token expires (None = no expiration within scope).

§scope: TokenScope

Token scope (session or persistent).

§issuer: PublicKey

Public key of the issuer (runtime).

§user_id: [u8; 8]

User who approved this token (key ID, first 8 bytes).

§approval_audit_id: AuditEntryId

Audit entry ID linking to the approval event.

§single_use: bool

Whether this token can only be used once (replay protection).

§signature: Signature

Cryptographic signature of the token.

Implementations§

Source§

impl CapabilityToken

Source

pub fn create( resource: ResourcePattern, permissions: Vec<Permission>, scope: TokenScope, user_id: [u8; 8], approval_audit_id: AuditEntryId, runtime_key: &KeyPair, ttl: Option<Duration>, ) -> Self

Create a new capability token.

This is typically called by the runtime after user approval.

Source

pub fn create_with_options( resource: ResourcePattern, permissions: Vec<Permission>, scope: TokenScope, user_id: [u8; 8], approval_audit_id: AuditEntryId, runtime_key: &KeyPair, ttl: Option<Duration>, single_use: bool, ) -> Self

Create a new capability token with additional options.

This is typically called by the runtime after user approval.

Source

pub fn signing_data(&self) -> Vec<u8>

Get the data used for signing (excludes the signature itself).

Format (v1):

  • 1 byte: version (0x01)
  • Length-prefixed token ID (UUID bytes)
  • Length-prefixed resource pattern string
  • 4 bytes: number of permissions
  • For each permission: length-prefixed string
  • 8 bytes: issued_at timestamp (i64 LE)
  • 1 byte: has_expiration flag
  • If has_expiration: 8 bytes expiration timestamp (i64 LE)
  • Length-prefixed scope string
  • 32 bytes: issuer public key
  • 8 bytes: user_id
  • Length-prefixed audit entry ID (UUID bytes)
  • 1 byte: single_use flag
Source

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

Verify the token’s signature.

§Errors

Returns CapabilityError::InvalidSignature if the signature is invalid.

Source

pub fn is_expired(&self) -> bool

Check if the token has expired.

Source

pub fn is_expired_with_skew(&self, skew_secs: i64) -> bool

Check if the token has expired, with clock skew tolerance.

A positive skew_secs value allows tokens that expired up to that many seconds ago to still be considered valid.

Source

pub fn validate(&self) -> CapabilityResult<()>

Check if the token is valid (not expired, signature OK).

Uses the default clock skew tolerance (30 seconds).

§Errors

Returns CapabilityError::TokenExpired if expired, or CapabilityError::InvalidSignature if the signature is invalid.

Source

pub fn validate_with_skew(&self, skew_secs: i64) -> CapabilityResult<()>

Check if the token is valid with custom clock skew tolerance.

§Errors

Returns CapabilityError::TokenExpired if expired, or CapabilityError::InvalidSignature if the signature is invalid.

Source

pub fn is_single_use(&self) -> bool

Check if this is a single-use token.

Source

pub fn grants(&self, resource: &str, permission: Permission) -> bool

Check if this token grants a permission for a resource.

Source

pub fn content_hash(&self) -> ContentHash

Hash the token for audit purposes.

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 Hash for CapabilityToken

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CapabilityToken

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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
Source§

impl Eq for CapabilityToken

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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<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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,