@@ -18,7 +18,7 @@ use crate::errors::{Result, SigstoreError};
18
18
19
19
use async_trait:: async_trait;
20
20
use cached:: proc_macro:: cached;
21
- use olpc_cjson :: CanonicalFormatter ;
21
+ use json_syntax :: Print ;
22
22
use serde:: Serialize ;
23
23
use sha2:: { Digest , Sha256 } ;
24
24
use tracing:: { debug, error} ;
@@ -103,15 +103,18 @@ impl<'a> PullSettings<'a> {
103
103
// Because of that the method will return the '0' value when something goes
104
104
// wrong during the serialization operation. This is very unlikely to happen
105
105
pub fn hash ( & self ) -> String {
106
- let mut buf = Vec :: new ( ) ;
107
- let mut ser = serde_json:: Serializer :: with_formatter ( & mut buf, CanonicalFormatter :: new ( ) ) ;
108
- if let Err ( e) = self . serialize ( & mut ser) {
109
- error ! ( err=?e, settings=?self , "Cannot perform canonical serialization" ) ;
110
- return "0" . to_string ( ) ;
111
- }
106
+ let mut body = match json_syntax:: to_value ( self ) {
107
+ Ok ( body) => body,
108
+ Err ( _e) => {
109
+ error ! ( err=?_e, settings=?self , "Cannot perform canonical serialization" ) ;
110
+ return "0" . to_string ( ) ;
111
+ }
112
+ } ;
113
+ body. canonicalize ( ) ;
114
+ let encoded = body. compact_print ( ) . to_string ( ) ;
112
115
113
116
let mut hasher = Sha256 :: new ( ) ;
114
- hasher. update ( & buf ) ;
117
+ hasher. update ( encoded . as_bytes ( ) ) ;
115
118
let result = hasher. finalize ( ) ;
116
119
result
117
120
. iter ( )
@@ -194,15 +197,18 @@ impl PullManifestSettings {
194
197
// Because of that the method will return the '0' value when something goes
195
198
// wrong during the serialization operation. This is very unlikely to happen
196
199
pub fn hash ( & self ) -> String {
197
- let mut buf = Vec :: new ( ) ;
198
- let mut ser = serde_json:: Serializer :: with_formatter ( & mut buf, CanonicalFormatter :: new ( ) ) ;
199
- if let Err ( e) = self . serialize ( & mut ser) {
200
- error ! ( err=?e, settings=?self , "Cannot perform canonical serialization" ) ;
201
- return "0" . to_string ( ) ;
202
- }
200
+ let mut body = match json_syntax:: to_value ( self ) {
201
+ Ok ( body) => body,
202
+ Err ( _e) => {
203
+ error ! ( err=?_e, settings=?self , "Cannot perform canonical serialization" ) ;
204
+ return "0" . to_string ( ) ;
205
+ }
206
+ } ;
207
+ body. canonicalize ( ) ;
208
+ let encoded = body. compact_print ( ) . to_string ( ) ;
203
209
204
210
let mut hasher = Sha256 :: new ( ) ;
205
- hasher. update ( & buf ) ;
211
+ hasher. update ( encoded . as_bytes ( ) ) ;
206
212
let result = hasher. finalize ( ) ;
207
213
result
208
214
. iter ( )
@@ -243,7 +249,7 @@ async fn pull_manifest_cached(
243
249
impl ClientCapabilitiesDeps for OciCachingClient { }
244
250
245
251
#[ cfg_attr( not( target_arch = "wasm32" ) , async_trait) ]
246
- #[ cfg_attr( target_arch = "wasm32" , async_trait( ?Send ) ) ]
252
+ #[ cfg_attr( target_arch = "wasm32" , async_trait( ? Send ) ) ]
247
253
impl ClientCapabilities for OciCachingClient {
248
254
async fn fetch_manifest_digest (
249
255
& mut self ,
0 commit comments