Skip to content

Commit

Permalink
remove rust-crypto, add bitcoin_hashes
Browse files Browse the repository at this point in the history
rust-crypto version has a warning about its dependency rustc-serialize

moreover bitcoin_hashes is more likely to already be in the tree of a bitcoin
related project
  • Loading branch information
RCasatta committed Apr 3, 2023
1 parent 8ffd96b commit d64dfd3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ name = "ots-info"
path = "src/bin/ots_info.rs"

[dependencies]
bitcoin_hashes = "0.12.0"
env_logger = "0.4"
log = "0.3"
rust-crypto = "0.2"

2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#![deny(unused_mut)]
#![deny(missing_docs)]

extern crate crypto;
extern crate bitcoin_hashes;
#[macro_use] extern crate log;

pub mod attestation;
Expand Down
23 changes: 4 additions & 19 deletions src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@
//! timestamps.
//!
use crypto::digest::Digest;
use crypto::sha1::Sha1;
use crypto::sha2::Sha256;
use crypto::ripemd160::Ripemd160;
use std::fmt;
use std::io::{Read, Write};

use bitcoin_hashes::{Hash, ripemd160, sha1, sha256};
use error::Error;
use hex::Hexed;
use ser;
Expand Down Expand Up @@ -100,25 +97,13 @@ impl Op {
pub fn execute(&self, input: &[u8]) -> Vec<u8> {
match *self {
Op::Sha1 => {
let mut ret = vec![0; 20];
let mut hasher = Sha1::new();
hasher.input(input);
hasher.result(&mut ret);
ret
sha1::Hash::hash(&input).to_byte_array().to_vec()
}
Op::Sha256 => {
let mut ret = vec![0; 32];
let mut hasher = Sha256::new();
hasher.input(input);
hasher.result(&mut ret);
ret
sha256::Hash::hash(&input).to_byte_array().to_vec()
}
Op::Ripemd160 => {
let mut ret = vec![0; 20];
let mut hasher = Ripemd160::new();
hasher.input(input);
hasher.result(&mut ret);
ret
ripemd160::Hash::hash(&input).to_byte_array().to_vec()
}
Op::Hexlify => {
format!("{}", Hexed(input)).into_bytes()
Expand Down

0 comments on commit d64dfd3

Please sign in to comment.