[public] Rename Signature::verify to is_valid to make it more obvious
Closes #16
Change-Id: Ib5e27d36085ac92de6e3093bd9395f116313710d
diff --git a/src/public/ec/mod.rs b/src/public/ec/mod.rs
index 322cdaf..8297ada 100644
--- a/src/public/ec/mod.rs
+++ b/src/public/ec/mod.rs
@@ -408,7 +408,7 @@
// MAX_SIGNATURE_LEN. Such signatures cannot possibly have been
// generated by an ECDSA signature over any of the curves we support,
// and so it could not possibly be valid. In other words, it would never
- // be correct for ecdsa_verify to return true when invoked on such a
+ // be correct for Signature::is_valid to return true when invoked on such a
// signature.
//
// However, if we were to simply truncate the byte slice and store a
@@ -450,7 +450,7 @@
&self.bytes[..self.len]
}
- fn is_valid(&self) -> bool {
+ fn is_valid_format(&self) -> bool {
self.len != 0
}
@@ -474,8 +474,8 @@
Ok(sig)
}
- fn verify(&self, key: &EcPubKey<C>, message: &[u8]) -> bool {
- if !self.is_valid() {
+ fn is_valid(&self, key: &EcPubKey<C>, message: &[u8]) -> bool {
+ if !self.is_valid_format() {
// see comment on EcdsaSignature::len for why we do this
return false;
}
@@ -532,8 +532,8 @@
fn test_invalid_signature() {
fn test_is_invalid(sig: &EcdsaSignature<P256, Sha256>) {
assert_eq!(sig.len, 0);
- assert!(!sig.is_valid());
- assert!(!sig.verify(&EcPrivKey::<P256>::generate().unwrap().public(), &[],));
+ assert!(!sig.is_valid_format());
+ assert!(!sig.is_valid(&EcPrivKey::<P256>::generate().unwrap().public(), &[],));
}
test_is_invalid(&EcdsaSignature::from_bytes(&[0; MAX_SIGNATURE_LEN + 1]));
test_is_invalid(&EcdsaSignature::from_bytes(&[]));
@@ -593,7 +593,7 @@
{
let sig = EcdsaSignature::<C, Sha256>::sign(&privkey, MESSAGE).unwrap();
assert!(
- EcdsaSignature::<C, Sha256>::from_bytes(sig.bytes()).verify(&pubkey, MESSAGE)
+ EcdsaSignature::<C, Sha256>::from_bytes(sig.bytes()).is_valid(&pubkey, MESSAGE)
)
}
diff --git a/src/public/ed25519.rs b/src/public/ed25519.rs
index 21bf3ea..e2564c3 100644
--- a/src/public/ed25519.rs
+++ b/src/public/ed25519.rs
@@ -166,7 +166,7 @@
Ok(Ed25519Signature::sign_ed25519(key, message))
}
- fn verify(&self, key: &Ed25519PubKey, message: &[u8]) -> bool {
+ fn is_valid(&self, key: &Ed25519PubKey, message: &[u8]) -> bool {
ed25519_verify(message, &self.sig, &key.key)
}
}
diff --git a/src/public/mod.rs b/src/public/mod.rs
index 7ec6643..85e4a8c 100644
--- a/src/public/mod.rs
+++ b/src/public/mod.rs
@@ -22,16 +22,16 @@
/// Verifies a message with this public key.
///
- /// `verify` verifies that a message was signed by the private key
+ /// `is_valid` verifies that a message was signed by the private key
/// corresponding to this public key. It is equivalent to
- /// `signature.verify(self, message)`.
+ /// `signature.is_valid(self, message)`.
#[must_use]
- fn verify<S: Signature<PrivateKey = Self::Private>>(
+ fn is_valid<S: Signature<PrivateKey = Self::Private>>(
&self,
message: &[u8],
signature: &S,
) -> bool {
- signature.verify(self, message)
+ signature.is_valid(self, message)
}
}
@@ -175,10 +175,10 @@
///
/// The input to this function is always a message, never a digest. If a
/// signature scheme calls for hashing a message and signing the hash
- /// digest, `verify` is responsible for both hashing and verifying the
+ /// digest, `is_valid` is responsible for both hashing and verifying the
/// digest.
#[must_use]
- fn verify(&self, key: &<Self::PrivateKey as PrivateKey>::Public, message: &[u8]) -> bool;
+ fn is_valid(&self, key: &<Self::PrivateKey as PrivateKey>::Public, message: &[u8]) -> bool;
}
mod inner {
@@ -238,17 +238,17 @@
bytes_from_sig: G,
) -> S {
let sig = S::sign(key, message).unwrap();
- assert!(sig.verify(&key.public(), message));
- // Make sure the PrivateKey::sign and PublicKey::verify convenience
+ assert!(sig.is_valid(&key.public(), message));
+ // Make sure the PrivateKey::sign and PublicKey::is_valid convenience
// functions also work.
let sig = key.sign::<S>(message).unwrap();
- assert!(key.public().verify(message, &sig));
+ assert!(key.public().is_valid(message, &sig));
let sig2 = S::sign(&key, bytes_from_sig(&sig)).unwrap();
- assert!(!sig2.verify(&key.public(), message));
- // Make sure the PrivateKey::sign and PublicKey::verify convenience
+ assert!(!sig2.is_valid(&key.public(), message));
+ // Make sure the PrivateKey::sign and PublicKey::is_valid convenience
// functions also work.
let sig2 = key.sign::<S>(bytes_from_sig(&sig)).unwrap();
- assert!(!key.public().verify(message, &sig2));
+ assert!(!key.public().is_valid(message, &sig2));
sig_from_bytes(bytes_from_sig(&sig))
}