Skip to main content

KeyVault

Struct KeyVault 

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

密钥保险库,集成生成、轮换、存储、检索与版本管理

所有操作线程安全,通过 parking_lot::RwLock 保护内部状态。

Implementations§

Source§

impl KeyVault

Source

pub fn new(rotation_policy: RotationPolicy) -> Self

创建密钥保险库,指定轮换策略

Source

pub fn generate_key( &self, name: &str, algorithm: KeyAlgorithm, purpose: KeyPurpose, ) -> Result<String, KeyError>

生成新密钥并存入存储,返回密钥 ID

Source

pub fn rotate_key(&self, name: &str) -> Result<String, KeyError>

轮换密钥:弃用当前版本并生成新版本

Source

pub fn get_key(&self, key_id: &str) -> Option<KeyEntry>

获取密钥(按 ID),同时递增使用计数

Source

pub fn get_latest_key(&self, name: &str) -> Option<KeyEntry>

获取最新版本密钥(按名称)

Source

pub fn get_key_by_version(&self, name: &str, version: u32) -> Option<KeyEntry>

按名称与版本获取密钥

Source

pub fn get_all_versions(&self, name: &str) -> Vec<KeyEntry>

获取指定名称的所有版本

Source

pub fn revoke_key(&self, key_id: &str) -> Result<(), KeyError>

吊销密钥

Source

pub fn deprecate_key(&self, key_id: &str) -> Result<(), KeyError>

弃用密钥

Source

pub fn needs_rotation(&self, name: &str) -> bool

检查密钥是否需要轮换

Source

pub fn auto_rotate(&self, name: &str) -> Option<String>

自动轮换检查:若需要轮换则执行

Source

pub fn key_count(&self) -> usize

返回密钥总数

Source

pub fn version_count(&self, name: &str) -> usize

返回指定名称的版本数

Source

pub fn key_names(&self) -> Vec<String>

返回所有密钥名称

Source

pub fn audit_log(&self) -> KeyAuditLog

返回审计日志的只读快照

Source

pub fn usage_count(&self, key_id: &str) -> u64

返回指定密钥的使用次数

Source

pub fn get_by_tag(&self, tag: &str) -> Vec<KeyEntry>

按标签检索密钥

Source

pub fn get_by_status(&self, status: KeyStatus) -> Vec<KeyEntry>

按状态检索密钥

Source

pub fn delete_key(&self, key_id: &str) -> Result<KeyEntry, KeyError>

删除密钥(永久移除)

Trait Implementations§

Source§

impl Debug for KeyVault

Source§

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

Formats the value using the given formatter. Read more

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

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