Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit c7d26dc

Browse files
authored
Remove superflous Pair::verify_weak (#13972)
1 parent 2fde380 commit c7d26dc

File tree

5 files changed

+15
-69
lines changed

5 files changed

+15
-69
lines changed

primitives/application-crypto/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,6 @@ macro_rules! app_crypto_pair {
154154
) -> bool {
155155
<$pair>::verify(&sig.0, message, pubkey.as_ref())
156156
}
157-
fn verify_weak<P: AsRef<[u8]>, M: AsRef<[u8]>>(
158-
sig: &[u8],
159-
message: M,
160-
pubkey: P,
161-
) -> bool {
162-
<$pair>::verify_weak(sig, message, pubkey)
163-
}
164157
fn public(&self) -> Self::Public {
165158
Public(self.0.public())
166159
}

primitives/core/src/crypto.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -716,10 +716,6 @@ mod dummy {
716716
true
717717
}
718718

719-
fn verify_weak<P: AsRef<[u8]>, M: AsRef<[u8]>>(_: &[u8], _: M, _: P) -> bool {
720-
true
721-
}
722-
723719
fn public(&self) -> Self::Public {
724720
Self
725721
}
@@ -917,9 +913,6 @@ pub trait Pair: CryptoType + Sized + Clone + Send + Sync + 'static {
917913
/// Verify a signature on a message. Returns true if the signature is good.
918914
fn verify<M: AsRef<[u8]>>(sig: &Self::Signature, message: M, pubkey: &Self::Public) -> bool;
919915

920-
/// Verify a signature on a message. Returns true if the signature is good.
921-
fn verify_weak<P: AsRef<[u8]>, M: AsRef<[u8]>>(sig: &[u8], message: M, pubkey: P) -> bool;
922-
923916
/// Get the public key.
924917
fn public(&self) -> Self::Public;
925918

@@ -1272,14 +1265,6 @@ mod tests {
12721265
true
12731266
}
12741267

1275-
fn verify_weak<P: AsRef<[u8]>, M: AsRef<[u8]>>(
1276-
_sig: &[u8],
1277-
_message: M,
1278-
_pubkey: P,
1279-
) -> bool {
1280-
true
1281-
}
1282-
12831268
fn public(&self) -> Self::Public {
12841269
TestPublic
12851270
}

primitives/core/src/ecdsa.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -407,22 +407,8 @@ impl TraitPair for Pair {
407407
}
408408

409409
/// Verify a signature on a message. Returns true if the signature is good.
410-
fn verify<M: AsRef<[u8]>>(sig: &Self::Signature, message: M, pubkey: &Self::Public) -> bool {
411-
match sig.recover(message) {
412-
Some(actual) => actual == *pubkey,
413-
None => false,
414-
}
415-
}
416-
417-
/// Verify a signature on a message. Returns true if the signature is good.
418-
///
419-
/// This doesn't use the type system to ensure that `sig` and `pubkey` are the correct
420-
/// size. Use it only if you're coming from byte buffers and need the speed.
421-
fn verify_weak<P: AsRef<[u8]>, M: AsRef<[u8]>>(sig: &[u8], message: M, pubkey: P) -> bool {
422-
match Signature::from_slice(sig).and_then(|sig| sig.recover(message)) {
423-
Some(actual) => actual.as_ref() == pubkey.as_ref(),
424-
None => false,
425-
}
410+
fn verify<M: AsRef<[u8]>>(sig: &Self::Signature, message: M, public: &Self::Public) -> bool {
411+
sig.recover(message).map(|actual| actual == *public).unwrap_or_default()
426412
}
427413

428414
/// Return a vec filled with raw data.

primitives/core/src/ed25519.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -406,27 +406,17 @@ impl TraitPair for Pair {
406406
Signature::from_raw(self.secret.sign(message).into())
407407
}
408408

409-
/// Verify a signature on a message. Returns true if the signature is good.
410-
fn verify<M: AsRef<[u8]>>(sig: &Self::Signature, message: M, pubkey: &Self::Public) -> bool {
411-
Self::verify_weak(&sig.0[..], message.as_ref(), pubkey)
412-
}
413-
414-
/// Verify a signature on a message. Returns true if the signature is good.
409+
/// Verify a signature on a message.
415410
///
416-
/// This doesn't use the type system to ensure that `sig` and `pubkey` are the correct
417-
/// size. Use it only if you're coming from byte buffers and need the speed.
418-
fn verify_weak<P: AsRef<[u8]>, M: AsRef<[u8]>>(sig: &[u8], message: M, pubkey: P) -> bool {
419-
let public_key = match VerificationKey::try_from(pubkey.as_ref()) {
420-
Ok(pk) => pk,
421-
Err(_) => return false,
411+
/// Returns true if the signature is good.
412+
fn verify<M: AsRef<[u8]>>(sig: &Self::Signature, message: M, public: &Self::Public) -> bool {
413+
let Ok(public) = VerificationKey::try_from(public.as_slice()) else {
414+
return false
422415
};
423-
424-
let sig = match ed25519_zebra::Signature::try_from(sig) {
425-
Ok(s) => s,
426-
Err(_) => return false,
416+
let Ok(signature) = ed25519_zebra::Signature::try_from(sig.as_ref()) else {
417+
return false
427418
};
428-
429-
public_key.verify(&sig, message.as_ref()).is_ok()
419+
public.verify(&signature, message.as_ref()).is_ok()
430420
}
431421

432422
/// Return a vec filled with raw data.

primitives/core/src/sr25519.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -487,21 +487,13 @@ impl TraitPair for Pair {
487487
}
488488

489489
fn verify<M: AsRef<[u8]>>(sig: &Self::Signature, message: M, pubkey: &Self::Public) -> bool {
490-
Self::verify_weak(&sig.0[..], message, pubkey)
491-
}
492-
493-
fn verify_weak<P: AsRef<[u8]>, M: AsRef<[u8]>>(sig: &[u8], message: M, pubkey: P) -> bool {
494-
let signature = match schnorrkel::Signature::from_bytes(sig) {
495-
Ok(signature) => signature,
496-
Err(_) => return false,
490+
let Ok(signature) = schnorrkel::Signature::from_bytes(sig.as_ref()) else {
491+
return false
497492
};
498-
499-
let pub_key = match PublicKey::from_bytes(pubkey.as_ref()) {
500-
Ok(pub_key) => pub_key,
501-
Err(_) => return false,
493+
let Ok(public) = PublicKey::from_bytes(pubkey.as_ref()) else {
494+
return false
502495
};
503-
504-
pub_key.verify_simple(SIGNING_CTX, message.as_ref(), &signature).is_ok()
496+
public.verify_simple(SIGNING_CTX, message.as_ref(), &signature).is_ok()
505497
}
506498

507499
fn to_raw_vec(&self) -> Vec<u8> {

0 commit comments

Comments
 (0)