pub struct Blake2bSum { /* private fields */ }
Expand description
§Blake2b File Hash Constructor
This is the official constructor used to call the new() function with the parameter of the intended digest size.
§Example
use b2sum_rust::Blake2bSum;
fn main() {
// Creates a new File Instance
let context = Blake2bSum::new(64);
// Outputs a Hexadecimal String
let hash = context.read("example_file.txt");
// Converts the hexadecimal string to a vector of bytes
let _bytes = Blake2bSum::as_bytes(&hash);
// Prints The Hexadecimal Representation
println!("Hash: {}",hash);
// Asserts That These Are Equal
assert_eq!(hash,"33B20D15383F97EB46D4FA69442596170CCA01008963A7D0E47210C33AEEF991C78323850C012550C227954A40B3D7AD612568ABC73DB9233FAB9EA4F002B0CB");
}
All outputs are in UPPER Hexadecimal and between 1 and 64 bytes.
Implementations§
Source§impl Blake2bSum
impl Blake2bSum
Sourcepub fn new(digest: usize) -> Self
pub fn new(digest: usize) -> Self
Examples found in repository?
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
fn main(){
// Creates a new File Instance
let context = Blake2bSum::new(64);
// Outputs a Hexadecimal String
let hash = context.read("example_file.txt");
// Converts the hexadecimal string to a vector of bytes
let _bytes = Blake2bSum::as_bytes(&hash);
// Prints The Hexadecimal Representation
println!("Hash: {}",hash);
// Asserts That These Are Equal
assert_eq!(hash,"33B20D15383F97EB46D4FA69442596170CCA01008963A7D0E47210C33AEEF991C78323850C012550C227954A40B3D7AD612568ABC73DB9233FAB9EA4F002B0CB");
}
Sourcepub fn read<T: AsRef<Path>>(&self, path: T) -> String
pub fn read<T: AsRef<Path>>(&self, path: T) -> String
§Hash File
This is a function that hashes a file using Blake2b and returns the Hexadecimal Representation of it as a String. It takes as input any reference to Path.
It should be noted that changes to the file during hashing, such as truncating the file may cause problems.
§About Filebuffer
Filebuffer can map files into memory. This is often faster than using the primitives in std::io, and also more convenient. Furthermore this crate offers prefetching and checking whether file data is resident in physical memory (so access will not incur a page fault). This enables non-blocking file reading.
Examples found in repository?
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
fn main(){
// Creates a new File Instance
let context = Blake2bSum::new(64);
// Outputs a Hexadecimal String
let hash = context.read("example_file.txt");
// Converts the hexadecimal string to a vector of bytes
let _bytes = Blake2bSum::as_bytes(&hash);
// Prints The Hexadecimal Representation
println!("Hash: {}",hash);
// Asserts That These Are Equal
assert_eq!(hash,"33B20D15383F97EB46D4FA69442596170CCA01008963A7D0E47210C33AEEF991C78323850C012550C227954A40B3D7AD612568ABC73DB9233FAB9EA4F002B0CB");
}
Sourcepub fn read_with_key<T: AsRef<Path>>(&self, path: T, key: &[u8]) -> String
pub fn read_with_key<T: AsRef<Path>>(&self, path: T, key: &[u8]) -> String
§Hash File (Using Key)
This is a function that hashes a file (using a key) with Blake2b and then returns the Hexadecimal Representation of it as a String. It takes as input any reference to Path.
Sourcepub fn read_using_fs<T: AsRef<Path>>(&self, path: T) -> String
👎Deprecated: Please use the read()
function instead which uses Filebuffer. This function uses the standard library.
pub fn read_using_fs<T: AsRef<Path>>(&self, path: T) -> String
read()
function instead which uses Filebuffer. This function uses the standard library.§Hash File (using standard library)
Note: read()
or read_with_key()
should be used as opposed to this function.
This is a function that hashes a file using Blake2b and returns the Hexadecimal Representation of it as a String. It takes as input any reference to Path.
This does not use filebuffer
and instead uses the standard library. Filebuffer is much faster.
Sourcepub fn read_str<T: AsRef<str>>(&self, string: T) -> String
pub fn read_str<T: AsRef<str>>(&self, string: T) -> String
§Read String
This function will allow you to take a String
or str
, convert it to bytes, then hash it.
Sourcepub fn read_bytes(&self, bytes: &[u8]) -> String
pub fn read_bytes(&self, bytes: &[u8]) -> String
§Read Bytes
This function will allow you to read bytes and then hash the bytes given the digest size.
Sourcepub fn as_bytes(s: &str) -> Vec<u8>
pub fn as_bytes(s: &str) -> Vec<u8>
§as_bytes()
as_bytes()
converts from a Hexadecimal String to a Vector of Bytes
Examples found in repository?
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
fn main(){
// Creates a new File Instance
let context = Blake2bSum::new(64);
// Outputs a Hexadecimal String
let hash = context.read("example_file.txt");
// Converts the hexadecimal string to a vector of bytes
let _bytes = Blake2bSum::as_bytes(&hash);
// Prints The Hexadecimal Representation
println!("Hash: {}",hash);
// Asserts That These Are Equal
assert_eq!(hash,"33B20D15383F97EB46D4FA69442596170CCA01008963A7D0E47210C33AEEF991C78323850C012550C227954A40B3D7AD612568ABC73DB9233FAB9EA4F002B0CB");
}
Sourcepub fn return_digest_size(&self) -> usize
pub fn return_digest_size(&self) -> usize
§Return Digest Size
This method will return the provided digest size that the struct contains. It should be between 1 and 64 of type usize
.