diff --git a/src/command/stash.rs b/src/command/stash.rs index ffd3b97..61aaa6c 100644 --- a/src/command/stash.rs +++ b/src/command/stash.rs @@ -62,8 +62,12 @@ impl Command for StashPop { return Ok(None); } stash_refs.sort(); - let last = stash_refs.last().unwrap().clone(); - let commit_hash = refs.get_ref(&last)?.unwrap(); + let last = stash_refs + .pop() + .ok_or_else(|| VctrlError::Other("no stash entries".into()))?; + let commit_hash = refs + .get_ref(&last)? + .ok_or_else(|| VctrlError::NotFound(format!("stash ref '{}' missing", last)))?; let commit = store.get_commit(&commit_hash)?; refs.delete_ref(&last)?; Ok(Some(commit.tree)) diff --git a/src/command/verify_commit.rs b/src/command/verify_commit.rs index 24d9ac6..6ca15b2 100644 --- a/src/command/verify_commit.rs +++ b/src/command/verify_commit.rs @@ -1,15 +1,15 @@ use crate::codec::Encoder; use crate::command::Command; +use crate::crypto::Verifier; use crate::domain::hash::Hash; use crate::domain::object::Object; use crate::error::VctrlError; use crate::hashing::Hasher; use crate::storage::traits::{ObjectStore, RefStore}; -use ed25519_dalek::{Signature, VerifyingKey}; pub struct VerifyCommit { pub commit_hash: Hash, - pub verifying_key: VerifyingKey, + pub verifier: Box, pub encoder: Box, pub hasher: Box, } @@ -47,13 +47,6 @@ impl Command for VerifyCommit { self.encoder.encode_commit(&pre_sig_commit, &mut buf)?; let pre_sig_hash = self.hasher.hash_commit_encoded(&buf); - let signature = Signature::try_from(sig_bytes.as_slice()) - .map_err(|_| VctrlError::Other("invalid signature format".into()))?; - - self.verifying_key - .verify_strict(pre_sig_hash.as_bytes(), &signature) - .map_err(|_| VctrlError::Other("signature verification failed".into()))?; - - Ok(true) + self.verifier.verify(pre_sig_hash.as_bytes(), &sig_bytes) } }