Removed Hash struct, cleaned the code. Renamed Wyrd to wyrd_ns.

This commit is contained in:
Revertron
2019-12-02 16:33:19 +01:00
parent f46367c95d
commit b5e36da737
9 changed files with 115 additions and 268 deletions
+14
View File
@@ -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) {