Skip to content

Commit

Permalink
fix(rust/catalyst-types): fix decode error
Browse files Browse the repository at this point in the history
  • Loading branch information
saibatizoku committed Jan 16, 2025
1 parent 257c0ff commit c6b0446
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions rust/catalyst-types/src/uuid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ pub enum CborUuidError {
pub(crate) fn decode_cbor_uuid<C>(
d: &mut Decoder<'_>, ctx: &mut C,
) -> Result<uuid::Uuid, minicbor::decode::Error> {
let decoded = d
.decode_with(ctx)
.map_err(|_| minicbor::decode::Error::message("Expected UUID to have 16 bytes"))?;
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 uuid = uuid::Uuid::from_bytes(decoded);
Ok(uuid)
}
Expand Down

0 comments on commit c6b0446

Please sign in to comment.