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

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

#1848 in Cryptography

Download history 20/week @ 2024-07-20 33/week @ 2024-07-27 35/week @ 2024-08-03 22/week @ 2024-08-10 42/week @ 2024-08-17 16/week @ 2024-08-24 38/week @ 2024-08-31 28/week @ 2024-09-07 16/week @ 2024-09-14 28/week @ 2024-09-21 21/week @ 2024-09-28 27/week @ 2024-10-05 36/week @ 2024-10-12 9/week @ 2024-10-19 1/week @ 2024-10-26 13/week @ 2024-11-02

66 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