Merge branch 'feature/no-panics' into develop

This commit is contained in:
Isis Lovecruft 2019-11-21 00:09:32 +00:00
commit 8f848793f3
No known key found for this signature in database
GPG key ID: AB41313533E8E812
2 changed files with 19 additions and 9 deletions

View file

@ -50,11 +50,6 @@ pub use crate::signature::*;
/// * `public_keys` is a slice of `PublicKey`s.
/// * `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
///
/// * 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],
) -> Result<(), SignatureError>
{
const ASSERT_MESSAGE: &'static str = "The number of messages, signatures, and public keys must be equal.";
assert!(signatures.len() == messages.len(), ASSERT_MESSAGE);
assert!(signatures.len() == public_keys.len(), ASSERT_MESSAGE);
assert!(public_keys.len() == messages.len(), ASSERT_MESSAGE);
if signatures.len() != messages.len() ||
signatures.len() != public_keys.len() ||
public_keys.len() != messages.len() {
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")]
use alloc::vec::Vec;

View file

@ -36,6 +36,11 @@ pub(crate) enum InternalError {
},
/// The verification equation wasn't satisfied
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 {
@ -49,6 +54,11 @@ impl Display for InternalError {
=> write!(f, "{} must be {} bytes in length", n, l),
InternalError::VerifyError
=> 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),
}
}
}