forked from hyperledger-archives/ursa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash.rs
38 lines (31 loc) · 1.03 KB
/
hash.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
use bn::BigNumber;
use errors::prelude::*;
pub fn get_hash_as_int(nums: &[Vec<u8>]) -> UrsaCryptoResult<BigNumber> {
trace!("Helpers::get_hash_as_int: >>> nums: {:?}", nums);
let hash = BigNumber::from_bytes(&BigNumber::hash_array(&nums)?);
trace!("Helpers::get_hash_as_int: <<< hash: {:?}", hash);
hash
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn get_hash_as_int_works() {
let mut nums = vec![
BigNumber::from_hex("ff9d2eedfee9cffd9ef6dbffedff3fcbef4caecb9bffe79bfa94d3fdf6abfbff")
.unwrap()
.to_bytes()
.unwrap(),
BigNumber::from_hex("ff9d2eedfee9cffd9ef6dbffedff3fcbef4caecb9bffe79bfa9168615ccbc546")
.unwrap()
.to_bytes()
.unwrap(),
];
let res = get_hash_as_int(&mut nums);
assert!(res.is_ok());
assert_eq!(
"2C2566C22E04AB3F18B3BA693823175002F10F400811363D26BBB33633AC8BAD",
res.unwrap().to_hex().unwrap()
);
}
}