spacedb_access/revocation.rs
1//! Revocation — immediate, fail-closed.
2//!
3//! A [`RevocationSet`] is the set of revoked capability ids a node currently
4//! knows about. [`authorize`](crate::authorize) checks it on every access and (in
5//! a chain) on every link, so a revoked grant — or any ancestor of it — is denied
6//! the moment the node learns of the revocation.
7//!
8//! The honest boundary: "immediate" means *as soon as the revocation reaches this
9//! node's set*. Propagating revocations across a partitioned mesh is the
10//! transport's job; the engine simply fails closed against whatever set it holds.
11
12use std::collections::HashSet;
13
14/// The set of revoked capability ids known to a node.
15#[derive(Clone, Debug, Default)]
16pub struct RevocationSet {
17 revoked: HashSet<[u8; 16]>,
18}
19
20impl RevocationSet {
21 pub fn new() -> Self {
22 Self::default()
23 }
24
25 /// Revoke a capability by its id. Idempotent.
26 pub fn revoke(&mut self, capability_id: [u8; 16]) {
27 self.revoked.insert(capability_id);
28 }
29
30 /// Whether a capability id has been revoked.
31 pub fn is_revoked(&self, capability_id: &[u8; 16]) -> bool {
32 self.revoked.contains(capability_id)
33 }
34
35 /// Number of revoked ids.
36 pub fn len(&self) -> usize {
37 self.revoked.len()
38 }
39
40 pub fn is_empty(&self) -> bool {
41 self.revoked.is_empty()
42 }
43}