3232//! # Ok::<(), anyhow::Error>(())
3333//! ```
3434
35- use std:: fmt;
36- use std:: ops:: Deref ;
37- use std:: str:: FromStr ;
35+ use std:: { fmt, ops:: Deref , str:: FromStr } ;
3836
39- use minicbor:: data:: Tag ;
40- use minicbor:: decode:: Error as DecodeError ;
41- use minicbor:: { Decoder , Encoder } ;
37+ use minicbor:: { Decoder , Encoder , data:: Tag , decode:: Error as DecodeError } ;
4238use sha2:: { Digest , Sha256 } ;
4339use thiserror:: Error ;
4440
@@ -78,7 +74,8 @@ pub enum CidError {
7874/// A newtype wrapper around `cid::Cid` for type-safe CID v1 handling.
7975///
8076/// This type provides conversion methods and trait implementations for working with
81- /// CID v1 identifiers, especially in the context of CBOR-encoded Catalyst Signed Documents.
77+ /// CID v1 identifiers, especially in the context of CBOR-encoded Catalyst Signed
78+ /// Documents.
8279#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
8380pub struct Cid ( cid:: Cid ) ;
8481
@@ -129,13 +126,19 @@ impl FromStr for Cid {
129126}
130127
131128impl fmt:: Display for Cid {
132- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
129+ fn fmt (
130+ & self ,
131+ f : & mut fmt:: Formatter < ' _ > ,
132+ ) -> fmt:: Result {
133133 write ! ( f, "{}" , self . 0 )
134134 }
135135}
136136
137137impl serde:: Serialize for Cid {
138- fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
138+ fn serialize < S > (
139+ & self ,
140+ serializer : S ,
141+ ) -> Result < S :: Ok , S :: Error >
139142 where
140143 S : serde:: Serializer ,
141144 {
@@ -145,9 +148,7 @@ impl serde::Serialize for Cid {
145148
146149impl < ' de > serde:: Deserialize < ' de > for Cid {
147150 fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
148- where
149- D : serde:: Deserializer < ' de > ,
150- {
151+ where D : serde:: Deserializer < ' de > {
151152 let s = String :: deserialize ( deserializer) ?;
152153 FromStr :: from_str ( & s) . map_err ( serde:: de:: Error :: custom)
153154 }
@@ -167,8 +168,14 @@ impl minicbor::Encode<()> for Cid {
167168}
168169
169170impl < ' de > minicbor:: Decode < ' de , ( ) > for Cid {
170- fn decode ( d : & mut Decoder < ' de > , _ctx : & mut ( ) ) -> Result < Self , DecodeError > {
171- let tag = d. tag ( ) . map_err ( |e| DecodeError :: message ( e. to_string ( ) ) ) ?. as_u64 ( ) ;
171+ fn decode (
172+ d : & mut Decoder < ' de > ,
173+ _ctx : & mut ( ) ,
174+ ) -> Result < Self , DecodeError > {
175+ let tag = d
176+ . tag ( )
177+ . map_err ( |e| DecodeError :: message ( e. to_string ( ) ) ) ?
178+ . as_u64 ( ) ;
172179 if tag != CID_CBOR_TAG {
173180 return Err ( DecodeError :: message ( format ! (
174181 "Expected IPLD CID tag ({CID_CBOR_TAG}), got {tag}" ,
@@ -259,8 +266,8 @@ mod tests {
259266 let cid_bytes = Vec :: < u8 > :: from ( cid) ;
260267
261268 // Convert back from bytes
262- let cid_from_bytes = Cid :: try_from ( cid_bytes . as_slice ( ) )
263- . expect ( "Should parse CID from bytes" ) ;
269+ let cid_from_bytes =
270+ Cid :: try_from ( cid_bytes . as_slice ( ) ) . expect ( "Should parse CID from bytes" ) ;
264271
265272 assert_eq ! ( cid, cid_from_bytes) ;
266273 }
@@ -274,8 +281,7 @@ mod tests {
274281 let cid_string = cid. to_string ( ) ;
275282
276283 // Parse the string back to a CID
277- let cid_from_str = Cid :: from_str ( & cid_string)
278- . expect ( "CID string should be parseable" ) ;
284+ let cid_from_str = Cid :: from_str ( & cid_string) . expect ( "CID string should be parseable" ) ;
279285
280286 assert_eq ! ( cid, cid_from_str) ;
281287 }
@@ -289,8 +295,10 @@ mod tests {
289295 let cid_string = cid. to_string ( ) ;
290296
291297 // Should be multibase encoded (starts with 'b' for base32)
292- assert ! ( cid_string. starts_with( 'b' ) ,
293- "CID v1 base32 string should start with 'b'" ) ;
298+ assert ! (
299+ cid_string. starts_with( 'b' ) ,
300+ "CID v1 base32 string should start with 'b'"
301+ ) ;
294302 }
295303
296304 #[ test]
@@ -407,10 +415,10 @@ mod tests {
407415 . build ( )
408416 . expect ( "Should build document" ) ;
409417
410- let cid1 = to_cid_v1 ( & doc1 . to_bytes ( ) . expect ( "Should serialize" ) )
411- . expect ( "CID 1 should be valid" ) ;
412- let cid2 = to_cid_v1 ( & doc2 . to_bytes ( ) . expect ( "Should serialize" ) )
413- . expect ( "CID 2 should be valid" ) ;
418+ let cid1 =
419+ to_cid_v1 ( & doc1 . to_bytes ( ) . expect ( "Should serialize" ) ) . expect ( "CID 1 should be valid" ) ;
420+ let cid2 =
421+ to_cid_v1 ( & doc2 . to_bytes ( ) . expect ( "Should serialize" ) ) . expect ( "CID 2 should be valid" ) ;
414422
415423 assert_ne ! (
416424 cid1, cid2,
@@ -434,7 +442,10 @@ mod tests {
434442
435443 // Base32 encoding uses lowercase letters and digits 2-7
436444 assert ! (
437- cid_string. chars( ) . skip( 1 ) . all( |c| c. is_ascii_lowercase( ) || ( '2' ..='7' ) . contains( & c) ) ,
445+ cid_string
446+ . chars( )
447+ . skip( 1 )
448+ . all( |c| c. is_ascii_lowercase( ) || ( '2' ..='7' ) . contains( & c) ) ,
438449 "CID v1 base32 string should only contain lowercase letters and digits 2-7"
439450 ) ;
440451
@@ -458,8 +469,8 @@ mod tests {
458469 let cid_bytes = Vec :: < u8 > :: from ( cid) ;
459470
460471 // Parse bytes back to CID
461- let cid_from_bytes = Cid :: try_from ( cid_bytes . as_slice ( ) )
462- . expect ( "Should parse CID from bytes" ) ;
472+ let cid_from_bytes =
473+ Cid :: try_from ( cid_bytes . as_slice ( ) ) . expect ( "Should parse CID from bytes" ) ;
463474
464475 // Convert back to string
465476 let final_string = cid_from_bytes. to_string ( ) ;
0 commit comments