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: TokenIdUnique token identifier.
resource: ResourcePatternResource pattern this token applies to.
permissions: Vec<Permission>Permissions granted.
issued_at: TimestampWhen the token was issued.
expires_at: Option<Timestamp>When the token expires (None = no expiration within scope).
scope: TokenScopeToken scope (session or persistent).
issuer: PublicKeyPublic key of the issuer (runtime).
user_id: [u8; 8]User who approved this token (key ID, first 8 bytes).
approval_audit_id: AuditEntryIdAudit entry ID linking to the approval event.
single_use: boolWhether this token can only be used once (replay protection).
signature: SignatureCryptographic signature of the token.
Implementations§
Source§impl CapabilityToken
impl CapabilityToken
Sourcepub fn create(
resource: ResourcePattern,
permissions: Vec<Permission>,
scope: TokenScope,
user_id: [u8; 8],
approval_audit_id: AuditEntryId,
runtime_key: &KeyPair,
ttl: Option<Duration>,
) -> Self
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.
Sourcepub 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
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.
Sourcepub fn signing_data(&self) -> Vec<u8> ⓘ
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_attimestamp (i64 LE) - 1 byte:
has_expirationflag - 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_useflag
Sourcepub fn verify_signature(&self) -> CapabilityResult<()>
pub fn verify_signature(&self) -> CapabilityResult<()>
Verify the token’s signature.
§Errors
Returns CapabilityError::InvalidSignature if the signature is invalid.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the token has expired.
Sourcepub fn is_expired_with_skew(&self, skew_secs: i64) -> bool
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.
Sourcepub fn validate(&self) -> CapabilityResult<()>
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.
Sourcepub fn validate_with_skew(&self, skew_secs: i64) -> CapabilityResult<()>
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.
Sourcepub fn is_single_use(&self) -> bool
pub fn is_single_use(&self) -> bool
Check if this is a single-use token.
Sourcepub fn grants(&self, resource: &str, permission: Permission) -> bool
pub fn grants(&self, resource: &str, permission: Permission) -> bool
Check if this token grants a permission for a resource.
Sourcepub fn content_hash(&self) -> ContentHash
pub fn content_hash(&self) -> ContentHash
Hash the token for audit purposes.
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 moreSource§impl Debug for CapabilityToken
impl Debug for CapabilityToken
Source§impl<'de> Deserialize<'de> for CapabilityToken
impl<'de> Deserialize<'de> for CapabilityToken
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Hash for CapabilityToken
impl Hash for CapabilityToken
Source§impl PartialEq for CapabilityToken
impl PartialEq for CapabilityToken
Source§impl Serialize for CapabilityToken
impl Serialize for CapabilityToken
impl Eq for CapabilityToken
Auto Trait Implementations§
impl Freeze for CapabilityToken
impl RefUnwindSafe for CapabilityToken
impl Send for CapabilityToken
impl Sync for CapabilityToken
impl Unpin for CapabilityToken
impl UnsafeUnpin for CapabilityToken
impl UnwindSafe for CapabilityToken
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.