Skip to content

Commit

Permalink
Add functionality to parse hashedrekord LogEntry
Browse files Browse the repository at this point in the history
- Make signature fields public
- Add Body struct and implementation
- add base64 decoding

Signed-off-by: Lily Sturmann <lsturman@redhat.com>
  • Loading branch information
lkatalin committed Oct 24, 2022
1 parent b544d25 commit 112ccee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/rekor/models/hashedrekord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -76,6 +79,11 @@ impl PublicKey {
pub fn new(content: String) -> PublicKey {
PublicKey { content }
}

pub fn decode(&self) -> Result<String, SigstoreError> {
let decoded = decode(&self.content)?;
String::from_utf8(decoded).map_err(|e| SigstoreError::from(e.utf8_error()))
}
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
Expand Down
23 changes: 22 additions & 1 deletion src/rekor/models/log_entry.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -15,6 +19,23 @@ pub struct LogEntry {
pub verification: Verification,
}

impl LogEntry {
pub fn decode_body(&self) -> Result<Body, SigstoreError> {
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 {
Expand Down

0 comments on commit 112ccee

Please sign in to comment.