Skip to main content

EntitlementCache

Struct EntitlementCache 

Source
pub struct EntitlementCache { /* private fields */ }

Implementations§

Source§

impl EntitlementCache

Source

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}.

Source

pub fn public_key(&self) -> &VerifyingKey

Source

pub fn allows(&self, tenant: &TenantId, action: Action) -> Verdict

The hot path. See the crate doc for its cost.

Source

pub fn notice(&self, tenant: &TenantId) -> Option<String>

The Grace banner / report-status warning, if the tenant is in Grace.

Source

pub fn state(&self, tenant: &TenantId) -> State

The state the cache holds for tenant; Free when unknown.

Source

pub fn fact(&self, tenant: &TenantId) -> Option<EntitlementFact>

A copy of the whole fact (caps, paid_until, source) for the product’s own checks.

Source

pub fn issued_unix_ms(&self) -> u64

The issue time of the snapshot the cache holds (0 before the first refresh).

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

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.

Source

pub fn push(&self, fact: EntitlementFact) -> Result<(), SignatureError>

One pushed fact. Verified before it replaces the tenant’s current fact.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.