2个稳定版本
使用旧的Rust 2015
1.0.1 | 2016年9月19日 |
---|
在加密学中排名1637
每月下载量153
12KB
218 行
ByteSha
目的
ByteSha是一个Rust crate,可以在Vec上执行SHA256运算并返回一个Vec
命名空间
ByteSha将所有函数放在crate的最高级别。只有三个公开函数,并且都在byte_sha命名空间下。
let result: Vec<u8> = *sah256_of_message_as_u8_vec(&mut message);
执行SHA256
extern crate byte_sha;
let mut message: Vec<u8> = vec![77, 117, 32, 83, 104, 97, 108, 108, 32, 82, 105, 115, 101, 33, 32, 65, 110, 100, 32, 119, 105, 116, 104, 32, 105, 116, 32, 115, 111, 32, 115, 104, 97, 108, 108, 32, 116, 111, 111, 44, 32, 115, 119, 101, 101, 116, 32, 108, 105, 98, 101, 114, 116, 121, 32, 101, 99, 104, 111, 32, 116, 104, 114, 111, 117, 103, 104, 32, 116, 104, 101, 32, 99, 104, 97, 109, 98, 101, 114, 32, 104, 97, 108, 108, 115, 44, 32, 98, 111, 116, 104, 32, 104, 105, 103, 104, 32, 97, 110, 100, 32, 108, 111, 119, 44, 32, 97, 110, 100, 32, 98, 105, 103, 32, 97, 110, 100, 32, 115, 109, 97, 108, 108, 46];
let result: Vec<u8> = *byte_sha::sha256_of_message_as_u8_vec(&mut message);
let expected: Vec<u8> = vec![61, 186, 202, 92, 52, 61, 155, 63, 150, 130, 106, 106, 206, 202, 234, 155, 196, 116, 142, 225, 90, 173, 181, 137, 94, 173, 27, 211, 63, 132, 41, 112];
assert_eq!(result, expected);
使用任何形式为Vec的消息,通过将Vec的不可变引用作为输入执行sha256_of_message_as_u8_vec函数。注意您需要解引用,因为它返回一个Box。这是为了避免不必要的复制。
依赖项
~11KB