impl Error for error type; remove `Unknown` error variant
This commit is contained in:
parent
7c85199b92
commit
d49db8167e
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
|
||||
name = "secp256k1"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
authors = [ "Dawid Ciężarkiewicz <dpc@ucore.info>",
|
||||
"Andrew Poelstra <apoelstra@wpsoftware.net>" ]
|
||||
license = "CC0-1.0"
|
||||
|
|
|
@ -23,7 +23,7 @@ use serialize::{Decoder, Decodable, Encoder, Encodable};
|
|||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
||||
|
||||
use super::{Secp256k1, ContextFlag};
|
||||
use super::Error::{self, IncapableContext, InvalidPublicKey, InvalidSecretKey, Unknown};
|
||||
use super::Error::{self, IncapableContext, InvalidPublicKey, InvalidSecretKey};
|
||||
use constants;
|
||||
use ffi;
|
||||
|
||||
|
@ -88,7 +88,7 @@ impl SecretKey {
|
|||
-> Result<(), Error> {
|
||||
unsafe {
|
||||
if ffi::secp256k1_ec_privkey_tweak_add(secp.ctx, self.as_mut_ptr(), other.as_ptr()) != 1 {
|
||||
Err(Unknown)
|
||||
Err(InvalidSecretKey)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ impl PublicKey {
|
|||
other.as_ptr()) == 1 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Unknown)
|
||||
Err(InvalidSecretKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
22
src/lib.rs
22
src/lib.rs
|
@ -44,7 +44,7 @@ extern crate libc;
|
|||
extern crate rand;
|
||||
|
||||
use libc::size_t;
|
||||
use std::{fmt, ops, ptr};
|
||||
use std::{error, fmt, ops, ptr};
|
||||
use rand::Rng;
|
||||
|
||||
#[macro_use]
|
||||
|
@ -267,14 +267,28 @@ pub enum Error {
|
|||
InvalidSecretKey,
|
||||
/// Bad recovery id
|
||||
InvalidRecoveryId,
|
||||
/// Boolean-returning function returned the wrong boolean
|
||||
Unknown
|
||||
}
|
||||
|
||||
// Passthrough Debug to Display, since errors should be user-visible
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fmt::Debug::fmt(self, f)
|
||||
f.write_str(error::Error::description(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for Error {
|
||||
fn cause(&self) -> Option<&error::Error> { None }
|
||||
|
||||
fn description(&self) -> &str {
|
||||
match *self {
|
||||
Error::IncapableContext => "secp: context does not have sufficient capabilities",
|
||||
Error::IncorrectSignature => "secp: signature failed verification",
|
||||
Error::InvalidMessage => "secp: message was not 32 bytes (do you need to hash?)",
|
||||
Error::InvalidPublicKey => "secp: malformed public key",
|
||||
Error::InvalidSignature => "secp: malformed signature",
|
||||
Error::InvalidSecretKey => "secp: malformed or out-of-range secret key",
|
||||
Error::InvalidRecoveryId => "secp: bad recovery id"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue