deno.land / std@0.224.0 / crypto / _wasm / src / fnv.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.const BASIS_32: u32 = 2166136261;const PRIME_32: u32 = 16777619;
const BASIS_64: u64 = 14695981039346656037;const PRIME_64: u64 = 1099511628211;
pub struct Fnv32 { state: u32,}
impl Fnv32 { pub fn new() -> Fnv32 { Fnv32 { state: BASIS_32 } }
pub fn update(&mut self, bytes: impl AsRef<[u8]>) { for byte in bytes.as_ref() { self.state = self.state.wrapping_mul(PRIME_32); self.state ^= u32::from(*byte); } }
pub fn digest(&self) -> Box<[u8]> { Box::new(self.state.to_be_bytes()) }}
pub struct Fnv32A { state: u32,}
impl Fnv32A { pub fn new() -> Fnv32A { Fnv32A { state: BASIS_32 } }
pub fn update(&mut self, bytes: impl AsRef<[u8]>) { for byte in bytes.as_ref() { self.state ^= u32::from(*byte); self.state = self.state.wrapping_mul(PRIME_32); } }
pub fn digest(&self) -> Box<[u8]> { Box::new(self.state.to_be_bytes()) }}
pub struct Fnv64 { state: u64,}
impl Fnv64 { pub fn new() -> Fnv64 { Fnv64 { state: BASIS_64 } }
pub fn update(&mut self, bytes: impl AsRef<[u8]>) { for byte in bytes.as_ref() { self.state = self.state.wrapping_mul(PRIME_64); self.state ^= u64::from(*byte); } }
pub fn digest(&self) -> Box<[u8]> { Box::new(self.state.to_be_bytes()) }}
pub struct Fnv64A { state: u64,}
impl Fnv64A { pub fn new() -> Fnv64A { Fnv64A { state: BASIS_64 } }
pub fn update(&mut self, bytes: impl AsRef<[u8]>) { for byte in bytes.as_ref() { self.state ^= u64::from(*byte); self.state = self.state.wrapping_mul(PRIME_64); } }
pub fn digest(&self) -> Box<[u8]> { Box::new(self.state.to_be_bytes()) }}
std

Version Info

Tagged at
4 months ago