Skip to main content

CipherId

Enum CipherId 

Source
#[repr(u8)]
pub enum CipherId { ChaCha20Poly1305 = 1, Aes256Gcm = 2, }
Expand description

AEAD 算法选择。

Variants§

§

ChaCha20Poly1305 = 1

ChaCha20-Poly1305(RFC 8439),12 字节 nonce。

参考实现与测试向量使用此算法。生产默认为 XChaCha20-Poly1305(24 字节 nonce), 目前尚未实现,见 docs/research/02-file-format-spec.md §5.2 的说明。

§

Aes256Gcm = 2

AES-256-GCM。有 AES-NI 硬件加速时更快。

Implementations§

Source§

impl CipherId

Source

pub const fn from_u8(v: u8) -> Result<Self>

由 header 中的数值解析。

§Errors

未知取值时返回 Error::MalformedHeader。

Source

pub fn encrypt( self, key: &SecretKey, nonce: &[u8; 12], plaintext: &[u8], aad: &[u8], ) -> Result<Vec<u8>>

AEAD 加密。输出为 密文 || tag。

§Errors

底层 AEAD 失败时返回错误(正常输入下不会发生)。

Source

pub fn decrypt( self, key: &SecretKey, nonce: &[u8; 12], ciphertext: &[u8], aad: &[u8], ) -> Result<Option<Vec<u8>>>

AEAD 解密。输入为 密文 || tag。

认证失败时返回 Ok(None),让调用方区分「密码不对」和「真的坏了」—— 这在扫描场景下很关键:试错密码是正常流程,不该当作错误处理。

§Errors

目前不返回 Err,签名保留以便未来扩展。

Trait Implementations§

Source§

impl Clone for CipherId

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 Copy for CipherId

Source§

impl Debug for CipherId

Source§

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

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

impl Eq for CipherId

Source§

impl PartialEq for CipherId

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CipherId

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