pub struct UsageCap { /* private fields */ }Expand description
A quantitative usage bound parsed from a Capability.
Capabilities are normally opaque presence tokens (sign_commit, acme:deploy):
holding the credential grants the action, with no notion of “how many times”.
A quantitative capability instead bounds a measured resource. The first such
resource is the call count: calls:<N> means “at most N exercises of this
credential”. The bound rides in the capability claim, which is part of the ACDC
SAID, so it cannot be edited without breaking the credential.
The verifier consumes a monotonic usage record alongside the credential: a presentation whose observed count has reached the cap is rejected with a distinct cap-exceeded verdict, and a presentation replaying an earlier (lower) count than the highest already observed is rejected as a rolled-back counter.
§Examples
use auths_keri::{Capability, UsageCap};
let cap = Capability::parse("calls:3").unwrap();
assert_eq!(UsageCap::from_capability(&cap), Some(UsageCap::calls(3)));
// A presence token carries no quantitative bound.
let sign = Capability::sign_commit();
assert_eq!(UsageCap::from_capability(&sign), None);Implementations§
Source§impl UsageCap
impl UsageCap
Sourcepub const fn calls(max_calls: u64) -> Self
pub const fn calls(max_calls: u64) -> Self
Construct a call-count cap admitting at most max_calls exercises.
Sourcepub fn from_capability(cap: &Capability) -> Option<Self>
pub fn from_capability(cap: &Capability) -> Option<Self>
Parse the quantitative usage bound carried by a capability, if any.
Recognizes the call-count grammar calls:<N> and the comparison spelling
calls<=<N>, where <N> is a non-negative decimal integer. Any other
capability (a presence token, a different resource) carries no bound and
yields None. A calls resource with a missing or non-numeric bound also
yields None — the credential then has no enforceable quantitative cap and
is treated as an ordinary (unbounded) capability, never silently zero.
Sourcepub fn from_capabilities(caps: &[Capability]) -> Option<Self>
pub fn from_capabilities(caps: &[Capability]) -> Option<Self>
The first quantitative usage bound among a set of capabilities, if any.
A credential carries at most one call-count cap; this returns the first one found so the verifier can enforce it regardless of where it sits among the granted capabilities.
Sourcepub fn is_malformed_quant_predicate(cap: &Capability) -> bool
pub fn is_malformed_quant_predicate(cap: &Capability) -> bool
Whether cap is a MALFORMED quantitative usage predicate.
true iff the capability targets the reserved calls usage resource (the
calls: / calls<= prefix) but its bound does NOT parse to a valid
non-negative call count — e.g. calls:, calls:abc, calls:-1. Such a
capability looks like a budget but enforces none: Self::from_capability
yields None, so the credential would verify at any count. An issuer must
refuse it rather than mint a cap that is silently no cap.
A well-formed cap (calls:3) is not malformed; a presence token
(sign_commit, acme:deploy) is not malformed (it targets no usage
resource); only a calls-resource capability with an unparseable bound is.
§Examples
use auths_keri::{Capability, UsageCap};
assert!(UsageCap::is_malformed_quant_predicate(&Capability::parse("calls:abc").unwrap()));
assert!(UsageCap::is_malformed_quant_predicate(&Capability::parse("calls:").unwrap()));
assert!(!UsageCap::is_malformed_quant_predicate(&Capability::parse("calls:3").unwrap()));
assert!(!UsageCap::is_malformed_quant_predicate(&Capability::sign_commit()));Trait Implementations§
impl Copy for UsageCap
Source§impl<'de> Deserialize<'de> for UsageCap
impl<'de> Deserialize<'de> for UsageCap
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 UsageCap
impl StructuralPartialEq for UsageCap
Auto Trait Implementations§
impl Freeze for UsageCap
impl RefUnwindSafe for UsageCap
impl Send for UsageCap
impl Sync for UsageCap
impl Unpin for UsageCap
impl UnsafeUnpin for UsageCap
impl UnwindSafe for UsageCap
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,
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.