pub struct NarrowingMatrix { /* private fields */ }Expand description
A 256-bit capability mask with cryptographic narrowing guarantees.
NarrowingMatrix enforces that delegated capability sets are strict subsets
of their parent’s set. The check is O(1): eight 64-bit AND operations on
modern hardware, regardless of how many named capabilities exist.
Each capability name maps deterministically to a bit position in the 256-bit field via Blake3. Two distinct capability names that collide on the same bit are both authorized by setting that bit — this is intentional and conservative: the narrowing guarantee (sub ⊆ parent) still holds.
§Collision behaviour
Hash-based mapping distributes capabilities uniformly across 256 bits. With
the birthday bound, collisions become likely when a single deployment uses
more than ~100–150 distinct capability names. Collisions are not a security
vulnerability — they produce false positives (capability A grants slot X,
and so does capability B, so holding A also passes a check for B). For large
deployments use CapabilityRegistry to assign explicit, collision-free
bit positions.
§Narrowing invariant
For any parent mask P and requested mask R:
R.is_subset_of(P) ↔ (P.mask & R.mask) == R.maskThis is the sole enforcement rule. No external registry, no network call, no configuration file is required at verification time.
Implementations§
Source§impl NarrowingMatrix
impl NarrowingMatrix
Sourcepub fn from_capabilities<S: AsRef<str>>(caps: &[S]) -> Self
pub fn from_capabilities<S: AsRef<str>>(caps: &[S]) -> Self
Build a mask from a slice of capability name strings.
Each name is mapped to a bit position via Blake3. Order does not matter. Duplicate names are idempotent.
For deployments with more than ~100 distinct capability names, prefer
CapabilityRegistry::build_mask to avoid hash-space collisions.
Sourcepub fn from_csv(csv: &str) -> Self
pub fn from_csv(csv: &str) -> Self
Parse a comma-separated capability string (e.g. "trade.equity,portfolio.read").
Sourcepub fn is_subset_of(&self, parent: &NarrowingMatrix) -> bool
pub fn is_subset_of(&self, parent: &NarrowingMatrix) -> bool
Return true if self is a subset of parent.
This is the sole enforcement rule for narrowing. A sub-passport cannot carry capabilities that its parent does not have.
Sourcepub fn enforce_narrowing(&self, parent: &NarrowingMatrix) -> Result<(), A1Error>
pub fn enforce_narrowing(&self, parent: &NarrowingMatrix) -> Result<(), A1Error>
Validate that self is a subset of parent, returning an error otherwise.
Sourcepub fn intersect(&self, other: &NarrowingMatrix) -> NarrowingMatrix
pub fn intersect(&self, other: &NarrowingMatrix) -> NarrowingMatrix
Produce the intersection of two masks (logical AND).
Useful for computing the maximum allowed sub-mask from a parent.
Sourcepub fn commitment(&self) -> [u8; 32]
pub fn commitment(&self) -> [u8; 32]
A 32-byte Blake3 commitment over this mask, domain-separated.
Stored in the cert extension so that a tampered mask fails the
extension commitment check inside DelegationCert::signable_bytes.
Sourcepub fn as_bytes(&self) -> &[u8; 32]
pub fn as_bytes(&self) -> &[u8; 32]
The raw 32-byte mask. Suitable for serialization and storage.
Sourcepub fn capacity_count(&self) -> u32
pub fn capacity_count(&self) -> u32
Count how many bits are set (number of unique capability slots in use).
Trait Implementations§
Source§impl Clone for NarrowingMatrix
impl Clone for NarrowingMatrix
Source§fn clone(&self) -> NarrowingMatrix
fn clone(&self) -> NarrowingMatrix
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NarrowingMatrix
impl Debug for NarrowingMatrix
Source§impl Default for NarrowingMatrix
impl Default for NarrowingMatrix
Source§impl<'de> Deserialize<'de> for NarrowingMatrix
impl<'de> Deserialize<'de> for NarrowingMatrix
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 Display for NarrowingMatrix
impl Display for NarrowingMatrix
Source§impl PartialEq for NarrowingMatrix
impl PartialEq for NarrowingMatrix
Source§fn eq(&self, other: &NarrowingMatrix) -> bool
fn eq(&self, other: &NarrowingMatrix) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for NarrowingMatrix
impl Serialize for NarrowingMatrix
impl Eq for NarrowingMatrix
impl StructuralPartialEq for NarrowingMatrix
Auto Trait Implementations§
impl Freeze for NarrowingMatrix
impl RefUnwindSafe for NarrowingMatrix
impl Send for NarrowingMatrix
impl Sync for NarrowingMatrix
impl Unpin for NarrowingMatrix
impl UnsafeUnpin for NarrowingMatrix
impl UnwindSafe for NarrowingMatrix
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.