Replaced std with core, and made std::error::Error optional through feature
This commit is contained in:
parent
8b4963588a
commit
11ce86681f
|
@ -27,8 +27,9 @@ path = "src/lib.rs"
|
|||
|
||||
[features]
|
||||
unstable = []
|
||||
default = []
|
||||
default = ["std"]
|
||||
fuzztarget = []
|
||||
std = []
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.6"
|
||||
|
@ -38,7 +39,9 @@ serde_test = "1.0"
|
|||
[dependencies.rand]
|
||||
version = "0.6"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
//! Support for shared secret computations
|
||||
//!
|
||||
|
||||
use std::{ops, ptr};
|
||||
use core::{ops, ptr};
|
||||
|
||||
use key::{SecretKey, PublicKey};
|
||||
use ffi;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#[cfg(any(test, feature = "rand"))] use rand::Rng;
|
||||
|
||||
use std::{fmt, mem, str};
|
||||
use core::{fmt, mem, str};
|
||||
|
||||
use super::{from_hex, Secp256k1};
|
||||
use super::Error::{self, InvalidPublicKey, InvalidSecretKey};
|
||||
|
|
24
src/lib.rs
24
src/lib.rs
|
@ -133,15 +133,17 @@
|
|||
#![cfg_attr(feature = "dev", feature(plugin))]
|
||||
#![cfg_attr(feature = "dev", plugin(clippy))]
|
||||
|
||||
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
|
||||
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
|
||||
#[cfg(all(test, feature = "unstable"))] extern crate test;
|
||||
#[cfg(any(test, feature = "rand"))] pub extern crate rand;
|
||||
#[cfg(any(test))] extern crate rand_core;
|
||||
#[cfg(feature = "serde")] pub extern crate serde;
|
||||
#[cfg(all(test, feature = "serde"))] extern crate serde_test;
|
||||
|
||||
use std::{error, fmt, ptr, str};
|
||||
#[cfg(any(test, feature = "rand"))] use rand::Rng;
|
||||
#[cfg(any(test, feature = "std"))] extern crate core;
|
||||
|
||||
use core::{fmt, ptr, str};
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
@ -152,7 +154,7 @@ pub mod key;
|
|||
|
||||
pub use key::SecretKey;
|
||||
pub use key::PublicKey;
|
||||
use std::marker::PhantomData;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
/// A tag used for recovering the public key from a compact signature
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
|
@ -519,15 +521,7 @@ pub enum Error {
|
|||
// 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(error::Error::description(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for Error {
|
||||
fn cause(&self) -> Option<&error::Error> { None }
|
||||
|
||||
fn description(&self) -> &str {
|
||||
match *self {
|
||||
let res = 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",
|
||||
|
@ -535,10 +529,14 @@ impl error::Error 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)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
/// Marker trait for indicating that an instance of `Secp256k1` can be used for signing.
|
||||
pub trait Signing {}
|
||||
|
||||
|
|
|
@ -53,14 +53,14 @@ macro_rules! impl_array_newtype {
|
|||
|
||||
impl PartialOrd for $thing {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &$thing) -> Option<::std::cmp::Ordering> {
|
||||
fn partial_cmp(&self, other: &$thing) -> Option<::core::cmp::Ordering> {
|
||||
self[..].partial_cmp(&other[..])
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for $thing {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &$thing) -> ::std::cmp::Ordering {
|
||||
fn cmp(&self, other: &$thing) -> ::core::cmp::Ordering {
|
||||
self[..].cmp(&other[..])
|
||||
}
|
||||
}
|
||||
|
@ -69,8 +69,8 @@ macro_rules! impl_array_newtype {
|
|||
#[inline]
|
||||
fn clone(&self) -> $thing {
|
||||
unsafe {
|
||||
use std::intrinsics::copy_nonoverlapping;
|
||||
use std::mem;
|
||||
use core::intrinsics::copy_nonoverlapping;
|
||||
use core::mem;
|
||||
let mut ret: $thing = mem::uninitialized();
|
||||
copy_nonoverlapping(self.as_ptr(),
|
||||
ret.as_mut_ptr(),
|
||||
|
@ -80,7 +80,7 @@ macro_rules! impl_array_newtype {
|
|||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::Index<usize> for $thing {
|
||||
impl ::core::ops::Index<usize> for $thing {
|
||||
type Output = $ty;
|
||||
|
||||
#[inline]
|
||||
|
@ -90,41 +90,41 @@ macro_rules! impl_array_newtype {
|
|||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::Index<::std::ops::Range<usize>> for $thing {
|
||||
impl ::core::ops::Index<::core::ops::Range<usize>> for $thing {
|
||||
type Output = [$ty];
|
||||
|
||||
#[inline]
|
||||
fn index(&self, index: ::std::ops::Range<usize>) -> &[$ty] {
|
||||
fn index(&self, index: ::core::ops::Range<usize>) -> &[$ty] {
|
||||
let &$thing(ref dat) = self;
|
||||
&dat[index]
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::Index<::std::ops::RangeTo<usize>> for $thing {
|
||||
impl ::core::ops::Index<::core::ops::RangeTo<usize>> for $thing {
|
||||
type Output = [$ty];
|
||||
|
||||
#[inline]
|
||||
fn index(&self, index: ::std::ops::RangeTo<usize>) -> &[$ty] {
|
||||
fn index(&self, index: ::core::ops::RangeTo<usize>) -> &[$ty] {
|
||||
let &$thing(ref dat) = self;
|
||||
&dat[index]
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::Index<::std::ops::RangeFrom<usize>> for $thing {
|
||||
impl ::core::ops::Index<::core::ops::RangeFrom<usize>> for $thing {
|
||||
type Output = [$ty];
|
||||
|
||||
#[inline]
|
||||
fn index(&self, index: ::std::ops::RangeFrom<usize>) -> &[$ty] {
|
||||
fn index(&self, index: ::core::ops::RangeFrom<usize>) -> &[$ty] {
|
||||
let &$thing(ref dat) = self;
|
||||
&dat[index]
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::Index<::std::ops::RangeFull> for $thing {
|
||||
impl ::core::ops::Index<::core::ops::RangeFull> for $thing {
|
||||
type Output = [$ty];
|
||||
|
||||
#[inline]
|
||||
fn index(&self, _: ::std::ops::RangeFull) -> &[$ty] {
|
||||
fn index(&self, _: ::core::ops::RangeFull) -> &[$ty] {
|
||||
let &$thing(ref dat) = self;
|
||||
&dat[..]
|
||||
}
|
||||
|
@ -134,8 +134,8 @@ macro_rules! impl_array_newtype {
|
|||
|
||||
macro_rules! impl_pretty_debug {
|
||||
($thing:ident) => {
|
||||
impl ::std::fmt::Debug for $thing {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
impl ::core::fmt::Debug for $thing {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||
try!(write!(f, "{}(", stringify!($thing)));
|
||||
for i in self[..].iter().cloned() {
|
||||
try!(write!(f, "{:02x}", i));
|
||||
|
@ -148,8 +148,8 @@ macro_rules! impl_pretty_debug {
|
|||
|
||||
macro_rules! impl_raw_debug {
|
||||
($thing:ident) => {
|
||||
impl ::std::fmt::Debug for $thing {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
impl ::core::fmt::Debug for $thing {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||
for i in self[..].iter().cloned() {
|
||||
try!(write!(f, "{:02x}", i));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue