Skip to main content

RecoveryCode

Struct RecoveryCode 

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

一份恢复码。

持有 32 字节熵,析构时清零。不实现 Clone——与 SecretKey 同理, 复制要显式可见,便于审计。

Implementations§

Source§

impl RecoveryCode

Source

pub fn generate() -> Self

生成一份新的恢复码。

Source

pub const fn from_entropy(entropy: [u8; 32]) -> Self

由已有熵构造(用于测试向量与跨实现验证)。

Source

pub const fn entropy(&self) -> &[u8; 32]

借出底层熵。

Source

pub fn to_words(&self) -> Vec<&'static str>

编码成 26 个词。

Source

pub fn to_phrase(&self) -> String

编码成空格分隔的一行。

Source

pub fn from_words(words: &[&str]) -> Result<Self, ParseError>

从词序列解析。

输入会被归一化:去首尾空白、转小写。用户手抄后重新输入时大小写和 空格很难完全一致,为此拒绝是没有意义的刁难。

§Errors

见 ParseError,每种失败对应不同的用户动作。

Source

pub fn from_phrase(phrase: &str) -> Result<Self, ParseError>

从一行文本解析,按空白切分。

§Errors

同 RecoveryCode::from_words。

Source

pub fn to_kek(&self, vault_salt: &[u8; 16]) -> Kek

派生 KEK。

vault_salt 参与派生,所以同一份恢复码在不同 vault 下得到不同 KEK—— 与密码派生保持一致,避免跨库误用。

Trait Implementations§

Source§

impl Debug for RecoveryCode

Source§

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

刻意不打印内容:它等同于一把万能钥匙,落到日志里就是灾难。

Source§

impl Drop for RecoveryCode

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Zeroize for RecoveryCode

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

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