From 8526f1ba8026e383779f0bf08a1480f57d649293 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Mon, 12 Jun 2023 21:57:17 +0800 Subject: [PATCH] Test for verify_stream() --- tests/ed25519.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/ed25519.rs b/tests/ed25519.rs index 60729cb..a9891be 100644 --- a/tests/ed25519.rs +++ b/tests/ed25519.rs @@ -697,3 +697,56 @@ mod serialisation { ); } } + +#[cfg(all(test, feature = "rand_core"))] +mod stream { + use super::*; + use rand::rngs::OsRng; + + #[test] + fn verify_stream() { + let signing_key = SigningKey::generate(&mut OsRng); + let verifying_key = signing_key.verifying_key(); + + let buf = [1u8, 2, 5, 9]; + let sig = signing_key.sign(&buf); + + let sver = verifying_key.verify_stream(&sig).unwrap(); + assert!( + sver.finalize_and_verify().is_err(), + "Stream verifier fails without update" + ); + + let mut sver = verifying_key.verify_stream(&sig).unwrap(); + sver.update(buf); + assert!( + sver.finalize_and_verify().is_ok(), + "Stream verifier one-pass succeeds" + ); + + let mut sver = verifying_key.verify_stream(&sig).unwrap(); + sver.update(&buf[..2]); + sver.update(&buf[2..]); + assert!( + sver.finalize_and_verify().is_ok(), + "Stream verifier two-pass succeeds" + ); + + let mut sver = verifying_key.verify_stream(&sig).unwrap(); + sver.update(&[]); + sver.update(buf); + sver.update(&[]); + assert!( + sver.finalize_and_verify().is_ok(), + "Stream verifier empty update succeeds" + ); + + let mut sver = verifying_key.verify_stream(&sig).unwrap(); + sver.update(buf); + sver.update(&[9u8]); + assert!( + sver.finalize_and_verify().is_err(), + "Stream verifier extra input fails" + ); + } +}