oxedyne/fe2o3/fe2o3_hash/tests/hash.rs
895 bytes, 17 runs
created by r1870400018:363, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | use oxedyne_fe2o3_core::{ |
| 2 | prelude::*, |
| 3 | }; |
| 4 | use oxedyne_fe2o3_hash::{ |
| 5 | hash::HashScheme, |
| 6 | }; |
| 7 | use oxedyne_fe2o3_iop_hash::{ |
| 8 | api::{ |
| 9 | Hasher, |
| 10 | HashForm, |
| 11 | }, |
| 12 | }; |
| 13 | |
| 14 | pub fn test_hash(filter: &'static str) -> Outcome<()> { |
| 15 | |
| 16 | match filter { |
| 17 | "all" | "hash" => { |
| 18 | let hasher = HashScheme::new_sha3_256(); |
| 19 | req!(*res!(hasher.hash_length().required("SHA3-256 hash length")), 32); |
| 20 | let input = b"this is a test"; |
| 21 | let hash = hasher.hash(&[&input[..]], []); |
| 22 | msg!("hash = {:02x?}", hash); |
| 23 | match hash.as_hashform() { |
| 24 | HashForm::Bytes32(a32) => req!(a32.len(), 32), |
| 25 | other => return Err(err!( |
| 26 | "Expected SHA3-256 to produce a HashForm::Bytes32, found {:?}.", other; |
| 27 | Test, Mismatch)), |
| 28 | } |
| 29 | }, |
| 30 | _ => (), |
| 31 | } |
| 32 | |
| 33 | Ok(()) |
| 34 | } |