Skip to content

Commit

Permalink
consolidated methods
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Embacher <[email protected]>
  • Loading branch information
vembacher committed Jul 26, 2023
1 parent c1eadee commit 900423e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
16 changes: 2 additions & 14 deletions src/rekor/models/checkpoint.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::crypto::merkle::{MerkleProofVerifier, Rfc6269Default};
use crate::crypto::{CosignVerificationKey, Signature};
use crate::errors::SigstoreError;
use crate::errors::SigstoreError::{ConsistencyProofError, UnexpectedError};
use crate::errors::SigstoreError::ConsistencyProofError;
use crate::rekor::models::checkpoint::ParseCheckpointError::*;
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
Expand Down Expand Up @@ -158,7 +158,7 @@ impl SignedCheckpoint {
}

/// Checks if the checkpoint and inclusion proof are valid together.
pub(crate) fn valid_consistency_proof(
pub(crate) fn is_valid_for_proof(
&self,
proof_root_hash: &Output<Rfc6269Default>,
proof_tree_size: u64,
Expand All @@ -173,18 +173,6 @@ impl SignedCheckpoint {
)
.map_err(ConsistencyProofError)
}

/// Verifies that the checkpoint can be used for an inclusion proof with this root hash.
pub(crate) fn valid_inclusion_proof(
&self,
proof_root_hash: &Output<Rfc6269Default>,
) -> Result<(), SigstoreError> {
Rfc6269Default::verify_match(proof_root_hash, &self.note.hash.into()).map_err(|_| {
UnexpectedError(
"consistency proof root hash does not match checkpoint root hash".to_string(),
)
})
}
}

impl Serialize for SignedCheckpoint {
Expand Down
2 changes: 1 addition & 1 deletion src/rekor/models/inclusion_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl InclusionProof {
let root_hash = hex_to_hash_output(&self.root_hash)?;

// check if the inclusion and checkpoint match
checkpoint.valid_inclusion_proof(&root_hash)?;
checkpoint.is_valid_for_proof(&root_hash, self.tree_size as u64)?;

Rfc6269Default::verify_inclusion(
self.log_index as usize,
Expand Down
6 changes: 2 additions & 4 deletions src/rekor/models/log_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ impl LogInfo {
// verify checkpoint is signed by log
self.signed_tree_head.verify_signature(rekor_key)?;

self.signed_tree_head.valid_consistency_proof(
&hex_to_hash_output(&self.root_hash)?,
self.tree_size as u64,
)?;
self.signed_tree_head
.is_valid_for_proof(&hex_to_hash_output(&self.root_hash)?, self.tree_size as u64)?;
consistency_proof.verify(old_size, old_root, self.tree_size as _)?;
Ok(())
}
Expand Down

0 comments on commit 900423e

Please sign in to comment.