Skip to content

Commit 0725c0d

Browse files
authored
Merge pull request #152 from lkatalin/parse_logentry
Updates for parsing hashedrekord LogEntry
2 parents a606ece + 112ccee commit 0725c0d

File tree

4 files changed

+40
-29
lines changed

4 files changed

+40
-29
lines changed

examples/rekor/create_log_entry/main.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,14 @@ async fn main() {
112112
.unwrap_or(&HASH.to_string())
113113
.to_owned(),
114114
);
115-
let data = Data::new(
116-
hash,
117-
Url::parse(flags.get_one::<String>("url").unwrap_or(&URL.to_string())).unwrap(),
118-
);
115+
let data = Data::new(hash);
119116
let public_key = PublicKey::new(
120117
flags
121118
.get_one::<String>("public_key")
122119
.unwrap_or(&PUBLIC_KEY.to_string())
123120
.to_owned(),
124121
);
125122
let signature = Signature::new(
126-
flags
127-
.get_one::<String>("key_format")
128-
.unwrap_or(&KEY_FORMAT.to_string())
129-
.to_owned(),
130123
flags
131124
.get_one("signature")
132125
.unwrap_or(&SIGNATURE.to_string())

examples/rekor/search_log_query/main.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,14 @@ async fn main() {
9393
.unwrap_or(&HASH.to_string())
9494
.to_owned(),
9595
);
96-
let data = Data::new(
97-
hash,
98-
Url::parse(flags.get_one::<String>("url").unwrap_or(&URL.to_string())).unwrap(),
99-
);
96+
let data = Data::new(hash);
10097
let public_key = PublicKey::new(
10198
flags
10299
.get_one::<String>("public_key")
103100
.unwrap_or(&PUBLIC_KEY.to_string())
104101
.to_owned(),
105102
);
106103
let signature = Signature::new(
107-
flags
108-
.get_one::<String>("key_format")
109-
.unwrap_or(&KEY_FORMAT.to_string())
110-
.to_owned(),
111104
flags
112105
.get_one::<String>("signature")
113106
.unwrap_or(&SIGNATURE.to_string())

src/rekor/models/hashedrekord.rs

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

11+
use base64::decode;
1112
use serde::{Deserialize, Serialize};
12-
use url::Url;
13+
14+
use crate::errors::SigstoreError;
1315

1416
/// Hashedrekord : Hashed Rekord object
1517
@@ -38,8 +40,8 @@ impl Hashedrekord {
3840
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
3941
#[serde(rename_all = "camelCase")]
4042
pub struct Spec {
41-
signature: Signature,
42-
data: Data,
43+
pub signature: Signature,
44+
pub data: Data,
4345
}
4446

4547
// Design a SPEC struct
@@ -53,15 +55,13 @@ impl Spec {
5355
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
5456
#[serde(rename_all = "camelCase")]
5557
pub struct Signature {
56-
format: String,
57-
content: String,
58-
public_key: PublicKey,
58+
pub content: String,
59+
pub public_key: PublicKey,
5960
}
6061

6162
impl Signature {
62-
pub fn new(format: String, content: String, public_key: PublicKey) -> Signature {
63+
pub fn new(content: String, public_key: PublicKey) -> Signature {
6364
Signature {
64-
format,
6565
content,
6666
public_key,
6767
}
@@ -79,18 +79,22 @@ impl PublicKey {
7979
pub fn new(content: String) -> PublicKey {
8080
PublicKey { content }
8181
}
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+
}
8287
}
8388

8489
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
8590
#[serde(rename_all = "camelCase")]
8691
pub struct Data {
87-
hash: Hash,
88-
url: Url,
92+
pub hash: Hash,
8993
}
9094

9195
impl Data {
92-
pub fn new(hash: Hash, url: Url) -> Data {
93-
Data { hash, url }
96+
pub fn new(hash: Hash) -> Data {
97+
Data { hash }
9498
}
9599
}
96100

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)