@@ -59,13 +59,12 @@ enum Cli {
5959const CONTENT_ENCODING_KEY : & str = "content encoding" ;
6060const CONTENT_ENCODING_VALUE : & str = "br" ;
6161const UUID_CBOR_TAG : u64 = 37 ;
62- const ULID_CBOR_TAG : u64 = 32780 ;
6362
6463#[ derive( Debug , serde:: Deserialize ) ]
6564struct Metadata {
6665 r#type : uuid:: Uuid ,
67- id : ulid :: Ulid ,
68- ver : ulid :: Ulid ,
66+ id : uuid :: Uuid ,
67+ ver : uuid :: Uuid ,
6968 r#ref : Option < DocumentRef > ,
7069 template : Option < DocumentRef > ,
7170 reply : Option < DocumentRef > ,
@@ -76,29 +75,9 @@ struct Metadata {
7675#[ serde( untagged) ]
7776enum DocumentRef {
7877 /// Reference to the latest document
79- Latest { id : ulid :: Ulid } ,
78+ Latest { id : uuid :: Uuid } ,
8079 /// Reference to the specific document version
81- WithVer { id : ulid:: Ulid , ver : ulid:: Ulid } ,
82- }
83-
84- fn encode_cbor_ulid ( ulid : & ulid:: Ulid ) -> coset:: cbor:: Value {
85- coset:: cbor:: Value :: Tag (
86- ULID_CBOR_TAG ,
87- coset:: cbor:: Value :: Bytes ( ulid. to_bytes ( ) . to_vec ( ) ) . into ( ) ,
88- )
89- }
90-
91- fn decode_cbor_ulid ( val : & coset:: cbor:: Value ) -> anyhow:: Result < ulid:: Ulid > {
92- let Some ( ( ULID_CBOR_TAG , coset:: cbor:: Value :: Bytes ( bytes) ) ) = val. as_tag ( ) else {
93- anyhow:: bail!( "Invalid CBOR encoded ULID type" ) ;
94- } ;
95- let ulid = ulid:: Ulid :: from_bytes (
96- bytes
97- . clone ( )
98- . try_into ( )
99- . map_err ( |_| anyhow:: anyhow!( "Invalid CBOR encoded ULID type, invalid bytes size" ) ) ?,
100- ) ;
101- Ok ( ulid)
80+ WithVer { id : uuid:: Uuid , ver : uuid:: Uuid } ,
10281}
10382
10483fn encode_cbor_uuid ( uuid : & uuid:: Uuid ) -> coset:: cbor:: Value {
@@ -123,24 +102,24 @@ fn decode_cbor_uuid(val: &coset::cbor::Value) -> anyhow::Result<uuid::Uuid> {
123102
124103fn encode_cbor_document_ref ( doc_ref : & DocumentRef ) -> coset:: cbor:: Value {
125104 match doc_ref {
126- DocumentRef :: Latest { id } => encode_cbor_ulid ( id) ,
105+ DocumentRef :: Latest { id } => encode_cbor_uuid ( id) ,
127106 DocumentRef :: WithVer { id, ver } => {
128- coset:: cbor:: Value :: Array ( vec ! [ encode_cbor_ulid ( id) , encode_cbor_ulid ( ver) ] )
107+ coset:: cbor:: Value :: Array ( vec ! [ encode_cbor_uuid ( id) , encode_cbor_uuid ( ver) ] )
129108 } ,
130109 }
131110}
132111
133112#[ allow( clippy:: indexing_slicing) ]
134113fn decode_cbor_document_ref ( val : & coset:: cbor:: Value ) -> anyhow:: Result < DocumentRef > {
135- if let Ok ( id) = decode_cbor_ulid ( val) {
114+ if let Ok ( id) = decode_cbor_uuid ( val) {
136115 Ok ( DocumentRef :: Latest { id } )
137116 } else {
138117 let Some ( array) = val. as_array ( ) else {
139118 anyhow:: bail!( "Invalid CBOR encoded document `ref` type" ) ;
140119 } ;
141120 anyhow:: ensure!( array. len( ) == 2 , "Invalid CBOR encoded document `ref` type" ) ;
142- let id = decode_cbor_ulid ( & array[ 0 ] ) ?;
143- let ver = decode_cbor_ulid ( & array[ 1 ] ) ?;
121+ let id = decode_cbor_uuid ( & array[ 0 ] ) ?;
122+ let ver = decode_cbor_uuid ( & array[ 1 ] ) ?;
144123 Ok ( DocumentRef :: WithVer { id, ver } )
145124 }
146125}
@@ -243,11 +222,11 @@ fn build_empty_cose_doc(doc_bytes: Vec<u8>, meta: &Metadata) -> coset::CoseSign
243222 ) ) ;
244223 protected_header. rest . push ( (
245224 coset:: Label :: Text ( "id" . to_string ( ) ) ,
246- encode_cbor_ulid ( & meta. id ) ,
225+ encode_cbor_uuid ( & meta. id ) ,
247226 ) ) ;
248227 protected_header. rest . push ( (
249228 coset:: Label :: Text ( "ver" . to_string ( ) ) ,
250- encode_cbor_ulid ( & meta. ver ) ,
229+ encode_cbor_uuid ( & meta. ver ) ,
251230 ) ) ;
252231 if let Some ( r#ref) = & meta. r#ref {
253232 protected_header. rest . push ( (
@@ -388,7 +367,7 @@ fn validate_cose_protected_header(cose: &coset::CoseSign) -> anyhow::Result<()>
388367 else {
389368 anyhow:: bail!( "Invalid COSE protected header, missing `id` field" ) ;
390369 } ;
391- decode_cbor_ulid ( value)
370+ decode_cbor_uuid ( value)
392371 . map_err ( |e| anyhow:: anyhow!( "Invalid COSE protected header `id` field, err: {e}" ) ) ?;
393372
394373 let Some ( ( _, value) ) = cose
@@ -400,7 +379,7 @@ fn validate_cose_protected_header(cose: &coset::CoseSign) -> anyhow::Result<()>
400379 else {
401380 anyhow:: bail!( "Invalid COSE protected header, missing `ver` field" ) ;
402381 } ;
403- decode_cbor_ulid ( value)
382+ decode_cbor_uuid ( value)
404383 . map_err ( |e| anyhow:: anyhow!( "Invalid COSE protected header `ver` field, err: {e}" ) ) ?;
405384
406385 if let Some ( ( _, value) ) = cose
0 commit comments