Skip to content

Commit 4339845

Browse files
authored
feat: add len check to short keyset id (#1492)
1 parent 40063c8 commit 4339845

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

crates/cashu/src/nuts/nut02.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub enum Error {
3434
#[error(transparent)]
3535
HexError(#[from] hex::Error),
3636
/// Keyset length error
37-
#[error("NUT02: ID length invalid")]
37+
#[error("NUT02: ID length invalid, expected 8 bytes (short/v1) or 33 bytes (v2)")]
3838
Length,
3939
/// Unknown version
4040
#[error("NUT02: Unknown Version")]
@@ -350,6 +350,10 @@ impl ShortKeysetId {
350350

351351
/// [`ShortKeysetId`] from bytes
352352
pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
353+
if bytes.is_empty() {
354+
return Err(Error::Length);
355+
}
356+
353357
let version = KeySetVersion::from_byte(&bytes[0])?;
354358
let prefix = bytes[1..].to_vec();
355359
Ok(Self { version, prefix })

0 commit comments

Comments
 (0)