Skip to main content

Guard

Struct Guard 

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

请求守卫:一个可跨请求共享、可跨线程克隆的加密句柄。

构造之后的一切加解密都经由它转发到 EncryptionManager;克隆只是 Arc 引用计数递增,不含任何密钥拷贝。

Implementations§

Source§

impl Guard

Source

pub fn new(manager: EncryptionManager) -> Self

从一个已经建好的 Manager 构造。

Source

pub fn from_master_key( master_key: &[u8], default_identifier: &str, ) -> Result<Self>

从 32 字节主密钥构造(内部走 crate::factory::EncryptionManagerFactory)。

构造时即完成全部校验(主密钥长度、默认算法是否注册),配置错了就在启动时炸。

Source

pub fn manager(&self) -> &EncryptionManager

共享的 Manager。总是存在。

Source

pub fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>>

用默认算法加密。

Source

pub fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>>

用默认算法解密。

Source

pub fn encrypt_with( &self, identifier: &str, plaintext: &[u8], ) -> Result<Vec<u8>>

用指定算法加密。

Source

pub fn decrypt_with( &self, identifier: &str, ciphertext: &[u8], ) -> Result<Vec<u8>>

用指定算法解密。

Source

pub fn identifiers(&self) -> Vec<&str>

已注册算法标识(健康检查 / 日志用)。

Trait Implementations§

Source§

impl Clone for Guard

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Guard

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Guarded for Guard

Source§

fn guard(&self) -> &Guard

取出守卫。永远成功 —— 取不到说明状态装配错了,那是编译期该发现的事。

Auto Trait Implementations§

§

impl !RefUnwindSafe for Guard

§

impl !UnwindSafe for Guard

§

impl Freeze for Guard

§

impl Send for Guard

§

impl Sync for Guard

§

impl Unpin for Guard

§

impl UnsafeUnpin for Guard

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromExt for T

Source§

fn from_<T>(t: T) -> Self
where Self: From<T>,

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> IntoExt for T

Source§

fn into_<T>(self) -> T
where Self: Into<T>,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> TryFromExt for T

Source§

fn try_from_<T>(t: T) -> Result<Self, Self::Error>
where Self: TryFrom<T>,

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<T> TryIntoExt for T

Source§

fn try_into_<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,