Merge branch 'master' into gav

This commit is contained in:
Gav Wood
2016-01-18 16:20:35 +01:00
21 changed files with 380 additions and 145 deletions

View File

@@ -5,10 +5,6 @@ license = "GPL-3.0"
name = "ethcore-util"
version = "0.1.0"
authors = ["Ethcore <admin@ethcore.io>"]
build = "build.rs"
[build-dependencies]
gcc = "0.3"
[dependencies]
log = "0.3"
@@ -27,6 +23,7 @@ elastic-array = "0.4"
heapsize = "0.2"
itertools = "0.4"
slab = { git = "https://github.com/arkpar/slab.git" }
sha3 = { path = "sha3" }
[dev-dependencies]
json-tests = { path = "json-tests" }

11
util/sha3/Cargo.toml Normal file
View File

@@ -0,0 +1,11 @@
[package]
description = "Rust bindings for tinykeccak C library"
homepage = "http://ethcore.io"
license = "GPL-3.0"
name = "sha3"
version = "0.1.0"
authors = ["Ethcore <admin@ethcore.io>"]
build = "build.rs"
[build-dependencies]
gcc = "0.3"

4
util/sha3/src/lib.rs Normal file
View File

@@ -0,0 +1,4 @@
extern {
pub fn sha3_256(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) -> i32;
pub fn sha3_512(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) -> i32;
}

View File

@@ -151,14 +151,22 @@ impl<Message> Handler for IoManager<Message> where Message: Send + 'static {
/// Allows sending messages into the event loop. All the IO handlers will get the message
/// in the `message` callback.
pub struct IoChannel<Message> where Message: Send {
channel: Sender<IoMessage<Message>>
channel: Option<Sender<IoMessage<Message>>>
}
impl<Message> IoChannel<Message> where Message: Send {
pub fn send(&mut self, message: Message) -> Result<(), IoError> {
try!(self.channel.send(IoMessage::UserMessage(message)));
/// Send a msessage through the channel
pub fn send(&self, message: Message) -> Result<(), IoError> {
if let Some(ref channel) = self.channel {
try!(channel.send(IoMessage::UserMessage(message)));
}
Ok(())
}
/// Create a new channel to connected to event loop.
pub fn disconnected() -> IoChannel<Message> {
IoChannel { channel: None }
}
}
/// General IO Service. Starts an event loop and dispatches IO requests.
@@ -198,7 +206,7 @@ impl<Message> IoService<Message> where Message: Send + 'static {
/// Create a new message channel
pub fn channel(&mut self) -> IoChannel<Message> {
IoChannel { channel: self.host_channel.clone() }
IoChannel { channel: Some(self.host_channel.clone()) }
}
}

View File

@@ -1,14 +1,13 @@
//! Wrapper around tiny-keccak crate.
extern crate sha3 as sha3_ext;
use std::mem::uninitialized;
use bytes::{BytesConvertable, Populatable};
use hash::{H256, FixedHash};
use self::sha3_ext::*;
pub const SHA3_EMPTY: H256 = H256( [0xc5, 0xd2, 0x46, 0x01, 0x86, 0xf7, 0x23, 0x3c, 0x92, 0x7e, 0x7d, 0xb2, 0xdc, 0xc7, 0x03, 0xc0, 0xe5, 0x00, 0xb6, 0x53, 0xca, 0x82, 0x27, 0x3b, 0x7b, 0xfa, 0xd8, 0x04, 0x5d, 0x85, 0xa4, 0x70] );
extern {
fn sha3_256(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) -> i32;
}
/// Types implementing this trait are sha3able.
///