Skip to content

Commit

Permalink
fix(rust/signed-doc): fix decode error
Browse files Browse the repository at this point in the history
  • Loading branch information
saibatizoku committed Jan 16, 2025
1 parent c6b0446 commit 1a430ec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
8 changes: 1 addition & 7 deletions rust/catalyst-types/src/uuid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ pub enum CborUuidError {
pub(crate) fn decode_cbor_uuid<C>(
d: &mut Decoder<'_>, ctx: &mut C,
) -> Result<uuid::Uuid, minicbor::decode::Error> {
let decoded_vec: Vec<u8> = d.decode_with(ctx)?;
let decoded = decoded_vec.try_into().map_err(|e| {
minicbor::decode::Error::message(format!(
"Expected UUID to have 16 bytes, err: {}",
hex::encode(e)
))
})?;
let decoded: [u8; 16] = d.decode_with(ctx)?;
let uuid = uuid::Uuid::from_bytes(decoded);
Ok(uuid)
}
Expand Down
8 changes: 4 additions & 4 deletions rust/catalyst-types/src/uuid/uuid_v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ impl Display for UuidV4 {
}
}

impl Decode<'_, ()> for UuidV4 {
fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result<Self, minicbor::decode::Error> {
impl<C> Decode<'_, C> for UuidV4 {
fn decode(d: &mut Decoder<'_>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
let uuid = decode_cbor_uuid(d, ctx)?;
Ok(Self { uuid })
}
}

impl Encode<()> for UuidV4 {
impl<C> Encode<C> for UuidV4 {
fn encode<W: minicbor::encode::Write>(
&self, e: &mut minicbor::Encoder<W>, ctx: &mut (),
&self, e: &mut minicbor::Encoder<W>, ctx: &mut C,
) -> Result<(), minicbor::encode::Error<W::Error>> {
encode_cbor_uuid(self.uuid(), e, ctx)
}
Expand Down

0 comments on commit 1a430ec

Please sign in to comment.