@@ -18,7 +18,7 @@ use crate::errors::{Result, SigstoreError};
1818
1919use async_trait:: async_trait;
2020use cached:: proc_macro:: cached;
21- use olpc_cjson :: CanonicalFormatter ;
21+ use json_syntax :: Print ;
2222use serde:: Serialize ;
2323use sha2:: { Digest , Sha256 } ;
2424use tracing:: { debug, error} ;
@@ -103,15 +103,18 @@ impl<'a> PullSettings<'a> {
103103 // Because of that the method will return the '0' value when something goes
104104 // wrong during the serialization operation. This is very unlikely to happen
105105 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 ( ) ;
112115
113116 let mut hasher = Sha256 :: new ( ) ;
114- hasher. update ( & buf ) ;
117+ hasher. update ( encoded . as_bytes ( ) ) ;
115118 let result = hasher. finalize ( ) ;
116119 result
117120 . iter ( )
@@ -194,15 +197,18 @@ impl PullManifestSettings {
194197 // Because of that the method will return the '0' value when something goes
195198 // wrong during the serialization operation. This is very unlikely to happen
196199 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 ( ) ;
203209
204210 let mut hasher = Sha256 :: new ( ) ;
205- hasher. update ( & buf ) ;
211+ hasher. update ( encoded . as_bytes ( ) ) ;
206212 let result = hasher. finalize ( ) ;
207213 result
208214 . iter ( )
@@ -243,7 +249,7 @@ async fn pull_manifest_cached(
243249impl ClientCapabilitiesDeps for OciCachingClient { }
244250
245251#[ 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 ) ) ]
247253impl ClientCapabilities for OciCachingClient {
248254 async fn fetch_manifest_digest (
249255 & mut self ,
0 commit comments