Skip to main content

KeyManager

Struct KeyManager 

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

密钥管理器(支持轮换)

维护一个当前活跃密钥和最多 3 个历史密钥(用于解密过渡期), 支持按时间间隔自动轮换检查。所有字段使用 RwLock 保护,可安全跨线程共享。

Implementations§

Source§

impl KeyManager

Source

pub fn new(initial_key: Vec<u8>) -> Self

创建密钥管理器,使用给定的初始密钥(版本号从 1 开始)

Source

pub fn with_rotation_interval(self, interval: Duration) -> Self

设置轮换间隔

Source

pub fn rotate(&self, new_key: Vec<u8>) -> Result<(), CryptoError>

轮换密钥

Source

pub fn needs_rotation(&self) -> bool

检查是否需要轮换

Source

pub fn current_key(&self) -> VersionedKey

获取当前密钥

Source

pub fn key_by_version(&self, version: u32) -> Option<VersionedKey>

按版本查找密钥

Source

pub fn previous_count(&self) -> usize

返回保留的旧密钥数量

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