diff --git a/examples/rekor/create_log_entry/main.rs b/examples/rekor/create_log_entry/main.rs index 2ac8f08dc2..856991d8c2 100644 --- a/examples/rekor/create_log_entry/main.rs +++ b/examples/rekor/create_log_entry/main.rs @@ -112,10 +112,7 @@ async fn main() { .unwrap_or(&HASH.to_string()) .to_owned(), ); - let data = Data::new( - hash, - Url::parse(flags.get_one::("url").unwrap_or(&URL.to_string())).unwrap(), - ); + let data = Data::new(hash); let public_key = PublicKey::new( flags .get_one::("public_key") @@ -123,10 +120,6 @@ async fn main() { .to_owned(), ); let signature = Signature::new( - flags - .get_one::("key_format") - .unwrap_or(&KEY_FORMAT.to_string()) - .to_owned(), flags .get_one("signature") .unwrap_or(&SIGNATURE.to_string()) diff --git a/examples/rekor/search_log_query/main.rs b/examples/rekor/search_log_query/main.rs index 5b1fe12de8..466e4808c0 100644 --- a/examples/rekor/search_log_query/main.rs +++ b/examples/rekor/search_log_query/main.rs @@ -93,10 +93,7 @@ async fn main() { .unwrap_or(&HASH.to_string()) .to_owned(), ); - let data = Data::new( - hash, - Url::parse(flags.get_one::("url").unwrap_or(&URL.to_string())).unwrap(), - ); + let data = Data::new(hash); let public_key = PublicKey::new( flags .get_one::("public_key") @@ -104,10 +101,6 @@ async fn main() { .to_owned(), ); let signature = Signature::new( - flags - .get_one::("key_format") - .unwrap_or(&KEY_FORMAT.to_string()) - .to_owned(), flags .get_one::("signature") .unwrap_or(&SIGNATURE.to_string()) diff --git a/src/rekor/models/hashedrekord.rs b/src/rekor/models/hashedrekord.rs index 83f96aad7b..a5dcd2d716 100644 --- a/src/rekor/models/hashedrekord.rs +++ b/src/rekor/models/hashedrekord.rs @@ -8,8 +8,10 @@ * Generated by: https://openapi-generator.tech */ +use base64::decode; use serde::{Deserialize, Serialize}; -use url::Url; + +use crate::errors::SigstoreError; /// Hashedrekord : Hashed Rekord object @@ -38,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 @@ -53,15 +55,13 @@ impl Spec { #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Signature { - format: String, - content: String, - public_key: PublicKey, + pub content: String, + pub public_key: PublicKey, } impl Signature { - pub fn new(format: String, content: String, public_key: PublicKey) -> Signature { + pub fn new(content: String, public_key: PublicKey) -> Signature { Signature { - format, content, public_key, } @@ -79,18 +79,22 @@ 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)] #[serde(rename_all = "camelCase")] pub struct Data { - hash: Hash, - url: Url, + pub hash: Hash, } impl Data { - pub fn new(hash: Hash, url: Url) -> Data { - Data { hash, url } + pub fn new(hash: Hash) -> Data { + Data { hash } } } 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 {