Implement secure password generation (#8)

This commit is contained in:
Hermes Agent
2026-08-09 22:41:33 +00:00
parent 0e4cbef944
commit 834df46818
6 changed files with 726 additions and 0 deletions

View File

@@ -248,6 +248,48 @@ impl<'a> VaultWriter<'a> {
})
}
#[allow(clippy::too_many_arguments)]
pub fn store_generated(
&self,
path: &EntryPath,
contents: SecretBytes,
force: bool,
overwrite: OverwriteDecision,
signing: Option<&SigningPolicy>,
committer: &mut impl EntryCommitter,
) -> Result<WriteOutcome, WriteError> {
let original = match self.repository.read_entry(path) {
Ok(original) => Some(original),
Err(RepositoryError::NotFound { .. }) => None,
Err(error) => return Err(error.into()),
};
if original.is_some() && !force && overwrite == OverwriteDecision::Decline {
return Err(WriteError::Cancelled);
}
let recipients = RecipientPolicyManager::new(self.repository, self.keys)
.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}."),
};
if let Err(error) = committer.commit(&change) {
if let Err(rollback) = self.restore(path, original.as_ref()) {
return Err(WriteError::RollbackFailed {
operation: error,
rollback,
});
}
return Err(WriteError::Commit(error));
}
Ok(WriteOutcome {
path: path.clone(),
action: EntryAction::Insert,
})
}
#[allow(clippy::too_many_arguments)]
pub fn finish_edit(
&self,