22 lines
637 B
Rust
22 lines
637 B
Rust
use hmac::{Hmac, Mac};
|
|
use sha1::Sha1;
|
|
|
|
const SHA1_DIGEST_SIZE: usize = 20;
|
|
|
|
type HmacSha1 = Hmac<Sha1>;
|
|
|
|
fn main() {
|
|
let args = std::env::args().into_iter().collect::<Vec<String>>();
|
|
println!("Args: {:?}", args);
|
|
let key = hex::decode(&args[1]).expect("Key hex parse failed");
|
|
let data = hex::decode(&args[2]).expect("Data hex parse failed");
|
|
let mut hmac_sha1 = HmacSha1::new_from_slice(&key).unwrap();
|
|
hmac_sha1.update(&data);
|
|
let result = hmac_sha1.finalize();
|
|
|
|
let mut code = [0; SHA1_DIGEST_SIZE];
|
|
code.copy_from_slice(result.into_bytes().as_slice());
|
|
|
|
println!("{}", hex::encode(&code));
|
|
}
|