Jwt

Struct Jwt 

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

Implementations§

Source§

impl Jwt

Source

pub fn default(iss: &str) -> Self

初始化

  • iss 签发人
Source

pub fn payload(&mut self, sub: &str, aud: &str, custom: JsonValue) -> &mut Self

token信息

  • sub 主题
  • aud 受众
  • custom 自定义内容
Source

pub fn nbf_exp(&mut self, nbf: i64, exp: i64) -> &mut Self

生效时间与过期时间设置

  • nbf 生效时间
  • exp 过期时间 分钟
Source

pub fn sign(&mut self, key: &str) -> String

返回口令

  • key 加密密钥
Source

pub fn verify(token: &str, key: &str) -> bool

验证

Examples found in repository?
examples/jwt.rs (line 18)
4fn main() {
5    // let mut data = jwt::Jwt::default("admin");
6    // let data = data.payload("2222", "1111", object! {
7    //     "name":"123123"
8    // });
9    // data.nbf_exp(0, 0);
10    // let token = data.sign("123456");
11    // let data = jwt::Jwt::verify(token.as_str().clone(), "123456");
12    // println!("{}", data);
13    // let data = jwt::Jwt::info(token.as_str().clone());
14    // println!("{}", data);
15
16    let token = "12313";
17
18    let data = jwt::Jwt::verify(token.clone(), "123456");
19    println!("{}",data);
20}
Source

pub fn info(token: &str) -> JsonValue

信息

Auto Trait Implementations§

§

impl Freeze for Jwt

§

impl RefUnwindSafe for Jwt

§

impl Send for Jwt

§

impl Sync for Jwt

§

impl Unpin for Jwt

§

impl UnwindSafe for Jwt

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