Token

Struct Token 

Source
pub struct Token {
    pub origin: String,
    pub feature: String,
    pub expiry: u64,
    pub is_subdomain: bool,
    pub is_third_party: bool,
    pub usage: Usage,
}
Expand description

An already decoded and maybe-verified token.

Fields§

§origin: String§feature: String§expiry: u64§is_subdomain: bool§is_third_party: bool§usage: Usage

Implementations§

Source§

impl Token

Source

pub fn origin(&self) -> &str

Source

pub fn feature(&self) -> &str

Source

pub fn expiry_since_unix_epoch(&self) -> Duration

Source

pub fn expiry_time(&self) -> Option<SystemTime>

Source

pub fn is_expired(&self) -> bool

Source

pub fn from_buffer( buffer: &[u8], verify_signature: impl FnOnce(&[u8; 64], &[u8]) -> bool, ) -> Result<Self, TokenValidationError>

Most high-level function: For a given buffer, tries to parse it and verify it as a token.

Source

pub fn from_raw_token( token: &RawToken, verify_signature: impl FnOnce(&[u8; 64], &[u8]) -> bool, ) -> Result<Self, TokenValidationError>

Validates a RawToken’s signature and converts the token if valid.

Source

pub fn from_raw_token_unverified( token: &RawToken, ) -> Result<Self, TokenValidationError>

Converts the token from a raw token, without verifying first.

Source

pub fn from_payload( version: u8, payload: &[u8], ) -> Result<Self, TokenValidationError>

Converts the token from a raw payload, version pair.

Source

pub fn to_payload(&self) -> Vec<u8>

Converts the token to a raw payload.

Source

pub fn to_signature_data(&self) -> Vec<u8>

Converts the token to the data that should be signed.

Source

pub fn to_signed_token(&self, sign: impl FnOnce(&[u8]) -> [u8; 64]) -> Vec<u8>

Turns the token into a fully signed token.

Trait Implementations§

Source§

impl Debug for Token

Source§

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

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

impl<'de> Deserialize<'de> for Token

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 PartialEq for Token

Source§

fn eq(&self, other: &Token) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Token

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

impl Eq for Token

Source§

impl StructuralPartialEq for Token

Auto Trait Implementations§

§

impl Freeze for Token

§

impl RefUnwindSafe for Token

§

impl Send for Token

§

impl Sync for Token

§

impl Unpin for Token

§

impl UnwindSafe for Token

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, 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,