remove `PublicKey::new()` and `PublicKey::is_valid()`
This commit is contained in:
parent
9b51ed3e2c
commit
c3ec027925
14
src/key.rs
14
src/key.rs
|
@ -122,20 +122,6 @@ impl SecretKey {
|
|||
}
|
||||
|
||||
impl PublicKey {
|
||||
/// Creates a new zeroed out public key
|
||||
#[inline]
|
||||
pub fn new() -> PublicKey {
|
||||
PublicKey(ffi::PublicKey::new())
|
||||
}
|
||||
|
||||
/// Determines whether a pubkey is valid
|
||||
#[inline]
|
||||
pub fn is_valid(&self) -> bool {
|
||||
// The only invalid pubkey the API should be able to create is
|
||||
// the zero one.
|
||||
self.0[..].iter().any(|&x| x != 0)
|
||||
}
|
||||
|
||||
/// Obtains a raw pointer suitable for use with FFI functions
|
||||
#[inline]
|
||||
pub fn as_ptr(&self) -> *const ffi::PublicKey {
|
||||
|
|
22
src/lib.rs
22
src/lib.rs
|
@ -552,16 +552,14 @@ impl<C: Verification> Secp256k1<C> {
|
|||
/// verify-capable context.
|
||||
#[inline]
|
||||
pub fn verify(&self, msg: &Message, sig: &Signature, pk: &key::PublicKey) -> Result<(), Error> {
|
||||
|
||||
if !pk.is_valid() {
|
||||
Err(Error::InvalidPublicKey)
|
||||
} else if unsafe { ffi::secp256k1_ecdsa_verify(self.ctx, sig.as_ptr(), msg.as_ptr(),
|
||||
pk.as_ptr()) } == 0 {
|
||||
unsafe {
|
||||
if ffi::secp256k1_ecdsa_verify(self.ctx, sig.as_ptr(), msg.as_ptr(), pk.as_ptr()) == 0 {
|
||||
Err(Error::IncorrectSignature)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -571,7 +569,7 @@ mod tests {
|
|||
use key::{SecretKey, PublicKey};
|
||||
use super::constants;
|
||||
use super::{Secp256k1, Signature, RecoverableSignature, Message, RecoveryId};
|
||||
use super::Error::{InvalidMessage, InvalidPublicKey, IncorrectSignature, InvalidSignature};
|
||||
use super::Error::{InvalidMessage, IncorrectSignature, InvalidSignature};
|
||||
|
||||
macro_rules! hex {
|
||||
($hex:expr) => {
|
||||
|
@ -642,18 +640,6 @@ mod tests {
|
|||
assert_eq!(one, one.clone());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_pubkey() {
|
||||
let s = Secp256k1::new();
|
||||
let sig = RecoverableSignature::from_compact(&s, &[1; 64], RecoveryId(0)).unwrap();
|
||||
let pk = PublicKey::new();
|
||||
let mut msg = [0u8; 32];
|
||||
thread_rng().fill_bytes(&mut msg);
|
||||
let msg = Message::from_slice(&msg).unwrap();
|
||||
|
||||
assert_eq!(s.verify(&msg, &sig.to_standard(&s), &pk), Err(InvalidPublicKey));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sign() {
|
||||
let mut s = Secp256k1::new();
|
||||
|
|
Loading…
Reference in New Issue