[core] TOTP, QR payloads, device key wrap: custos-totp, custos-qr, Vault::wrap_for_device (v0.2.0)

This commit is contained in:
2026-10-31 10:44:24 +01:00
parent fe90e7691b
commit 0b9cce40e2
13 changed files with 478 additions and 3 deletions
+17
View File
@@ -12,6 +12,7 @@
//! ```
mod crypto;
mod device;
mod format;
mod item;
mod save;
@@ -42,6 +43,8 @@ pub enum Error {
WrongPassword,
#[error("the vault file was changed or damaged after it was written")]
Corrupted,
#[error("this device's unlock key no longer opens the vault; use the master password")]
DeviceKeyRejected,
#[error("{0}")]
Io(#[from] std::io::Error),
}
@@ -160,6 +163,20 @@ impl Vault {
Ok(Vault { key, slots: header.slots, items: body.items })
}
/// Wraps the vault key for device unlock with key material only this device can produce (e.g. a
/// Windows Hello signature). Keep the blob on the device; see docs/FORMAT.md, "Device key wrap".
pub fn wrap_for_device(&self, material: &[u8]) -> Result<Vec<u8>, Error> {
Ok(device::wrap(&self.key, material))
}
/// Unlocks with a device blob instead of the password. Fails with `DeviceKeyRejected` when the
/// material is wrong or the blob was changed, and with `Corrupted` when it belongs to another vault.
pub fn open_with_device(bytes: &[u8], blob: &[u8], material: &[u8]) -> Result<Vault, Error> {
let (header, body_at) = Header::parse(bytes)?;
let key = device::unwrap(blob, material)?;
Vault::open_body(bytes, header, body_at, key)
}
/// The encrypted file contents, with a fresh body nonce.
pub fn to_bytes(&self) -> Result<Vec<u8>, Error> {
let body_nonce = crypto::random_nonce();