Skip to main content

JwtKeySet

Struct JwtKeySet 

Source
pub struct JwtKeySet { /* private fields */ }
Expand description

JWT 密钥集:支持多密钥并存,以 kid 标识,实现无停机密钥轮换

Implementations§

Source§

impl JwtKeySet

Source

pub fn new( keys: HashMap<String, String>, active_kid: String, ) -> Result<Self, AuthError>

创建密钥集,校验所有密钥长度 ≥ 32 字节,active_kid 存在于 keys

Source

pub fn rotate( &self, new_kid: String, new_secret: String, ) -> Result<(), AuthError>

轮换密钥:新增 kid 设为 active,保留旧 kid(旧令牌用旧密钥验证直至过期)

Source

pub fn remove_kid(&self, kid: &str) -> Result<(), AuthError>

移除非 active 的 kid

Source

pub fn active_kid(&self) -> String

获取当前 active kid

Source

pub fn get_secret(&self, kid: &str) -> Result<String, AuthError>

按 kid 获取密钥

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> 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, 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, <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