Skip to main content

Claims

Struct Claims 

Source
#[non_exhaustive]
pub struct Claims { pub root: String, pub publish: Vec<String>, pub subscribe: Vec<String>, pub expires: Option<SystemTime>, pub issued: Option<SystemTime>, }
Expand description

The payload of a token: a root, plus the publish/subscribe prefixes granted beneath it.

Build one from Default with the with_* setters, sign it with Key::sign, and scope it to a connection with authorize.

let claims = moq_token::Claims::default()
    .with_root("room/123")
    .with_publish(["alice"])
    .with_subscribe([""]);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§root: String

The root for the publish/subscribe options below. It’s mostly for compression and is optional, defaulting to the empty string.

§publish: Vec<String>

If specified, the user can publish any matching broadcasts. If not specified, the user will not publish any broadcasts.

§subscribe: Vec<String>

If specified, the user can subscribe to any matching broadcasts. If not specified, the user will not receive announcements and cannot subscribe to any broadcasts.

§expires: Option<SystemTime>

The expiration time of the token as a unix timestamp.

§issued: Option<SystemTime>

The issued time of the token as a unix timestamp.

Implementations§

Source§

impl Claims

Source

pub fn with_root(self, root: impl Into<String>) -> Self

Set the root that the publish/subscribe prefixes are relative to.

Source

pub fn with_publish( self, paths: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Grant publish access to these prefixes, relative to the root.

Source

pub fn with_subscribe( self, paths: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Grant subscribe access to these prefixes, relative to the root.

Source

pub fn with_expires(self, at: impl Into<Option<SystemTime>>) -> Self

Expire the token at this time. Enforced by Key::verify.

Accepts an Option so a caller can pass one through without unwrapping it.

Source

pub fn with_issued(self, at: impl Into<Option<SystemTime>>) -> Self

Record when the token was issued. Purely informational; nothing enforces it.

Accepts an Option so a caller can pass one through without unwrapping it.

Source

pub fn validate(&self) -> Result<()>

Returns an error when the token grants nothing at all, making it useless.

Source

pub fn authorize(&self, path: &str) -> Result<Permissions>

The access these claims grant at path, rebased so each returned prefix is relative to path.

path and root must overlap, in either direction:

  • path extends the root (root demo, path demo/room), so the extra room narrows each prefix and drops the ones outside it.
  • path is a parent of the root (root demo, path ``), so demo is prepended to each prefix to keep it anchored where the token points.

Matching is segment-aware, so a root of foo does not cover foobar. Slashes at the boundaries are implicit: /demo/ and demo are the same path.

Returns Error::RootMismatch when the two don’t overlap, and Error::NoAccess when they do but every prefix falls outside path.

This is authorization only. Verify the signature first with Key::verify, which is where expiry is enforced.

Trait Implementations§

Source§

impl Clone for Claims

Source§

fn clone(&self) -> Claims

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Claims

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Claims

Source§

fn default() -> Claims

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Claims
where Claims: Default,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Claims

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V