pub struct ConsentStore { /* private fields */ }Expand description
The set of consent decisions a host holds: a keyed table of legacy boolean
ConsentRecords and an append-only ledger of scope-level
ConsentReceipts (docs/context-reuse.md §3). Both are serde-able so a
host can persist a user’s decisions — and the receipt ledger — across runs.
Implementations§
Source§impl ConsentStore
impl ConsentStore
pub fn new() -> Self
Sourcepub fn record(&mut self, record: ConsentRecord)
pub fn record(&mut self, record: ConsentRecord)
Record (or replace) legacy boolean consent for a provider.
Stamps granted_at with the host clock when the caller left it unset.
The field existed from the start and was never populated by anything
— every consent decision the reference host recorded went into the
ledger with no time on it, which is precisely the datum an audit needs
(“when did I agree to this?”). Stamping at insertion is the one place
that can answer honestly; a caller replaying a persisted decision keeps
its original instant via ConsentRecord::granted_at.
Sourcepub fn record_receipt(&mut self, receipt: ConsentReceipt)
pub fn record_receipt(&mut self, receipt: ConsentReceipt)
Append a scope-level consent receipt to the audit ledger. Append-only: this never removes or edits an earlier receipt (§3).
Sourcepub fn receipts(&self) -> &[ConsentReceipt]
pub fn receipts(&self) -> &[ConsentReceipt]
The full append-only receipt ledger, in the order receipts were granted — the audit trail.
Sourcepub fn receipts_for<'a>(
&'a self,
provider_id: &'a str,
) -> impl Iterator<Item = &'a ConsentReceipt>
pub fn receipts_for<'a>( &'a self, provider_id: &'a str, ) -> impl Iterator<Item = &'a ConsentReceipt>
Every receipt recorded for a provider, in grant order.
Sourcepub fn has_receipt(&self, provider_id: &str, scope: &EgressScope) -> bool
pub fn has_receipt(&self, provider_id: &str, scope: &EgressScope) -> bool
Whether any recorded receipt authorizes scope for provider_id
(presence, ignoring expiry). This is what the zero-clock runtime gate
consults; a host that also enforces expiry uses live_receipt.
Sourcepub fn live_receipt(
&self,
provider_id: &str,
scope: &EgressScope,
now: &str,
) -> Option<&ConsentReceipt>
pub fn live_receipt( &self, provider_id: &str, scope: &EgressScope, now: &str, ) -> Option<&ConsentReceipt>
The receipt authorizing scope for provider_id that is live at now
(presence and non-expiry), if any. A host enforcing expiry gates on
this against its own clock (docs/context-reuse.md §3).
Sourcepub fn revoke(&mut self, provider_id: &str) -> Option<ConsentRecord>
pub fn revoke(&mut self, provider_id: &str) -> Option<ConsentRecord>
Withdraw consent for a provider, returning the prior record if any.
Sourcepub fn get(&self, provider_id: &str) -> Option<&ConsentRecord>
pub fn get(&self, provider_id: &str) -> Option<&ConsentRecord>
The recorded decision for a provider, if consent was granted.
Sourcepub fn is_consented(&self, provider_id: &str) -> bool
pub fn is_consented(&self, provider_id: &str) -> bool
Whether consent has been recorded for a provider.
Sourcepub fn requires_consent(info: &ProviderInfo) -> bool
pub fn requires_consent(info: &ProviderInfo) -> bool
Whether a provider needs consent before any query: a provider needs it
if it declares the boolean egress flag or any off-machine egress
scope (§3.5, §3). A purely local provider is always permitted — nothing
it can do leaves the machine.
Sourcepub fn evaluate(&self, id: &str, info: &ProviderInfo) -> ConsentDecision
pub fn evaluate(&self, id: &str, info: &ProviderInfo) -> ConsentDecision
The host’s pre-query consent gate: may we transmit a query to this
provider right now, and if not, why (docs/context-reuse.md §3)?
- A provider declaring off-machine egress scopes is governed by the
receipt gate: permitted only when every off-machine scope has a
recorded receipt; otherwise
NeedsReceiptsnames the scopes still missing one. (This is presence-based — a host enforcing expiry prunes/consults live receipts with its own clock.) - A provider declaring only the boolean
egressflag (no scopes) is governed by the legacy gate: permitted with a recordedConsentRecord, elseNeedsConsent. - A purely local provider is
Permitted.
Trait Implementations§
Source§impl Clone for ConsentStore
impl Clone for ConsentStore
Source§fn clone(&self) -> ConsentStore
fn clone(&self) -> ConsentStore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more