mirror of
https://github.com/UneBaguette/blake3.wasm.git
synced 2026-08-11 00:00:26 +02:00
feat: multi-target build + CI + publish workflow
This commit is contained in:
+81
@@ -62,4 +62,85 @@ impl Hasher {
|
||||
pub fn reset(&mut self) {
|
||||
self.0.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_hash_deterministic() {
|
||||
let a = hash(b"hello");
|
||||
let b = hash(b"hello");
|
||||
assert_eq!(a, b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hash_length() {
|
||||
assert_eq!(hash(b"hello").len(), 32);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hash_xof_length() {
|
||||
assert_eq!(hash_xof(b"hello", 64).len(), 64);
|
||||
assert_eq!(hash_xof(b"hello", 16).len(), 16);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_keyed_hash_valid() {
|
||||
let key = [0u8; 32];
|
||||
assert!(keyed_hash(b"hello", &key).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_derive_key() {
|
||||
let a = derive_key("ctx", b"material");
|
||||
let b = derive_key("ctx", b"material");
|
||||
assert_eq!(a, b);
|
||||
assert_eq!(a.len(), 32);
|
||||
|
||||
let c = derive_key("other", b"material");
|
||||
assert_ne!(a, c);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hasher_streaming() {
|
||||
let oneshot = hash(b"helloworld");
|
||||
let mut h = Hasher::new();
|
||||
h.update(b"hello");
|
||||
h.update(b"world");
|
||||
assert_eq!(h.finalize(), oneshot);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hasher_reset() {
|
||||
let mut h = Hasher::new();
|
||||
h.update(b"junk");
|
||||
h.reset();
|
||||
h.update(b"hello");
|
||||
assert_eq!(h.finalize(), hash(b"hello"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hasher_keyed() {
|
||||
let key = [1u8; 32];
|
||||
let h = Hasher::new_keyed(&key).unwrap();
|
||||
assert_ne!(h.finalize(), hash(b"").as_slice());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod wasm_tests {
|
||||
use super::*;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_keyed_hash_bad_key() {
|
||||
assert!(keyed_hash(b"hello", &[0u8; 16]).is_err());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_hasher_keyed_bad_key() {
|
||||
assert!(Hasher::new_keyed(&[0u8; 10]).is_err());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user