mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-05 20:30:57 +00:00
Remove panics from batch verification API in lieu of better error handling.
This commit is contained in:
parent
58fdc9163b
commit
f1d4c4a732
2 changed files with 19 additions and 9 deletions
|
|
@ -50,11 +50,6 @@ pub use crate::signature::*;
|
||||||
/// * `public_keys` is a slice of `PublicKey`s.
|
/// * `public_keys` is a slice of `PublicKey`s.
|
||||||
/// * `csprng` is an implementation of `Rng + CryptoRng`.
|
/// * `csprng` is an implementation of `Rng + CryptoRng`.
|
||||||
///
|
///
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// This function will panic if the `messages, `signatures`, and `public_keys`
|
|
||||||
/// slices are not equal length.
|
|
||||||
///
|
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// * A `Result` whose `Ok` value is an emtpy tuple and whose `Err` value is a
|
/// * A `Result` whose `Ok` value is an emtpy tuple and whose `Err` value is a
|
||||||
|
|
@ -93,10 +88,15 @@ pub fn verify_batch(
|
||||||
public_keys: &[PublicKey],
|
public_keys: &[PublicKey],
|
||||||
) -> Result<(), SignatureError>
|
) -> Result<(), SignatureError>
|
||||||
{
|
{
|
||||||
const ASSERT_MESSAGE: &'static str = "The number of messages, signatures, and public keys must be equal.";
|
if signatures.len() != messages.len() ||
|
||||||
assert!(signatures.len() == messages.len(), ASSERT_MESSAGE);
|
signatures.len() != public_keys.len() ||
|
||||||
assert!(signatures.len() == public_keys.len(), ASSERT_MESSAGE);
|
public_keys.len() != messages.len() {
|
||||||
assert!(public_keys.len() == messages.len(), ASSERT_MESSAGE);
|
return Err(SignatureError(InternalError::ArrayLengthError{
|
||||||
|
name_a: "signatures", length_a: signatures.len(),
|
||||||
|
name_b: "messages", length_b: messages.len(),
|
||||||
|
name_c: "public_keys", length_c: public_keys.len(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,11 @@ pub(crate) enum InternalError {
|
||||||
},
|
},
|
||||||
/// The verification equation wasn't satisfied
|
/// The verification equation wasn't satisfied
|
||||||
VerifyError,
|
VerifyError,
|
||||||
|
/// Two arrays did not match in size, making the called signature
|
||||||
|
/// verification method impossible.
|
||||||
|
ArrayLengthError{ name_a: &'static str, length_a: usize,
|
||||||
|
name_b: &'static str, length_b: usize,
|
||||||
|
name_c: &'static str, length_c: usize, },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for InternalError {
|
impl Display for InternalError {
|
||||||
|
|
@ -46,6 +51,11 @@ impl Display for InternalError {
|
||||||
=> write!(f, "{} must be {} bytes in length", n, l),
|
=> write!(f, "{} must be {} bytes in length", n, l),
|
||||||
InternalError::VerifyError
|
InternalError::VerifyError
|
||||||
=> write!(f, "Verification equation was not satisfied"),
|
=> write!(f, "Verification equation was not satisfied"),
|
||||||
|
InternalError::ArrayLengthError{ name_a: na, length_a: la,
|
||||||
|
name_b: nb, length_b: lb,
|
||||||
|
name_c: nc, length_c: lc, }
|
||||||
|
=> write!(f, "Arrays must be the same length: {} has length {},
|
||||||
|
{} has length {}, {} has length {}.", na, la, nb, lb, nc, lc),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue