Return an error if the IKM list ID is invalid

This commit is contained in:
Rodolphe Bréard 2024-03-16 10:28:25 +01:00
parent 230f867502
commit 66271877dc
2 changed files with 5 additions and 0 deletions

View file

@ -18,6 +18,8 @@ pub enum Error {
ParsingEncodedDataInvalidIkmId(Vec<u8>), ParsingEncodedDataInvalidIkmId(Vec<u8>),
#[error("parsing error: encoded data: invalid IKM length{0}")] #[error("parsing error: encoded data: invalid IKM length{0}")]
ParsingEncodedDataInvalidIkmLen(usize), ParsingEncodedDataInvalidIkmLen(usize),
#[error("parsing error: encoded data: invalid IKM list id: {0:?}")]
ParsingEncodedDataInvalidIkmListId(Vec<u8>),
#[error("parsing error: encoded data: invalid IKM list length{0}")] #[error("parsing error: encoded data: invalid IKM list length{0}")]
ParsingEncodedDataInvalidIkmListLen(usize), ParsingEncodedDataInvalidIkmListLen(usize),
#[error("parsing error: encoded data: invalid number of parts: got {1} instead of {0}")] #[error("parsing error: encoded data: invalid number of parts: got {1} instead of {0}")]

View file

@ -53,6 +53,9 @@ pub(crate) fn decode_ikm_list(data: &str) -> Result<InputKeyMaterialList> {
return Err(Error::ParsingEncodedDataInvalidIkmListLen(v.len())); return Err(Error::ParsingEncodedDataInvalidIkmListLen(v.len()));
} }
let id_data = decode_data(v[0])?; 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 id_counter = CounterId::from_le_bytes(id_data[0..4].try_into().unwrap());
let mut ikm_lst = Vec::with_capacity(v.len() - 1); let mut ikm_lst = Vec::with_capacity(v.len() - 1);
for ikm_str in &v[1..] { for ikm_str in &v[1..] {