tlv8 wronglength error more descriptive
This commit is contained in:
parent
a4e3e37e6b
commit
03a4835ed8
|
@ -80,7 +80,10 @@ pub fn decode(data: &[u8]) -> Result<HashMap<u8, Vec<u8>>, TlvCodecError> {
|
|||
let tlv_len = (data[1] as usize) + 2;
|
||||
let current;
|
||||
if tlv_len > data.len() {
|
||||
return Err(TlvCodecError::WrongLength);
|
||||
return Err(TlvCodecError::WrongLength {
|
||||
expected: tlv_len,
|
||||
got: data.len(),
|
||||
});
|
||||
}
|
||||
|
||||
(current, data) = data.split_at(tlv_len);
|
||||
|
@ -90,7 +93,10 @@ pub fn decode(data: &[u8]) -> Result<HashMap<u8, Vec<u8>>, TlvCodecError> {
|
|||
}
|
||||
|
||||
if current.len() < tlv_len {
|
||||
return Err(TlvCodecError::WrongLength);
|
||||
return Err(TlvCodecError::WrongLength {
|
||||
expected: tlv_len,
|
||||
got: current.len(),
|
||||
});
|
||||
}
|
||||
|
||||
let tlv_type = current[0];
|
||||
|
@ -110,7 +116,7 @@ pub enum TlvCodecError {
|
|||
#[error("too short")]
|
||||
TooShort,
|
||||
#[error("wrong length")]
|
||||
WrongLength,
|
||||
WrongLength { expected: usize, got: usize },
|
||||
}
|
||||
|
||||
pub trait TlvEncode {
|
||||
|
|
Loading…
Reference in a new issue