Skip to main content

KeyRotationManager

Struct KeyRotationManager 

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

密钥轮换管理器

管理多个版本的密钥,支持:

  • 轮换生成新版本密钥
  • 用最新密钥签名
  • 用任意历史密钥验证(向后兼容)
  • 自动淘汰过期密钥

Implementations§

Source§

impl KeyRotationManager

Source

pub fn new(max_versions: usize) -> Self

创建密钥轮换管理器,指定最大保留版本数

Source

pub fn with_initial_key(key: Vec<u8>) -> Self

初始化首个密钥版本

Source

pub fn rotate_key(&mut self, new_key: Vec<u8>) -> u32

轮换到新密钥,返回新版本号

Source

pub fn sign(&self, message: &[u8]) -> (u32, Vec<u8>)

使用当前(最新)密钥签名

Source

pub fn verify(&self, message: &[u8], version: u32, signature: &[u8]) -> bool

验证签名(尝试所有保留的密钥版本)

Source

pub fn current_version(&self) -> u32

返回当前密钥版本号

Source

pub fn version_count(&self) -> usize

返回保留的密钥版本数量

Source

pub fn versions(&self) -> Vec<u32>

返回所有保留的版本号

Source

pub fn key_created_at(&self, version: u32) -> Option<u64>

返回指定版本密钥的创建时间(Unix 秒),不存在返回 None

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