Skip to content

Commit

Permalink
SFT-3538: Update minicbor.
Browse files Browse the repository at this point in the history
* Cargo.toml (workspace.dependencies) <minicbor>: Update to 0.24.
* src/cbor/timestamp.rs: Fix breaking changes.
* src/cbor/uuid.rs: Ditto.
* src/passport.rs: Ditto.
* src/registry/crypto_address.rs: Ditto.
* src/registry/crypto_coininfo.rs: Ditto.
* src/registry/crypto_eckey.rs: Ditto.
* src/registry/crypto_hdkey.rs: Ditto.
* src/registry/crypto_output.rs: Ditto.
* src/registry/crypto_seed.rs: Ditto.
* src/registry/passport.rs: Ditto.
* src/supply_chain_validation.rs: Ditto.
  • Loading branch information
jeandudey committed May 10, 2024
1 parent 92a0732 commit e4d6519
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
6 changes: 3 additions & 3 deletions urtypes/src/cbor/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

use minicbor::{
data::{Int, Tag, Type},
data::{IanaTag, Int, Tag, Type},
decode::Error,
encode::Write,
Decode, Decoder, Encode, Encoder,
Expand All @@ -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<Self, Error> {
if d.tag()? != Tag::Timestamp {
if d.tag()? != Tag::from(IanaTag::Timestamp) {
return Err(Error::message("invalid timestamp tag"));
}

Expand All @@ -45,7 +45,7 @@ impl<C> Encode<C> for Timestamp {
e: &mut Encoder<W>,
_ctx: &mut C,
) -> Result<(), minicbor::encode::Error<W::Error>> {
e.tag(Tag::Timestamp)?;
e.tag(IanaTag::Timestamp)?;

match self {
Timestamp::Int(x) => e.int(*x)?,
Expand Down
2 changes: 1 addition & 1 deletion urtypes/src/cbor/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C, W: Write>(
Expand Down
2 changes: 1 addition & 1 deletion urtypes/src/passport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion urtypes/src/registry/crypto_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion urtypes/src/registry/crypto_coininfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion urtypes/src/registry/crypto_eckey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 10 additions & 7 deletions urtypes/src/registry/crypto_hdkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -325,17 +328,17 @@ impl<'a, C> Encode<C> 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)?;
}

Expand Down
22 changes: 11 additions & 11 deletions urtypes/src/registry/crypto_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion urtypes/src/registry/crypto_seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
6 changes: 3 additions & 3 deletions urtypes/src/registry/passport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions urtypes/src/supply_chain_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

0 comments on commit e4d6519

Please sign in to comment.