cleaning up hash reexports

This commit is contained in:
debris
2016-08-03 18:05:17 +02:00
parent 573e775ef9
commit e8c451ac82
42 changed files with 102 additions and 148 deletions

View File

@@ -28,7 +28,7 @@ extern crate ethcore_util;
extern crate rand;
use test::{Bencher, black_box};
use ethcore_util::numbers::*;
use ethcore_util::U256;
#[bench]
fn u256_add(b: &mut Bencher) {

View File

@@ -28,7 +28,7 @@ extern crate ethcore_util;
use test::Bencher;
use std::str::FromStr;
use ethcore_util::rlp::*;
use ethcore_util::numbers::U256;
use ethcore_util::U256;
#[bench]
fn bench_stream_u64_value(b: &mut Bencher) {

View File

@@ -36,21 +36,19 @@ lazy_static! {
static ref SECP256K1: Secp256k1 = Secp256k1::new();
}
impl Signature {
/// Create a new signature from the R, S and V componenets.
pub fn from_rsv(r: &H256, s: &H256, v: u8) -> Signature {
let mut ret: Signature = Signature::new();
(&mut ret[0..32]).copy_from_slice(r);
(&mut ret[32..64]).copy_from_slice(s);
/// Create a new signature from the R, S and V componenets.
pub fn signature_from_rsv(r: &H256, s: &H256, v: u8) -> Signature {
let mut ret: Signature = Signature::new();
(&mut ret[0..32]).copy_from_slice(r);
(&mut ret[32..64]).copy_from_slice(s);
ret[64] = v;
ret
}
ret[64] = v;
ret
}
/// Convert transaction to R, S and V components.
pub fn to_rsv(&self) -> (U256, U256, u8) {
(U256::from(&self.as_slice()[0..32]), U256::from(&self.as_slice()[32..64]), self[64])
}
/// Convert transaction to R, S and V components.
pub fn signature_to_rsv(s: &Signature) -> (U256, U256, u8) {
(U256::from(&s.as_slice()[0..32]), U256::from(&s.as_slice()[32..64]), s[64])
}
#[derive(Debug)]
@@ -206,10 +204,10 @@ pub mod ec {
signature.clone_from_slice(&data);
signature[64] = rec_id.to_i32() as u8;
let (_, s, v) = signature.to_rsv();
let (_, s, v) = signature_to_rsv(&signature);
let secp256k1n = U256::from_str("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141").unwrap();
if !is_low_s(&s) {
signature = super::Signature::from_rsv(&H256::from_slice(&signature[0..32]), &H256::from(secp256k1n - s), v ^ 1);
signature = super::signature_from_rsv(&H256::from_slice(&signature[0..32]), &H256::from(secp256k1n - s), v ^ 1);
}
Ok(signature)
}

View File

@@ -1,21 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Calculates heapsize of util types.
use hash::*;

View File

@@ -139,7 +139,6 @@ pub mod triehash;
pub mod trie;
pub mod nibbleslice;
pub mod nibblevec;
mod heapsizeof;
pub mod semantic_version;
pub mod io;
pub mod network;
@@ -171,6 +170,7 @@ pub use timer::*;
#[cfg(test)]
mod tests {
use std::str::FromStr;
use {U256, H256, Uint};
#[test]
fn u256_multi_muls() {