#sha-256 #vec-u8 #performs #curencies #purhapse #cryto

byte_sha

Performs SHA256 on a Vec<u8> and returns a Vec<u8> as the result. Useful for cryto curencies and purhapse other things.

2 stable releases

Uses old Rust 2015

1.0.1 Sep 19, 2016

#1525 in Cryptography

Download history 1/week @ 2024-01-08 9/week @ 2024-01-15 2/week @ 2024-01-29 23/week @ 2024-02-05 37/week @ 2024-02-12 66/week @ 2024-02-19 58/week @ 2024-02-26 66/week @ 2024-03-04 47/week @ 2024-03-11 30/week @ 2024-03-18

204 downloads per month

MIT license

12KB
218 lines

ByteSha

Purpose

ByteSha is a rust crate that can perform SHA256 on a Vec and return a Vec

Namespace

ByteSha houses all functions at the top level of the crate. There are only three public functions and all are under the byte_sha namespace.

let result: Vec<u8> = *sah256_of_message_as_u8_vec(&mut message);

Performing 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);

With any message in the form of Vec execute the function sha256_of_message_as_u8_vec with the mutable reference of a Vec as it's input. Notice you have to dereference because it returns a Box. This is to avoid unessisary copying.

Dependencies

~11KB