Commit e365d543 authored by Tom Almeida's avatar Tom Almeida
Browse files

Merge branch 'impl-write-trait' into 'master'

impl Write trait for the streaming SeaHasher

See merge request !4
parents a39dd378 90751ff1
Pipeline #8137 passed with stage
in 1 minute and 5 seconds
......@@ -21,4 +21,4 @@ image: "rust:latest"
test:cargo:
script:
- rustc --version && cargo --version # Print version info for debugging
- cargo test --all --verbose
- cargo test --all --verbose --all-features
......@@ -6,8 +6,12 @@ description = "A blazingly fast, portable hash function with proven statistical
repository = "https://gitlab.redox-os.org/redox-os/seahash"
documentation = "https://docs.rs/seahash"
license = "MIT"
keywords = ["hash", "hashing", "checksum", "checsumming", "portable"]
keywords = ["hash", "hashing", "checksum", "checksumming", "portable"]
exclude = ["target", "Cargo.lock"]
[dev-dependencies]
quickcheck = "0.9.2"
[features]
default = []
use_std = []
//! A highly optimized version of SeaHash.
use core::slice;
use std::slice;
use helper;
......
use crate::SeaHasher;
use std::hash::Hasher;
use std::io;
impl io::Write for SeaHasher {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
Hasher::write(self, buf);
Ok(buf.len())
}
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hash_write_trait() {
let reader: &[u8] = &[0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00];
let mut hasher = SeaHasher::new();
// io::copy consumes the mutable reader -> cloning the buffer
let _ = io::copy(&mut reader.clone(), &mut hasher).unwrap();
let hash = hasher.finish();
let control = crate::hash(&reader);
assert_eq!(control, hash);
}
}
......@@ -151,8 +151,10 @@
//! Joshua Landau suggested using the [PCG family of diffusions](http://www.pcg-random.org/),
//! created by Melissa E. O'Neill. Sokolov Yura spotted multiple bugs in SeaHash.
#![no_std]
#![warn(missing_docs)]
#![cfg_attr(all(not(test), not(feature = "use_std")), no_std)]
#[cfg(all(not(test), not(feature = "use_std")))]
extern crate core as std;
pub use buffer::{hash, hash_seeded, State};
pub use stream::SeaHasher;
......@@ -161,3 +163,6 @@ pub mod reference;
mod buffer;
mod helper;
mod stream;
#[cfg(feature = "use_std")]
mod impl_std;
use core::hash::Hasher;
use core::slice;
use std::hash::Hasher;
use std::slice;
use helper;
......@@ -213,7 +213,7 @@ impl Hasher for SeaHasher {
mod tests {
use super::*;
use crate::hash_seeded;
use core::hash::Hasher;
use std::hash::Hasher;
#[test]
fn chunked_equiv() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment