pub struct CapToken {
pub agent_id: String,
pub role: Role,
pub scopes: Vec<String>,
pub issued_at: u64,
pub expire_at: u64,
pub max_uses: Option<u32>,
pub nonce: String,
pub sig_hex: String,
}Expand description
Capability token. max_uses picks between OneTime / Session /
Limited.
The uses_left counter is server-side, on EngineState: the
token stays immutable, and the record holds the counter.
Fields§
§agent_id: StringIdentifier of the agent this token was minted for.
role: RoleThe Role the bearer is authorized to act as.
scopes: Vec<String>Free-form scope strings (interpretation is caller-defined; "*"
conventionally means unrestricted).
issued_at: u64Unix timestamp (seconds) when the token was minted.
expire_at: u64Unix timestamp (seconds) after which the token is expired.
max_uses: Option<u32>Remaining-use budget: None = unlimited (session token), Some(n)
= at most n uses (one-time when n == 1).
nonce: StringRandom per-mint value; also serves as the token’s server-side
lookup key (see CapToken::id).
sig_hex: StringHex-encoded HMAC-SHA256 signature over CapToken::signing_input.
Implementations§
Source§impl CapToken
impl CapToken
Sourcepub fn signing_input(&self) -> Vec<u8> ⓘ
pub fn signing_input(&self) -> Vec<u8> ⓘ
Input for the HMAC signature — the concatenation of every field
except sig itself.
Sourcepub fn is_expired(&self, now_unix: u64) -> bool
pub fn is_expired(&self, now_unix: u64) -> bool
Whether now_unix is at or past CapToken::expire_at.
Sourcepub fn encode(&self) -> String
pub fn encode(&self) -> String
Transport-safe string encoding — URL-safe base64 of the
serde_json representation. Used when SubAgents put the token
on the HTTP path via Authorization: Bearer <encode()>. The
HMAC signature covers every field, so the server verifies with
verify_sig after decoding.
Sourcepub fn decode(s: &str) -> Result<Self, CapTokenDecodeError>
pub fn decode(s: &str) -> Result<Self, CapTokenDecodeError>
The inverse of encode(): base64 decode followed by JSON
parse. Either failure returns CapTokenDecodeError — this is
the input-validation step when the server receives a Bearer
token.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for CapToken
impl<'de> Deserialize<'de> for CapToken
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>,
impl Eq for CapToken
impl StructuralPartialEq for CapToken
Auto Trait Implementations§
impl Freeze for CapToken
impl RefUnwindSafe for CapToken
impl Send for CapToken
impl Sync for CapToken
impl Unpin for CapToken
impl UnsafeUnpin for CapToken
impl UnwindSafe for CapToken
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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