From 70990c0e83fb35176b4508fdf43a9ca46ea9d129 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 1 Dec 2015 01:08:04 +0100 Subject: [PATCH] Update README.md --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index a7aa724..3664cb1 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,33 @@ and this to your crate root: ```rust extern crate tiny_keccak; ``` + +## Example + +```rust +extern crate tiny_keccak; +use tiny_keccak::Keccak; + +fn main() { + let mut sha3 = Keccak::new_sha3_256(); + let data: Vec = From::from("hello"); + let data2: Vec = From::from("world"); + + sha3.update(&data); + sha3.update(&[b' ']); + sha3.update(&data2); + + let mut res: [u8; 32] = [0; 32]; + sha3.finalize(&mut res); + + let expected = vec![ + 0x64, 0x4b, 0xcc, 0x7e, 0x56, 0x43, 0x73, 0x04, + 0x09, 0x99, 0xaa, 0xc8, 0x9e, 0x76, 0x22, 0xf3, + 0xca, 0x71, 0xfb, 0xa1, 0xd9, 0x72, 0xfd, 0x94, + 0xa3, 0x1c, 0x3b, 0xfb, 0xf2, 0x4e, 0x39, 0x38 + ]; + + let ref_ex: &[u8] = &expected; + assert_eq!(&res, ref_ex); +} +```