remove `PublicKey::new()` and `PublicKey::is_valid()`

This commit is contained in:
Andrew Poelstra 2018-07-24 21:24:19 +00:00
parent 9b51ed3e2c
commit c3ec027925
2 changed files with 7 additions and 35 deletions

View File

@ -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 {

View File

@ -552,17 +552,15 @@ 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)]
mod tests {
@ -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();