diff --git a/Cargo.toml b/Cargo.toml index 57f32d3..5babc75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ heapless = { version = "0.8", default-features = false } hex = { version = "0.4.2", default-features = false } itertools = { version = "0.10", default-features = false } libfuzzer-sys = "0.4" -minicbor = { version = "0.20", features = ["derive"] } +minicbor = { version = "0.24", features = ["derive"] } phf = { version = "0.11", features = ["macros"], default-features = false } rand_xoshiro = "0.6" serde = { version = "1.0.156", features = ["derive"] } diff --git a/urtypes/src/cbor/timestamp.rs b/urtypes/src/cbor/timestamp.rs index 537e834..bf65d0d 100644 --- a/urtypes/src/cbor/timestamp.rs +++ b/urtypes/src/cbor/timestamp.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later use minicbor::{ - data::{Int, Tag, Type}, + data::{Int, Tag, Type, IanaTag}, decode::Error, encode::Write, Decode, Decoder, Encode, Encoder, @@ -22,7 +22,7 @@ pub enum Timestamp { #[rustfmt::skip] impl<'b, C> Decode<'b, C> for Timestamp { fn decode(d: &mut Decoder<'b>, _ctx: &mut C) -> Result { - if d.tag()? != Tag::Timestamp { + if d.tag()? != Tag::from(IanaTag::Timestamp) { return Err(Error::message("invalid timestamp tag")); } @@ -45,7 +45,7 @@ impl Encode for Timestamp { e: &mut Encoder, _ctx: &mut C, ) -> Result<(), minicbor::encode::Error> { - e.tag(Tag::Timestamp)?; + e.tag(IanaTag::Timestamp)?; match self { Timestamp::Int(x) => e.int(*x)?, diff --git a/urtypes/src/cbor/uuid.rs b/urtypes/src/cbor/uuid.rs index 4ac2295..62bf5c1 100644 --- a/urtypes/src/cbor/uuid.rs +++ b/urtypes/src/cbor/uuid.rs @@ -23,7 +23,7 @@ use minicbor::{data::Tag, decode::Error, encode::Write, Decoder, Encoder}; use uuid::Uuid; /// Tag representing of [`Uuid`]. -pub const TAG: Tag = Tag::Unassigned(37); +pub const TAG: Tag = Tag::new(37); /// Encode an [`Uuid`]. pub fn encode( diff --git a/urtypes/src/passport.rs b/urtypes/src/passport.rs index e02a61a..d89cfd5 100644 --- a/urtypes/src/passport.rs +++ b/urtypes/src/passport.rs @@ -27,7 +27,7 @@ pub enum Model { impl Model { /// Tag for embedding [`Model`] in other types. - pub const TAG: Tag = Tag::Unassigned(721); + pub const TAG: Tag = Tag::new(721); } impl<'b, C> Decode<'b, C> for Model { diff --git a/urtypes/src/registry/crypto_address.rs b/urtypes/src/registry/crypto_address.rs index 0f565bd..0a94580 100644 --- a/urtypes/src/registry/crypto_address.rs +++ b/urtypes/src/registry/crypto_address.rs @@ -25,7 +25,7 @@ pub struct CryptoAddress<'a> { impl<'a> CryptoAddress<'a> { /// The CBOR tag used when [`CryptoAddress`] is embedded in other CBOR /// types. - pub const TAG: Tag = Tag::Unassigned(307); + pub const TAG: Tag = Tag::new(307); } #[cfg(feature = "bitcoin")] diff --git a/urtypes/src/registry/crypto_coininfo.rs b/urtypes/src/registry/crypto_coininfo.rs index 604aba5..a438e2d 100644 --- a/urtypes/src/registry/crypto_coininfo.rs +++ b/urtypes/src/registry/crypto_coininfo.rs @@ -21,7 +21,7 @@ pub struct CryptoCoinInfo { impl CryptoCoinInfo { /// Tag for embedding [`CryptoCoinInfo`] in other types. - pub const TAG: Tag = Tag::Unassigned(305); + pub const TAG: Tag = Tag::new(305); /// Universal value for unique network. pub const NETWORK_MAINNET: u64 = 0; diff --git a/urtypes/src/registry/crypto_eckey.rs b/urtypes/src/registry/crypto_eckey.rs index bc424d5..b69db08 100644 --- a/urtypes/src/registry/crypto_eckey.rs +++ b/urtypes/src/registry/crypto_eckey.rs @@ -22,7 +22,7 @@ pub struct CryptoECKey<'a> { impl<'a> CryptoECKey<'a> { /// The CBOR tag used when [`CryptoECKey`] is embedded in other CBOR types. - pub const TAG: Tag = Tag::Unassigned(306); + pub const TAG: Tag = Tag::new(306); /// `secp256k1` curve type. pub const SECP256K1: u64 = 0; diff --git a/urtypes/src/registry/crypto_hdkey.rs b/urtypes/src/registry/crypto_hdkey.rs index 90a4e6e..e1474a3 100644 --- a/urtypes/src/registry/crypto_hdkey.rs +++ b/urtypes/src/registry/crypto_hdkey.rs @@ -22,7 +22,7 @@ pub enum CryptoHDKey<'a> { impl<'a> CryptoHDKey<'a> { /// The CBOR tag used when [`CryptoHDKey`] is embedded in other CBOR types. - pub const TAG: Tag = Tag::Unassigned(303); + pub const TAG: Tag = Tag::new(303); } #[cfg(feature = "bitcoin")] @@ -254,20 +254,23 @@ impl<'b, C> Decode<'b, C> for DerivedKey<'b> { } } + const TAGGED_COININFO: Tag = Tag::new(305); + const TAGGED_KEYPATH: Tag = Tag::new(304); + match d.u32()? { 2 => is_private = d.bool()?, 3 => key_data = Some(DecodeBytes::decode_bytes(d, ctx)?), 4 => chain_code = Some(DecodeBytes::decode_bytes(d, ctx)?), 5 => match d.tag()? { - Tag::Unassigned(305) => use_info = Some(CryptoCoinInfo::decode(d, ctx)?), + TAGGED_COININFO => use_info = Some(CryptoCoinInfo::decode(d, ctx)?), _ => return Err(Error::message("invalid tag for crypto-coininfo")), }, 6 => match d.tag()? { - Tag::Unassigned(304) => origin = Some(CryptoKeypath::decode(d, ctx)?), + TAGGED_KEYPATH => origin = Some(CryptoKeypath::decode(d, ctx)?), _ => return Err(Error::message("invalid tag for crypto-keypath")), }, 7 => match d.tag()? { - Tag::Unassigned(304) => children = Some(CryptoKeypath::decode(d, ctx)?), + TAGGED_KEYPATH => children = Some(CryptoKeypath::decode(d, ctx)?), _ => return Err(Error::message("invalid tag for crypto-keypath")), }, 8 => { @@ -325,17 +328,17 @@ impl<'a, C> Encode for DerivedKey<'a> { } if let Some(ref use_info) = self.use_info { - e.u8(5)?.tag(Tag::Unassigned(305))?; + e.u8(5)?.tag(Tag::new(305))?; use_info.encode(e, ctx)?; } if let Some(ref origin) = self.origin { - e.u8(6)?.tag(Tag::Unassigned(304))?; + e.u8(6)?.tag(Tag::new(304))?; origin.encode(e, ctx)?; } if let Some(ref children) = self.children { - e.u8(7)?.tag(Tag::Unassigned(304))?; + e.u8(7)?.tag(Tag::new(304))?; children.encode(e, ctx)?; } diff --git a/urtypes/src/registry/crypto_output.rs b/urtypes/src/registry/crypto_output.rs index 59f3178..1b9daf8 100644 --- a/urtypes/src/registry/crypto_output.rs +++ b/urtypes/src/registry/crypto_output.rs @@ -55,17 +55,17 @@ pub enum Terminal<'a, 'b> { } impl<'a, 'b> Terminal<'a, 'b> { - const TAG_SCRIPT_HASH: Tag = Tag::Unassigned(400); - const TAG_WITNESS_SCRIPT_HASH: Tag = Tag::Unassigned(401); - const TAG_PUBLIC_KEY: Tag = Tag::Unassigned(402); - const TAG_PUBLIC_KEY_HASH: Tag = Tag::Unassigned(403); - const TAG_WITNESS_PUBLIC_KEY_HASH: Tag = Tag::Unassigned(404); - const TAG_COMBO: Tag = Tag::Unassigned(405); - const TAG_MULTISIG: Tag = Tag::Unassigned(406); - const TAG_SORTED_MULTISIG: Tag = Tag::Unassigned(407); - const TAG_RAW_SCRIPT: Tag = Tag::Unassigned(408); - const TAG_TAPROOT: Tag = Tag::Unassigned(409); - const TAG_COSIGNER: Tag = Tag::Unassigned(410); + const TAG_SCRIPT_HASH: Tag = Tag::new(400); + const TAG_WITNESS_SCRIPT_HASH: Tag = Tag::new(401); + const TAG_PUBLIC_KEY: Tag = Tag::new(402); + const TAG_PUBLIC_KEY_HASH: Tag = Tag::new(403); + const TAG_WITNESS_PUBLIC_KEY_HASH: Tag = Tag::new(404); + const TAG_COMBO: Tag = Tag::new(405); + const TAG_MULTISIG: Tag = Tag::new(406); + const TAG_SORTED_MULTISIG: Tag = Tag::new(407); + const TAG_RAW_SCRIPT: Tag = Tag::new(408); + const TAG_TAPROOT: Tag = Tag::new(409); + const TAG_COSIGNER: Tag = Tag::new(410); } fn oom() -> Error { diff --git a/urtypes/src/registry/crypto_seed.rs b/urtypes/src/registry/crypto_seed.rs index 2bbb1cf..a353e2f 100644 --- a/urtypes/src/registry/crypto_seed.rs +++ b/urtypes/src/registry/crypto_seed.rs @@ -31,7 +31,7 @@ pub mod digest { use minicbor::{Decoder, Encoder}; /// Tag representing a `crypto-seed-digest`. - pub const TAG: Tag = Tag::Unassigned(600); + pub const TAG: Tag = Tag::new(600); /// Encode a `crypto-seed-digest`. #[doc(alias("crypto-seed-digest"))] diff --git a/urtypes/src/registry/passport.rs b/urtypes/src/registry/passport.rs index fdafaad..e865ac5 100644 --- a/urtypes/src/registry/passport.rs +++ b/urtypes/src/registry/passport.rs @@ -54,11 +54,11 @@ use minicbor::{ use uuid::Uuid; /// Passport model request tag. -const PASSPORT_MODEL_REQUEST_TAG: Tag = Tag::Unassigned(720); +const PASSPORT_MODEL_REQUEST_TAG: Tag = Tag::new(720); /// Passport firmware version request tag. -const PASSPORT_FIRMWARE_VERSION_REQUEST_TAG: Tag = Tag::Unassigned(770); +const PASSPORT_FIRMWARE_VERSION_REQUEST_TAG: Tag = Tag::new(770); /// Passport firmware version response tag. -const PASSPORT_FIRMWARE_VERSION_RESPONSE_TAG: Tag = Tag::Unassigned(771); +const PASSPORT_FIRMWARE_VERSION_RESPONSE_TAG: Tag = Tag::new(771); /// Passport custom `crypto-request`. #[derive(Debug, Clone, Eq, PartialEq, Hash)] diff --git a/urtypes/src/supply_chain_validation.rs b/urtypes/src/supply_chain_validation.rs index f039c17..0d41ffb 100644 --- a/urtypes/src/supply_chain_validation.rs +++ b/urtypes/src/supply_chain_validation.rs @@ -45,7 +45,7 @@ pub struct Challenge { impl Challenge { /// Tag for embedding [`Challenge`] in other types. - pub const TAG: Tag = Tag::Unassigned(710); + pub const TAG: Tag = Tag::new(710); } impl<'b, C> Decode<'b, C> for Challenge { @@ -134,5 +134,5 @@ pub struct Solution<'a> { impl<'a> Solution<'a> { /// Tag for embedding [`Solution`] in other types. - pub const TAG: Tag = Tag::Unassigned(711); + pub const TAG: Tag = Tag::new(711); }