diff --git a/src/error.rs b/src/error.rs index b4b8cf4..3151807 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,6 +18,8 @@ pub enum Error { ParsingEncodedDataInvalidIkmId(Vec), #[error("parsing error: encoded data: invalid IKM length{0}")] ParsingEncodedDataInvalidIkmLen(usize), + #[error("parsing error: encoded data: invalid IKM list id: {0:?}")] + ParsingEncodedDataInvalidIkmListId(Vec), #[error("parsing error: encoded data: invalid IKM list length{0}")] ParsingEncodedDataInvalidIkmListLen(usize), #[error("parsing error: encoded data: invalid number of parts: got {1} instead of {0}")] diff --git a/src/storage.rs b/src/storage.rs index e2f21bb..83356a4 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -53,6 +53,9 @@ pub(crate) fn decode_ikm_list(data: &str) -> Result { return Err(Error::ParsingEncodedDataInvalidIkmListLen(v.len())); } let id_data = decode_data(v[0])?; + if id_data.len() != 4 { + return Err(Error::ParsingEncodedDataInvalidIkmListId(id_data)); + } let id_counter = CounterId::from_le_bytes(id_data[0..4].try_into().unwrap()); let mut ikm_lst = Vec::with_capacity(v.len() - 1); for ikm_str in &v[1..] {