Fold a few panics

Removes a few panics we don't need by folding them in the Error case of their enclosing Result return.
This commit is contained in:
François Garillot
2020-12-09 13:10:05 -08:00
parent 94630dff7c
commit 6b22064863
4 changed files with 35 additions and 48 deletions
+8 -1
View File
@@ -160,7 +160,14 @@ impl KeyPair for X25519KeyPair {
}
fn check_public_key(key: Self::Repr) -> Result<Self::Repr, InternalPakeError> {
let key_bytes: [u8; 32] = (&key[..]).try_into().expect("Key invariant broken");
let key_bytes: [u8; 32] =
(&key[..])
.try_into()
.map_err(|_| InternalPakeError::SizeError {
name: "key",
len: 32,
actual_len: key.len(),
})?;
let point = ::curve25519_dalek::montgomery::MontgomeryPoint(key_bytes)
.to_edwards(1)
.ok_or(InternalPakeError::PointError)?;