11//! `UUID` types.
22
3- use displaydoc:: Display ;
4- use minicbor:: Decoder ;
5- use thiserror:: Error ;
6- use uuid:: Uuid ;
7-
83mod uuid_v4;
94mod uuid_v7;
105
@@ -14,39 +9,26 @@ pub use uuid_v7::UuidV7 as V7;
149/// Invalid Doc Type UUID
1510pub const INVALID_UUID : uuid:: Uuid = uuid:: Uuid :: from_bytes ( [ 0x00 ; 16 ] ) ;
1611
17- // UUID CBOR tag <https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml/>.
18- // pub(crate) const UUID_CBOR_TAG: u64 = 37;
19-
20- /// Errors that can occur when decoding CBOR-encoded UUIDs.
21- #[ derive( Display , Debug , Error ) ]
22- pub enum CborUuidError {
23- /// Invalid CBOR encoded UUID type
24- InvalidCborType ,
25- /// Invalid CBOR encoded UUID type: invalid bytes size
26- InvalidByteSize ,
27- /// UUID {uuid} is not `v{expected_version}`
28- InvalidVersion {
29- /// The decoded UUID that was checked.
30- uuid : Uuid ,
31- /// The expected version of the UUID, which did not match the decoded one.
32- expected_version : usize ,
33- } ,
34- }
12+ /// UUID CBOR tag <https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml/>.
13+ #[ allow( dead_code) ]
14+ const UUID_CBOR_TAG : u64 = 37 ;
3515
3616/// Decode from `CBOR` into `UUID`
37- pub ( crate ) fn decode_cbor_uuid < C > (
38- d : & mut Decoder < ' _ > , ctx : & mut C ,
17+ fn decode_cbor_uuid < C > (
18+ d : & mut minicbor :: Decoder < ' _ > , _ctx : & mut C ,
3919) -> Result < uuid:: Uuid , minicbor:: decode:: Error > {
40- let decoded: [ u8 ; 16 ] = d. decode_with ( ctx) ?;
20+ let decoded: [ u8 ; 16 ] = d. bytes ( ) ?. try_into ( ) . map_err ( |_| {
21+ minicbor:: decode:: Error :: message ( "Invalid CBOR encoded UUID type: invalid bytes size" )
22+ } ) ?;
4123 let uuid = uuid:: Uuid :: from_bytes ( decoded) ;
4224 Ok ( uuid)
4325}
4426
4527/// Encode `UUID` into `CBOR`
46- pub ( crate ) fn encode_cbor_uuid < C , W : minicbor:: encode:: Write > (
47- uuid : uuid:: Uuid , e : & mut minicbor:: Encoder < W > , ctx : & mut C ,
28+ fn encode_cbor_uuid < C , W : minicbor:: encode:: Write > (
29+ uuid : uuid:: Uuid , e : & mut minicbor:: Encoder < W > , _ctx : & mut C ,
4830) -> Result < ( ) , minicbor:: encode:: Error < W :: Error > > {
49- e. encode_with ( uuid. as_bytes ( ) , ctx ) ?;
31+ e. bytes ( uuid. as_bytes ( ) ) ?;
5032 Ok ( ( ) )
5133}
5234
0 commit comments