Add a basic test.

This ran into problems with Clone/Copy bounds -- it seems like the
derived impls require that the phantom type T also be Clone / Copy /
Debug for the type to be.  This commit does a hacky fix that makes it
work for now, but it should be cleaned up later.
This commit is contained in:
Henry de Valence 2019-12-03 22:33:27 -08:00
parent d761316579
commit 8bcfeae920
2 changed files with 21 additions and 1 deletions

View File

@ -10,5 +10,8 @@ thiserror = "1.0"
blake2b_simd = "0.5"
jubjub = { git = "https://github.com/zkcrypto/jubjub", rev = "e83f7d2bd136498a27f9d943fea635d8682bf2c6" }
[dev-dependencies]
rand = "0.7"
[features]
nightly = []

View File

@ -39,16 +39,18 @@ pub use signature::Signature;
pub trait SigType: private::Sealed {}
/// A type variable corresponding to Zcash's `BindingSig`.
#[derive(Copy, Clone, Debug)]
pub struct Binding {}
impl SigType for Binding {}
/// A type variable corresponding to Zcash's `SpendAuthSig`.
#[derive(Copy, Clone, Debug)]
pub struct SpendAuth {}
impl SigType for SpendAuth {}
pub(crate) mod private {
use super::*;
pub trait Sealed {
pub trait Sealed: Copy + Clone + std::fmt::Debug {
fn basepoint() -> jubjub::ExtendedPoint;
}
impl Sealed for Binding {
@ -66,3 +68,18 @@ pub(crate) mod private {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sign_and_verify() {
let sk = SecretKey::<Binding>::new(rand::thread_rng());
let msg = b"test";
let sig = sk.sign(rand::thread_rng(), msg);
let pk = PublicKey::from(&sk);
assert_eq!(pk.verify(msg, &sig), Ok(()));
}
}