add calc_hash

This commit is contained in:
2020-04-20 00:34:51 +08:00
parent dbb46bc18a
commit ea6c70a305

View File

@@ -70,13 +70,14 @@ fn make_btc_address(public_key: &PublicKey) -> String {
}
fn calc_sha256(i: &[u8]) -> Vec<u8> {
let mut hasher = Sha256::default();
hasher.input(&i);
hasher.fixed_result().to_vec()
calc_hash(Sha256::default(), i)
}
fn calc_ripemd160(i: &[u8]) -> Vec<u8> {
let mut hasher = Ripemd160::default();
calc_hash(Ripemd160::default(), i)
}
fn calc_hash<T>(mut hasher: T, i: &[u8]) -> Vec<u8> where T: Input + FixedOutput {
hasher.input(&i);
hasher.fixed_result().to_vec()
}