generate hash160 from sha256 as a separate method

This commit is contained in:
Jude Nelson
2019-02-07 15:32:13 -05:00
parent 3dfba809d3
commit e39ea808f5

View File

@@ -30,19 +30,23 @@ impl_array_hexstring_fmt!(Hash160);
impl_byte_array_newtype!(Hash160, u8, 20);
impl Hash160 {
pub fn from_sha256(sha256_hash: &[u8; 32]) -> Hash160 {
let mut rmd = Ripemd160::new();
let mut ret = [0u8; 20];
rmd.input(sha256_hash);
rmd.result(&mut ret);
Hash160(ret)
}
/// Create a hash by hashing some data
/// (borrwed from Andrew Poelstra)
#[allow(dead_code)]
pub fn from_data(data: &[u8]) -> Hash160 {
let mut tmp = [0; 32];
let mut ret = [0; 20];
let mut tmp = [0u8; 32];
let mut sha2 = Sha256::new();
let mut rmd = Ripemd160::new();
sha2.input(data);
sha2.result(&mut tmp);
rmd.input(&tmp);
rmd.result(&mut ret);
Hash160(ret)
Hash160::from_sha256(&tmp)
}
}