Skip to content

Commit e554421

Browse files
committed
Added Error::description impl and c_void as c_uchar
1 parent a1b659f commit e554421

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
@@ -522,24 +522,31 @@ pub enum Error {
522522
InvalidTweak,
523523
}
524524

525-
// Passthrough Debug to Display, since errors should be user-visible
526-
impl fmt::Display for Error {
527-
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
528-
let res = match *self {
525+
impl Error {
526+
fn as_str(&self) -> &str {
527+
match *self {
529528
Error::IncorrectSignature => "secp: signature failed verification",
530529
Error::InvalidMessage => "secp: message was not 32 bytes (do you need to hash?)",
531530
Error::InvalidPublicKey => "secp: malformed public key",
532531
Error::InvalidSignature => "secp: malformed signature",
533532
Error::InvalidSecretKey => "secp: malformed or out-of-range secret key",
534533
Error::InvalidRecoveryId => "secp: bad recovery id",
535534
Error::InvalidTweak => "secp: bad tweak",
536-
};
537-
f.write_str(res)
535+
}
536+
}
537+
}
538+
539+
// Passthrough Debug to Display, since errors should be user-visible
540+
impl fmt::Display for Error {
541+
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
542+
f.write_str(self.as_str())
538543
}
539544
}
540545

541546
#[cfg(feature = "std")]
542-
impl std::error::Error for Error {}
547+
impl std::error::Error for Error {
548+
fn description(&self) -> &str { self.as_str() }
549+
}
543550

544551
/// Marker trait for indicating that an instance of `Secp256k1` can be used for signing.
545552
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)