rust/pv_core: Add decode_hex

It's uncommon and prone to error to silently stop decoding/parsing a
hex-string if there is an invalid character. Therefore, add a new
function `decode_hex` which fixes this behavior and use it in the code.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2024-10-14 12:36:51 +00:00
committed by Jan Höppner
parent a4a29d1e05
commit 8da2f44ae2
5 changed files with 78 additions and 8 deletions
+6
View File
@@ -68,6 +68,12 @@ pub enum Error {
Io(#[from] std::io::Error),
#[error(transparent)]
ParseInt(#[from] std::num::ParseIntError),
#[error("Cannot decode hex string: Size {0} is not a multiple of two")]
InvHexStringSize(usize),
#[error("Cannot decode hex string")]
InvHexStringChar { source: std::num::ParseIntError },
}
/// Error cases for I/O operations