diff --git a/src/rekor/models/hashedrekord.rs b/src/rekor/models/hashedrekord.rs index a355a4b9b8..a5dcd2d716 100644 --- a/src/rekor/models/hashedrekord.rs +++ b/src/rekor/models/hashedrekord.rs @@ -8,8 +8,11 @@ * Generated by: https://openapi-generator.tech */ +use base64::decode; use serde::{Deserialize, Serialize}; +use crate::errors::SigstoreError; + /// Hashedrekord : Hashed Rekord object #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] @@ -37,8 +40,8 @@ impl Hashedrekord { #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Spec { - signature: Signature, - data: Data, + pub signature: Signature, + pub data: Data, } // Design a SPEC struct @@ -76,6 +79,11 @@ impl PublicKey { pub fn new(content: String) -> PublicKey { PublicKey { content } } + + pub fn decode(&self) -> Result { + let decoded = decode(&self.content)?; + String::from_utf8(decoded).map_err(|e| SigstoreError::from(e.utf8_error())) + } } #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] diff --git a/src/rekor/models/log_entry.rs b/src/rekor/models/log_entry.rs index 3f685f0f79..166234e242 100644 --- a/src/rekor/models/log_entry.rs +++ b/src/rekor/models/log_entry.rs @@ -1,6 +1,10 @@ -use crate::rekor::TreeSize; +use base64::decode; use serde::{Deserialize, Serialize}; +use crate::errors::SigstoreError; +use crate::rekor::models::hashedrekord::Spec; +use crate::rekor::TreeSize; + /// Stores the response returned by Rekor after making a new entry #[derive(Default, Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -15,6 +19,23 @@ pub struct LogEntry { pub verification: Verification, } +impl LogEntry { + pub fn decode_body(&self) -> Result { + let decoded = decode(&self.body)?; + serde_json::from_slice(&decoded).map_err(SigstoreError::from) + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct Body { + #[serde(rename = "kind")] + pub kind: String, + #[serde(rename = "apiVersion")] + pub api_version: String, + #[serde(rename = "spec")] + pub spec: Spec, +} + #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Attestation {