Skip to content

Commit

Permalink
Test for verify_stream()
Browse files Browse the repository at this point in the history
  • Loading branch information
mkj committed Jun 12, 2023
1 parent b8b98bf commit 8526f1b
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}

0 comments on commit 8526f1b

Please sign in to comment.