Skip to content

Commit 7f8ab57

Browse files
committed
Add functionality to parse hashedrekord LogEntry
- Make signature fields public - Add Body struct and implementation - add base64 decoding Signed-off-by: Lily Sturmann <[email protected]>
1 parent e76c481 commit 7f8ab57

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/rekor/models/hashedrekord.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
* Generated by: https://openapi-generator.tech
99
*/
1010

11+
use base64::decode;
1112
use serde::{Deserialize, Serialize};
1213

14+
use crate::errors::SigstoreError;
15+
1316
/// Hashedrekord : Hashed Rekord object
1417
1518
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
@@ -37,8 +40,8 @@ impl Hashedrekord {
3740
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
3841
#[serde(rename_all = "camelCase")]
3942
pub struct Spec {
40-
signature: Signature,
41-
data: Data,
43+
pub signature: Signature,
44+
pub data: Data,
4245
}
4346

4447
// Design a SPEC struct
@@ -76,6 +79,11 @@ impl PublicKey {
7679
pub fn new(content: String) -> PublicKey {
7780
PublicKey { content }
7881
}
82+
83+
pub fn decode(&self) -> Result<String, SigstoreError> {
84+
let decoded = decode(&self.content)?;
85+
String::from_utf8(decoded).map_err(|e| SigstoreError::from(e.utf8_error()))
86+
}
7987
}
8088

8189
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]

src/rekor/models/log_entry.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
use crate::rekor::TreeSize;
1+
use base64::decode;
22
use serde::{Deserialize, Serialize};
33

4+
use crate::errors::SigstoreError;
5+
use crate::rekor::models::hashedrekord::Spec;
6+
use crate::rekor::TreeSize;
7+
48
/// Stores the response returned by Rekor after making a new entry
59
#[derive(Default, Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
610
#[serde(rename_all = "camelCase")]
@@ -15,6 +19,23 @@ pub struct LogEntry {
1519
pub verification: Verification,
1620
}
1721

22+
impl LogEntry {
23+
pub fn decode_body(&self) -> Result<Body, SigstoreError> {
24+
let decoded = decode(&self.body)?;
25+
serde_json::from_slice(&decoded).map_err(SigstoreError::from)
26+
}
27+
}
28+
29+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
30+
pub struct Body {
31+
#[serde(rename = "kind")]
32+
pub kind: String,
33+
#[serde(rename = "apiVersion")]
34+
pub api_version: String,
35+
#[serde(rename = "spec")]
36+
pub spec: Spec,
37+
}
38+
1839
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1940
#[serde(rename_all = "camelCase")]
2041
pub struct Attestation {

0 commit comments

Comments
 (0)