diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index 68f435756..596f0fede 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -134,6 +134,11 @@ mod tests { } } + #[test] + fn test_parse_0x() { + assert!("0x0000000000000000000000000000000000000000000000000000000000000000".parse::().is_ok()) + } + #[test] fn test_serialize_invalid() { assert!(ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000\"") diff --git a/ethereum-types/src/lib.rs b/ethereum-types/src/lib.rs index ce84e3731..56963f28d 100644 --- a/ethereum-types/src/lib.rs +++ b/ethereum-types/src/lib.rs @@ -13,9 +13,7 @@ mod uint; pub use ethbloom::{Bloom, BloomRef, Input as BloomInput}; pub use hash::{BigEndianHash, H128, H160, H256, H264, H32, H512, H520, H64}; -#[cfg(feature = "num-traits")] -pub use primitive_types::{FromStrRadixErr, FromStrRadixErrKind}; -pub use uint::{FromDecStrErr, U128, U256, U512, U64}; +pub use uint::{FromDecStrErr, FromStrRadixErr, FromStrRadixErrKind, U128, U256, U512, U64}; pub type Address = H160; pub type Secret = H256; diff --git a/ethereum-types/src/uint.rs b/ethereum-types/src/uint.rs index 440221c16..eaf9bbf49 100644 --- a/ethereum-types/src/uint.rs +++ b/ethereum-types/src/uint.rs @@ -14,7 +14,7 @@ use impl_rlp::impl_uint_rlp; use impl_serde::impl_uint_serde; use uint_crate::*; -pub use uint_crate::FromDecStrErr; +pub use uint_crate::{FromDecStrErr, FromStrRadixErr, FromStrRadixErrKind}; construct_uint! { /// Unsigned 64-bit integer. diff --git a/fixed-hash/src/hash.rs b/fixed-hash/src/hash.rs index a971b4136..c84d6bb35 100644 --- a/fixed-hash/src/hash.rs +++ b/fixed-hash/src/hash.rs @@ -588,6 +588,7 @@ macro_rules! impl_rustc_hex_for_fixed_hash { /// - When encountering invalid non hex-digits /// - Upon empty string input or invalid input length in general fn from_str(input: &str) -> $crate::core_::result::Result<$name, $crate::rustc_hex::FromHexError> { + let input = input.strip_prefix("0x").unwrap_or(input); let mut iter = $crate::rustc_hex::FromHexIter::new(input); let mut result = Self::zero(); for byte in result.as_mut() { diff --git a/keccak-hash/Cargo.toml b/keccak-hash/Cargo.toml index 9f1e4523b..54e75b1aa 100644 --- a/keccak-hash/Cargo.toml +++ b/keccak-hash/Cargo.toml @@ -13,7 +13,7 @@ tiny-keccak = { version = "2.0", features = ["keccak"] } primitive-types = { path = "../primitive-types", version = "0.8", default-features = false } [dev-dependencies] -tempdir = "0.3.7" +tempfile = "3.1.0" criterion = "0.3.0" [features] diff --git a/keccak-hash/src/lib.rs b/keccak-hash/src/lib.rs index dbad92af5..e01f6156d 100644 --- a/keccak-hash/src/lib.rs +++ b/keccak-hash/src/lib.rs @@ -189,7 +189,7 @@ mod tests { use std::io::{BufReader, Write}; // given - let tmpdir = tempdir::TempDir::new("keccak").unwrap(); + let tmpdir = tempfile::Builder::new().prefix("keccak").tempdir().unwrap(); let mut path = tmpdir.path().to_owned(); path.push("should_keccak_a_file"); // Prepare file diff --git a/parity-crypto/CHANGELOG.md b/parity-crypto/CHANGELOG.md index 42a24d6a5..2d8a372c0 100644 --- a/parity-crypto/CHANGELOG.md +++ b/parity-crypto/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog]. ### Breaking - Bump `rust-secp256k1` to v0.19, always allow zero signatures. [#438](https://github.com/paritytech/parity-common/pull/438) - Updated `rlp` to 0.5. [#463](https://github.com/paritytech/parity-common/pull/463) +- Remove deprecated trait impls `FromStr`/`TryFrom` for `Secret` [#495](https://github.com/paritytech/parity-common/pull/495) ## [0.6.2] - 2020-06-19 - Put `Secret` memory on heap. [#400](https://github.com/paritytech/parity-common/pull/400) diff --git a/parity-crypto/src/publickey/secret_key.rs b/parity-crypto/src/publickey/secret_key.rs index 269afdf3e..80a37a590 100644 --- a/parity-crypto/src/publickey/secret_key.rs +++ b/parity-crypto/src/publickey/secret_key.rs @@ -138,7 +138,7 @@ impl Secret { pub fn dec(&mut self) -> Result<(), Error> { match self.is_zero() { true => { - *self = Secret::try_from(super::MINUS_ONE_KEY) + *self = Self::copy_from_slice(&super::MINUS_ONE_KEY) .expect("Constructing a secret key from a known-good constant works; qed."); Ok(()) } @@ -213,14 +213,6 @@ impl Secret { } } -#[deprecated(since = "0.6.2", note = "please use `copy_from_str` instead, input is not zeroized")] -impl FromStr for Secret { - type Err = Error; - fn from_str(s: &str) -> Result { - Ok(H256::from_str(s).map_err(|e| Error::Custom(format!("{:?}", e)))?.into()) - } -} - impl From<[u8; 32]> for Secret { #[inline(always)] fn from(mut k: [u8; 32]) -> Self { @@ -239,27 +231,6 @@ impl From for Secret { } } -#[deprecated(since = "0.6.2", note = "please use `copy_from_str` instead, input is not zeroized")] -impl TryFrom<&str> for Secret { - type Error = Error; - - fn try_from(s: &str) -> Result { - s.parse().map_err(|e| Error::Custom(format!("{:?}", e))) - } -} - -#[deprecated(since = "0.6.2", note = "please use `copy_from_slice` instead, input is not zeroized")] -impl TryFrom<&[u8]> for Secret { - type Error = Error; - - fn try_from(b: &[u8]) -> Result { - if b.len() != SECP256K1_SECRET_KEY_SIZE { - return Err(Error::InvalidSecretKey); - } - Ok(Self { inner: Box::new(H256::from_slice(b)) }) - } -} - impl From for Secret { #[inline(always)] fn from(key: key::SecretKey) -> Self { diff --git a/parity-util-mem/Cargo.toml b/parity-util-mem/Cargo.toml index 09a8d1c7c..6ab5f3e54 100644 --- a/parity-util-mem/Cargo.toml +++ b/parity-util-mem/Cargo.toml @@ -23,7 +23,7 @@ hashbrown = { version = "0.9", optional = true } mimalloc = { version = "0.1.18", optional = true } libmimalloc-sys = { version = "0.1.14", optional = true } parity-util-mem-derive = { path = "derive", version = "0.1" } -impl-trait-for-tuples = "0.1.3" +impl-trait-for-tuples = "0.2.0" smallvec = { version = "1.0.0", optional = true } ethereum-types = { version = "0.10.0", optional = true, path = "../ethereum-types" } diff --git a/primitive-types/impls/num-traits/Cargo.toml b/primitive-types/impls/num-traits/Cargo.toml index fed7c898e..8e0fef9f3 100644 --- a/primitive-types/impls/num-traits/Cargo.toml +++ b/primitive-types/impls/num-traits/Cargo.toml @@ -10,7 +10,3 @@ edition = "2018" [dependencies] num-traits = { version = "0.2", default-features = false } uint = { version = "0.8.5", path = "../../../uint", default-features = false } - -[features] -default = ["std"] -std = ["num-traits/std", "uint/std"] diff --git a/primitive-types/impls/num-traits/src/lib.rs b/primitive-types/impls/num-traits/src/lib.rs index d5e5e5d8b..094447592 100644 --- a/primitive-types/impls/num-traits/src/lib.rs +++ b/primitive-types/impls/num-traits/src/lib.rs @@ -8,12 +8,13 @@ //! num-traits support for uint. -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] #[doc(hidden)] pub use num_traits; -pub use uint::{FromStrRadixErr, FromStrRadixErrKind}; +#[doc(hidden)] +pub use uint; /// Add num-traits support to an integer created by `construct_uint!`. #[macro_export] @@ -39,7 +40,7 @@ macro_rules! impl_uint_num_traits { } impl $crate::num_traits::Num for $name { - type FromStrRadixErr = $crate::FromStrRadixErr; + type FromStrRadixErr = $crate::uint::FromStrRadixErr; fn from_str_radix(txt: &str, radix: u32) -> Result { Self::from_str_radix(txt, radix) diff --git a/primitive-types/src/lib.rs b/primitive-types/src/lib.rs index bf9acbdc3..696ac6898 100644 --- a/primitive-types/src/lib.rs +++ b/primitive-types/src/lib.rs @@ -22,7 +22,6 @@ use fixed_hash::{construct_fixed_hash, impl_fixed_hash_conversions}; #[cfg(feature = "scale-info")] use scale_info::TypeInfo; use uint::{construct_uint, uint_full_mul_reg}; -pub use uint::{FromStrRadixErr, FromStrRadixErrKind}; /// Error type for conversion. #[derive(Debug, PartialEq, Eq)] diff --git a/rlp-derive/Cargo.toml b/rlp-derive/Cargo.toml index 5059d6d02..16f7e010e 100644 --- a/rlp-derive/Cargo.toml +++ b/rlp-derive/Cargo.toml @@ -16,4 +16,4 @@ quote = "1.0.2" proc-macro2 = "1.0.8" [dev-dependencies] -rlp = "0.4.4" +rlp = { version = "0.5.0", path = "../rlp" } diff --git a/uint/src/uint.rs b/uint/src/uint.rs index edf5c9e5a..27bd0be96 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -1688,6 +1688,7 @@ macro_rules! construct_uint { type Err = $crate::FromHexError; fn from_str(value: &str) -> $crate::core_::result::Result<$name, Self::Err> { + let value = value.strip_prefix("0x").unwrap_or(value); const BYTES_LEN: usize = $n_words * 8; const MAX_ENCODED_LEN: usize = BYTES_LEN * 2; diff --git a/uint/tests/uint_tests.rs b/uint/tests/uint_tests.rs index 539f5f23f..e9f441ac9 100644 --- a/uint/tests/uint_tests.rs +++ b/uint/tests/uint_tests.rs @@ -133,6 +133,8 @@ fn uint256_from() { // test initializtion from string let sa = U256::from_str("0a").unwrap(); + let sa2 = U256::from_str("0x0a").unwrap(); + assert_eq!(sa2, sa); assert_eq!(e, sa); assert_eq!(U256([0, 0, 0, 0]), U256::from_str("").unwrap()); assert_eq!(U256([0x1, 0, 0, 0]), U256::from_str("1").unwrap());