mirror of
https://github.com/saymrwulf/risc0-curve25519-dalek-source.git
synced 2026-09-04 20:03:40 +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.
|
||||
/// * `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;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,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 {
|
||||
|
|
@ -46,6 +51,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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue