Skip to content

Commit 4a8599b

Browse files
committed
Added Error::description impl and c_void as c_uchar
1 parent e98975a commit 4a8599b

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/ffi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
//! Direct bindings to the underlying C library functions. These should
1818
//! not be needed for most users.
1919
use core::{mem, hash};
20-
use core::ffi::c_void;
2120
use types::*;
2221
// use std::os::raw::{c_int, c_uchar, c_uint, c_void};
2322

src/lib.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -519,24 +519,31 @@ pub enum Error {
519519
InvalidTweak,
520520
}
521521

522-
// Passthrough Debug to Display, since errors should be user-visible
523-
impl fmt::Display for Error {
524-
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
525-
let res = match *self {
522+
impl Error {
523+
fn as_str(&self) -> &str {
524+
match *self {
526525
Error::IncorrectSignature => "secp: signature failed verification",
527526
Error::InvalidMessage => "secp: message was not 32 bytes (do you need to hash?)",
528527
Error::InvalidPublicKey => "secp: malformed public key",
529528
Error::InvalidSignature => "secp: malformed signature",
530529
Error::InvalidSecretKey => "secp: malformed or out-of-range secret key",
531530
Error::InvalidRecoveryId => "secp: bad recovery id",
532531
Error::InvalidTweak => "secp: bad tweak",
533-
};
534-
f.write_str(res)
532+
}
533+
}
534+
}
535+
536+
// Passthrough Debug to Display, since errors should be user-visible
537+
impl fmt::Display for Error {
538+
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
539+
f.write_str(self.as_str())
535540
}
536541
}
537542

538543
#[cfg(feature = "std")]
539-
impl std::error::Error for Error {}
544+
impl std::error::Error for Error {
545+
fn description(&self) -> &str { self.as_str() }
546+
}
540547

541548
/// Marker trait for indicating that an instance of `Secp256k1` can be used for signing.
542549
pub trait Signing {}

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
pub type c_int = i32;
33
pub type c_uchar = u8;
44
pub type c_uint = u32;
5-
pub use core::ffi::c_void;
5+
pub type c_void = c_uchar;

0 commit comments

Comments
 (0)