Skip to content
Snippets Groups Projects
Commit c5c01361 authored by Éloïs's avatar Éloïs
Browse files

[ref] crypto:bases:b16 replace unwrap by if let

parent c7566976
No related branches found
No related tags found
No related merge requests found
......@@ -40,23 +40,22 @@ pub fn str_hex_to_32bytes(text: &str) -> Result<[u8; 32], BaseConvertionError> {
let byte1 = chars[i].to_digit(16);
let byte2 = chars[i + 1].to_digit(16);
if byte1.is_none() {
return Err(BaseConvertionError::InvalidCharacter {
character: chars[i],
offset: i,
});
} else if byte2.is_none() {
if let Some(byte1) = byte1 {
if let Some(byte2) = byte2 {
let byte = ((byte1 as u8) << 4) | byte2 as u8;
bytes[i / 2] = byte;
} else {
return Err(BaseConvertionError::InvalidCharacter {
character: chars[i + 1],
offset: i + 1,
});
}
let byte1 = byte1.unwrap_or_else(|| panic!(dbg!("dev error"))) as u8;
let byte2 = byte2.unwrap_or_else(|| panic!(dbg!("dev error"))) as u8;
let byte = (byte1 << 4) | byte2;
bytes[i / 2] = byte;
} else {
return Err(BaseConvertionError::InvalidCharacter {
character: chars[i],
offset: i,
});
}
}
Ok(bytes)
......
......@@ -15,8 +15,9 @@
//! Manage cryptographic operations for the DUP (DUniter Protocol).
#![deny(clippy::option_unwrap_used, clippy::result_unwrap_used)]
#![deny(
clippy::option_unwrap_used,
clippy::result_unwrap_used,
missing_docs,
missing_debug_implementations,
missing_copy_implementations,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment