Implement pass-otp compatible TOTP and HOTP

This commit is contained in:
Hermes Agent
2026-08-10 01:22:53 +00:00
parent b8c614e141
commit 4bd39b1ef2
12 changed files with 2382 additions and 28 deletions

View File

@@ -11,6 +11,7 @@ pub mod crypto;
pub mod generate;
pub mod git;
pub mod mutation;
pub mod otp;
pub mod presentation;
pub mod read;
pub mod recipient;

1083
crates/storage/src/otp.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -83,6 +83,14 @@ pub struct EntryCommit {
}
impl EntryCommit {
pub(crate) fn new(path: EntryPath, action: EntryAction, message: String) -> Self {
Self {
path,
action,
message,
}
}
pub fn path(&self) -> &EntryPath {
&self.path
}
@@ -205,11 +213,11 @@ impl<'a> VaultWriter<'a> {
.keys
.encrypt(contents.into_secret(), recipients.recipients())?;
self.repository.write_entry(&path, &ciphertext)?;
let change = EntryCommit {
path: path.clone(),
action: EntryAction::Insert,
message: format!("Add given password for {path} to store."),
};
let change = EntryCommit::new(
path.clone(),
EntryAction::Insert,
format!("Add given password for {path} to store."),
);
if let Err(error) = committer.commit(&change) {
if let Err(rollback) = self.restore(&path, original.as_ref()) {
return Err(WriteError::RollbackFailed {
@@ -270,11 +278,11 @@ impl<'a> VaultWriter<'a> {
.resolve_for_entry(path, signing)?;
let ciphertext = self.keys.encrypt(contents, recipients.recipients())?;
self.repository.write_entry(path, &ciphertext)?;
let change = EntryCommit {
path: path.clone(),
action: EntryAction::Insert,
message: format!("Add generated password for {path}."),
};
let change = EntryCommit::new(
path.clone(),
EntryAction::Insert,
format!("Add generated password for {path}."),
);
if let Err(error) = committer.commit(&change) {
if let Err(rollback) = self.restore(path, original.as_ref()) {
return Err(WriteError::RollbackFailed {
@@ -320,11 +328,11 @@ impl<'a> VaultWriter<'a> {
.resolve_for_entry(&session.path, signing)?;
let ciphertext = self.keys.encrypt(replacement, recipients.recipients())?;
self.repository.write_entry(&session.path, &ciphertext)?;
let change = EntryCommit {
path: session.path.clone(),
action: EntryAction::Edit,
message: format!("Edit password for {} using {}.", session.path, editor_name),
};
let change = EntryCommit::new(
session.path.clone(),
EntryAction::Edit,
format!("Edit password for {} using {}.", session.path, editor_name),
);
if let Err(error) = committer.commit(&change) {
if let Err(rollback) = self.restore(&session.path, session.original_ciphertext.as_ref())
{