pub struct EntitlementCache { /* private fields */ }Implementations§
Source§impl EntitlementCache
impl EntitlementCache
Sourcepub fn new(public_key: &[u8; 32], billing_url: &str) -> Result<Self, KeyError>
pub fn new(public_key: &[u8; 32], billing_url: &str) -> Result<Self, KeyError>
public_key is monetize’s 32-byte Ed25519 verifying key; billing_url is the
pay page template, e.g. https://gunnar.rs/billing/{tenant}.
pub fn public_key(&self) -> &VerifyingKey
Sourcepub fn allows(&self, tenant: &TenantId, action: Action) -> Verdict
pub fn allows(&self, tenant: &TenantId, action: Action) -> Verdict
The hot path. See the crate doc for its cost.
Sourcepub fn notice(&self, tenant: &TenantId) -> Option<String>
pub fn notice(&self, tenant: &TenantId) -> Option<String>
The Grace banner / report-status warning, if the tenant is in Grace.
Sourcepub fn state(&self, tenant: &TenantId) -> State
pub fn state(&self, tenant: &TenantId) -> State
The state the cache holds for tenant; Free when unknown.
Sourcepub fn fact(&self, tenant: &TenantId) -> Option<EntitlementFact>
pub fn fact(&self, tenant: &TenantId) -> Option<EntitlementFact>
A copy of the whole fact (caps, paid_until, source) for the product’s own checks.
Sourcepub fn issued_unix_ms(&self) -> u64
pub fn issued_unix_ms(&self) -> u64
The issue time of the snapshot the cache holds (0 before the first refresh).
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn refresh(&self, snapshot_bytes: &[u8]) -> Result<usize, RefreshError>
pub fn refresh(&self, snapshot_bytes: &[u8]) -> Result<usize, RefreshError>
Replace everything with a signed Snapshot (its JSON bytes). Nothing changes
unless the envelope and every fact verify and the snapshot is not older than
the one held. Returns the number of tenants now known.
Sourcepub fn push(&self, fact: EntitlementFact) -> Result<(), SignatureError>
pub fn push(&self, fact: EntitlementFact) -> Result<(), SignatureError>
One pushed fact. Verified before it replaces the tenant’s current fact.
Auto Trait Implementations§
impl !Freeze for EntitlementCache
impl RefUnwindSafe for EntitlementCache
impl Send for EntitlementCache
impl Sync for EntitlementCache
impl Unpin for EntitlementCache
impl UnsafeUnpin for EntitlementCache
impl UnwindSafe for EntitlementCache
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
Mutably borrows from an owned value. Read more