Skip to content

Commit 5da1350

Browse files
authored
Merge pull request #521 from HastD/canonical-json
chore: replace olpc-cjson with serde_json_canonicalizer
2 parents 9b425a6 + 830d9d7 commit 5da1350

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ cosign = [
2222
"dep:async-trait",
2323
"dep:cfg-if",
2424
"dep:oci-client",
25-
"dep:olpc-cjson",
2625
"dep:regex",
26+
"dep:serde_json_canonicalizer",
2727
"registry",
2828
]
2929
fulcio = [
@@ -49,7 +49,7 @@ native-tls = [
4949
"reqwest?/native-tls",
5050
]
5151
oauth = ["dep:openidconnect", "dep:reqwest"]
52-
registry = ["dep:async-trait", "dep:oci-client", "dep:olpc-cjson"]
52+
registry = ["dep:async-trait", "dep:oci-client", "dep:serde_json_canonicalizer"]
5353
rekor = ["dep:reqwest"]
5454
rustls-tls = [
5555
"oci-client?/rustls-tls",
@@ -127,7 +127,6 @@ hex = { version = "0.4", default-features = false, optional = true, features = [
127127
"std",
128128
] }
129129
oci-client = { version = "0.15", default-features = false, optional = true }
130-
olpc-cjson = { version = "0.1", default-features = false, optional = true }
131130
openidconnect = { version = "4.0", default-features = false, features = [
132131
"reqwest",
133132
"reqwest-blocking",

src/cosign/bundle.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use std::{cmp::PartialEq, collections::BTreeMap};
1717

18-
use olpc_cjson::CanonicalFormatter;
1918
use serde::{Deserialize, Serialize};
2019

2120
use crate::{
@@ -87,9 +86,7 @@ impl Bundle {
8786
bundle: &Bundle,
8887
rekor_pub_keys: &BTreeMap<String, CosignVerificationKey>,
8988
) -> Result<()> {
90-
let mut buf = Vec::new();
91-
let mut ser = serde_json::Serializer::with_formatter(&mut buf, CanonicalFormatter::new());
92-
bundle.payload.serialize(&mut ser).map_err(|e| {
89+
let buf = serde_json_canonicalizer::to_vec(&bundle.payload).map_err(|e| {
9390
SigstoreError::UnexpectedError(format!(
9491
"Cannot create canonical JSON representation of bundle: {e:?}"
9592
))

src/registry/oci_caching_client.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::errors::{Result, SigstoreError};
2020

2121
use async_trait::async_trait;
2222
use cached::proc_macro::cached;
23-
use olpc_cjson::CanonicalFormatter;
2423
use serde::Serialize;
2524
use sha2::{Digest, Sha256};
2625
use tracing::{debug, error};
@@ -105,12 +104,13 @@ impl<'a> PullSettings<'a> {
105104
// Because of that the method will return the '0' value when something goes
106105
// wrong during the serialization operation. This is very unlikely to happen
107106
pub fn hash(&self) -> String {
108-
let mut buf = Vec::new();
109-
let mut ser = serde_json::Serializer::with_formatter(&mut buf, CanonicalFormatter::new());
110-
if let Err(e) = self.serialize(&mut ser) {
111-
error!(err=?e, settings=?self, "Cannot perform canonical serialization");
112-
return "0".to_string();
113-
}
107+
let buf = match serde_json_canonicalizer::to_vec(self) {
108+
Ok(vec) => vec,
109+
Err(e) => {
110+
error!(err=?e, settings=?self, "Cannot perform canonical serialization");
111+
return "0".to_string();
112+
}
113+
};
114114

115115
let mut hasher = Sha256::new();
116116
hasher.update(&buf);
@@ -196,12 +196,13 @@ impl PullManifestSettings {
196196
// Because of that the method will return the '0' value when something goes
197197
// wrong during the serialization operation. This is very unlikely to happen
198198
pub fn hash(&self) -> String {
199-
let mut buf = Vec::new();
200-
let mut ser = serde_json::Serializer::with_formatter(&mut buf, CanonicalFormatter::new());
201-
if let Err(e) = self.serialize(&mut ser) {
202-
error!(err=?e, settings=?self, "Cannot perform canonical serialization");
203-
return "0".to_string();
204-
}
199+
let buf = match serde_json_canonicalizer::to_vec(self) {
200+
Ok(vec) => vec,
201+
Err(e) => {
202+
error!(err=?e, settings=?self, "Cannot perform canonical serialization");
203+
return "0".to_string();
204+
}
205+
};
205206

206207
let mut hasher = Sha256::new();
207208
hasher.update(&buf);

0 commit comments

Comments
 (0)