Removed Hash struct, cleaned the code. Renamed Wyrd to wyrd_ns.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use std::num;
|
||||
|
||||
/// Convert bytes array to HEX format
|
||||
pub fn to_hex(buf: &[u8]) -> String {
|
||||
@@ -8,6 +9,19 @@ pub fn to_hex(buf: &[u8]) -> String {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn from_hex(string: &str) -> Result<Vec<u8>, num::ParseIntError> {
|
||||
split_n(&string.trim()[..], 2)
|
||||
.iter()
|
||||
.map(|b| u8::from_str_radix(b, 16))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn split_n(s: &str, n: usize) -> Vec<&str> {
|
||||
(0..=(s.len() - n + 1) / 2)
|
||||
.map(|i| &s[2 * i..2 * i + n])
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// There is no default PartialEq implementation for arrays > 32 in size
|
||||
pub fn same_hash(left: &[u8], right: &[u8]) -> bool {
|
||||
for (x, y) in left.iter().zip(right) {
|
||||
|
||||
Reference in New Issue
Block a user