Skip to content

Commit ef4662e

Browse files
committed
Added Error::description impl and c_void as c_uchar
1 parent 2f0e3a5 commit ef4662e

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

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

542547
#[cfg(feature = "std")]
543-
impl std::error::Error for Error {}
548+
impl std::error::Error for Error {
549+
fn description(&self) -> &str { self.as_str() }
550+
}
544551

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