Skip to content

Commit

Permalink
Merge branch 'master' into ao-prepare-for-releases
Browse files Browse the repository at this point in the history
* master:
  Remove deprecated FromStr/TryFrom impls for Secret (#495)
  primitive-types: address nits of #480 (#485)
  • Loading branch information
ordian committed Jan 4, 2021
2 parents 4ea278d + f98a93d commit eeff88a
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 42 deletions.
4 changes: 1 addition & 3 deletions ethereum-types/src/lib.rs
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ethereum-types/src/uint.rs
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions parity-crypto/CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog].
- 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)
- Updated dependencies. [#483](https://github.com/paritytech/parity-common/pull/483)
- 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)
Expand Down
31 changes: 1 addition & 30 deletions parity-crypto/src/publickey/secret_key.rs
Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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<Self, Self::Err> {
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 {
Expand All @@ -239,27 +231,6 @@ impl From<H256> 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<Self, Error> {
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<Self, Error> {
if b.len() != SECP256K1_SECRET_KEY_SIZE {
return Err(Error::InvalidSecretKey);
}
Ok(Self { inner: Box::new(H256::from_slice(b)) })
}
}

impl From<key::SecretKey> for Secret {
#[inline(always)]
fn from(key: key::SecretKey) -> Self {
Expand Down
4 changes: 0 additions & 4 deletions primitive-types/impls/num-traits/Cargo.toml
Expand Up @@ -10,7 +10,3 @@ edition = "2018"
[dependencies]
num-traits = { version = "0.2", default-features = false }
uint = { version = "0.9.0", path = "../../../uint", default-features = false }

[features]
default = ["std"]
std = ["num-traits/std", "uint/std"]
7 changes: 4 additions & 3 deletions primitive-types/impls/num-traits/src/lib.rs
Expand Up @@ -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]
Expand All @@ -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, Self::FromStrRadixErr> {
Self::from_str_radix(txt, radix)
Expand Down
1 change: 0 additions & 1 deletion primitive-types/src/lib.rs
Expand Up @@ -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)]
Expand Down

0 comments on commit eeff88a

Please sign in to comment.