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
impl MasterKey
Sourcepub fn generate() -> Result<Self>
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.
Sourcepub fn from_bytes(bytes: [u8; 32]) -> Self
pub fn from_bytes(bytes: [u8; 32]) -> Self
Wraps key material that came from a key file.
Sourcepub fn expose_bytes(&self) -> &[u8; 32]
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.
Sourcepub fn key_id(&self) -> [u8; 8]
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.