Skip to main content

MasterKey

Struct MasterKey 

Source
pub struct MasterKey(/* private fields */);
Expand description

The repository key.

Deliberately has no Debug, Display or Clone: the only ways out are MasterKey::expose_bytes, whose name is meant to be uncomfortable at a call site, and the derivations below.

Implementations§

Source§

impl MasterKey

Source

pub fn generate() -> Result<Self>

Draws a fresh key from the operating system’s entropy source.

§Errors

Error::Entropy when the platform refuses to provide randomness. Falling back to anything weaker would be worse than failing.

Source

pub fn from_bytes(bytes: [u8; 32]) -> Self

Wraps key material that came from a key file.

Source

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

The raw key material.

Named to make every call site read like the disclosure it is. Only the key file writer and export-key have any business calling it.

Source

pub fn key_id(&self) -> [u8; 8]

The fingerprint stored in every encrypted file’s header.

Identifies the key, not the suite, so it survives a future change of cipher and keeps unlock and export-key working across one.

§Panics

Never in practice: KEY_ID_LEN is eight bytes against HKDF’s ceiling of 8160, so the expansion cannot fail. Handing back half-derived material instead would put a wrong key_id into a file header for good.

Source

pub fn suite_key(&self, suite: u8) -> Result<SuiteKey>

The working key for suite.

§Errors

Error::Format for a suite this build cannot key.

Trait Implementations§

Source§

impl Drop for MasterKey

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 MasterKey

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