Skip to content

Commit

Permalink
Rebased to main.
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Embacher <victor@embacher.xyz>
  • Loading branch information
vembacher committed Mar 20, 2024
1 parent d936abd commit 6d51377
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
16 changes: 8 additions & 8 deletions src/rekor/models/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::str::FromStr;
/// The `note` field stores this data,
/// and its authenticity can be verified with the data in `signature`.
#[derive(Debug, PartialEq, Clone, Eq)]
pub struct SignedCheckpoint {
pub struct Checkpoint {
pub note: CheckpointNote,
pub signature: CheckpointSignature,
}
Expand Down Expand Up @@ -67,7 +67,7 @@ pub enum ParseCheckpointError {
DecodeError(String),
}

impl FromStr for SignedCheckpoint {
impl FromStr for Checkpoint {
type Err = ParseCheckpointError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Expand All @@ -82,7 +82,7 @@ impl FromStr for SignedCheckpoint {
let signature = signature.parse()?;
let note = CheckpointNote::unmarshal(note)?;

Ok(SignedCheckpoint { note, signature })
Ok(Checkpoint { note, signature })
}
}

Expand Down Expand Up @@ -139,15 +139,15 @@ impl CheckpointNote {
}
}

impl ToString for SignedCheckpoint {
impl ToString for Checkpoint {
fn to_string(&self) -> String {
let note = self.note.marshal();
let signature = self.signature.to_string();
format!("{note}\n{signature}")
}
}

impl SignedCheckpoint {
impl Checkpoint {
/// This method can be used to verify that the checkpoint was issued by the log with the
/// public key `rekor_key`.
pub fn verify_signature(&self, rekor_key: &CosignVerificationKey) -> Result<(), SigstoreError> {
Expand Down Expand Up @@ -175,7 +175,7 @@ impl SignedCheckpoint {
}
}

impl Serialize for SignedCheckpoint {
impl Serialize for Checkpoint {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
Expand All @@ -184,13 +184,13 @@ impl Serialize for SignedCheckpoint {
}
}

impl<'de> Deserialize<'de> for SignedCheckpoint {
impl<'de> Deserialize<'de> for Checkpoint {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
<String>::deserialize(deserializer).and_then(|s| {
SignedCheckpoint::from_str(&s).map_err(|DecodeError(err)| serde::de::Error::custom(err))
Checkpoint::from_str(&s).map_err(|DecodeError(err)| serde::de::Error::custom(err))
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/rekor/models/inclusion_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::crypto::merkle::{
use crate::crypto::CosignVerificationKey;
use crate::errors::SigstoreError;
use crate::errors::SigstoreError::{InclusionProofError, UnexpectedError};
use crate::rekor::models::checkpoint::SignedCheckpoint;
use crate::rekor::models::checkpoint::Checkpoint;
use crate::rekor::TreeSize;
use serde::{Deserialize, Serialize};

Expand All @@ -32,7 +32,7 @@ pub struct InclusionProof {
/// A list of hashes required to compute the inclusion proof, sorted in order from leaf to root
#[serde(rename = "hashes")]
pub hashes: Vec<String>,
pub checkpoint: Option<SignedCheckpoint>,
pub checkpoint: Option<Checkpoint>,
}

impl InclusionProof {
Expand All @@ -41,7 +41,7 @@ impl InclusionProof {
root_hash: String,
tree_size: TreeSize,
hashes: Vec<String>,
checkpoint: Option<SignedCheckpoint>,
checkpoint: Option<Checkpoint>,
) -> InclusionProof {
InclusionProof {
log_index,
Expand Down
18 changes: 16 additions & 2 deletions src/rekor/models/log_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use base64::{engine::general_purpose::STANDARD as BASE64_STD_ENGINE, Engine as _

use crate::crypto::CosignVerificationKey;
use crate::errors::SigstoreError::UnexpectedError;
use crate::rekor::models::InclusionProof;
use crate::rekor::models::checkpoint::Checkpoint;
use crate::rekor::models::InclusionProof as InclusionProof2;
use olpc_cjson::CanonicalFormatter;
use serde::{Deserialize, Serialize};
use serde_json::{json, Error, Value};
Expand Down Expand Up @@ -54,7 +55,7 @@ impl FromStr for LogEntry {
decode_body(body.as_str().expect("Failed to parse Body"))
.expect("Failed to decode Body"),
)
.expect("Serialization failed");
.expect("Serialization failed");
*body = json!(decoded_body);
});
let log_entry_str = serde_json::to_string(&log_entry_map)?;
Expand Down Expand Up @@ -143,6 +144,19 @@ impl LogEntry {
.inclusion_proof
.as_ref()
.ok_or(UnexpectedError("missing inclusion proof".to_string()))
.and_then(|proof| {
Checkpoint::from_str(&proof.checkpoint)
.map_err(|_| UnexpectedError("failed to parse checkpoint".to_string()))
.map(|checkpoint| {
InclusionProof2::new(
proof.log_index,
proof.root_hash.clone(),
proof.tree_size,
proof.hashes.clone(),
Some(checkpoint),
)
})
})
.and_then(|proof| {
// encode as canonical JSON
let mut encoded_entry = Vec::new();
Expand Down
10 changes: 3 additions & 7 deletions src/rekor/models/log_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use crate::crypto::merkle::hex_to_hash_output;
use crate::crypto::CosignVerificationKey;
use crate::errors::SigstoreError;
use crate::rekor::models::checkpoint::SignedCheckpoint;
use crate::rekor::models::checkpoint::Checkpoint;
use crate::rekor::models::ConsistencyProof;
use crate::rekor::TreeSize;
use serde::{Deserialize, Serialize};
Expand All @@ -26,7 +26,7 @@ pub struct LogInfo {
pub tree_size: TreeSize,
/// The current signed tree head
#[serde(rename = "signedTreeHead")]
pub signed_tree_head: SignedCheckpoint,
pub signed_tree_head: Checkpoint,
/// The current treeID
#[serde(rename = "treeID")]
pub tree_id: Option<String>,
Expand All @@ -35,11 +35,7 @@ pub struct LogInfo {
}

impl LogInfo {
pub fn new(
root_hash: String,
tree_size: TreeSize,
signed_tree_head: SignedCheckpoint,
) -> LogInfo {
pub fn new(root_hash: String, tree_size: TreeSize, signed_tree_head: Checkpoint) -> LogInfo {
LogInfo {
root_hash,
tree_size,
Expand Down

0 comments on commit 6d51377

Please sign in to comment.