Added Error::description copied c_void impl from core::ffi::c_void
This commit is contained in:
parent
e98975a1c0
commit
312b9a55fc
|
@ -17,7 +17,6 @@
|
|||
//! Direct bindings to the underlying C library functions. These should
|
||||
//! not be needed for most users.
|
||||
use core::{mem, hash};
|
||||
use core::ffi::c_void;
|
||||
use types::*;
|
||||
// use std::os::raw::{c_int, c_uchar, c_uint, c_void};
|
||||
|
||||
|
|
21
src/lib.rs
21
src/lib.rs
|
@ -519,10 +519,9 @@ pub enum Error {
|
|||
InvalidTweak,
|
||||
}
|
||||
|
||||
// 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> {
|
||||
let res = match *self {
|
||||
impl Error {
|
||||
fn as_str(&self) -> &str {
|
||||
match *self {
|
||||
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",
|
||||
|
@ -530,13 +529,21 @@ impl fmt::Display for Error {
|
|||
Error::InvalidSecretKey => "secp: malformed or out-of-range secret key",
|
||||
Error::InvalidRecoveryId => "secp: bad recovery id",
|
||||
Error::InvalidTweak => "secp: bad tweak",
|
||||
};
|
||||
f.write_str(res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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> {
|
||||
f.write_str(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::error::Error for Error {}
|
||||
impl std::error::Error for Error {
|
||||
fn description(&self) -> &str { self.as_str() }
|
||||
}
|
||||
|
||||
/// Marker trait for indicating that an instance of `Secp256k1` can be used for signing.
|
||||
pub trait Signing {}
|
||||
|
|
19
src/types.rs
19
src/types.rs
|
@ -1,5 +1,22 @@
|
|||
#![allow(non_camel_case_types)]
|
||||
use core::fmt;
|
||||
|
||||
pub type c_int = i32;
|
||||
pub type c_uchar = u8;
|
||||
pub type c_uint = u32;
|
||||
pub use core::ffi::c_void;
|
||||
|
||||
/// This is an exact copy of https://doc.rust-lang.org/core/ffi/enum.c_void.html
|
||||
/// It should be Equivalent to C's void type when used as a pointer.
|
||||
///
|
||||
/// We can replace this with `core::ffi::c_void` once we update the rustc version to >=1.30.0.
|
||||
#[repr(u8)]
|
||||
pub enum c_void {
|
||||
#[doc(hidden)] __variant1,
|
||||
#[doc(hidden)] __variant2,
|
||||
}
|
||||
|
||||
impl fmt::Debug for c_void {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.pad("c_void")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue