fluent-hash

Crates.iofluent-hash
lib.rsfluent-hash
version0.2.3
sourcesrc
created_at2023-05-06 22:51:02.735154
updated_at2023-12-03 07:54:55.80269
descriptionA lightweight library which provides a fluent interface for generating SHA-1 and SHA-2 digests.
homepagehttps://github.com/web3-developer/fluent-hash#readme
repositoryhttps://github.com/web3-developer/fluent-hash
max_upload_size
id858784
size24,380
(bhartnett)

documentation

https://docs.rs/fluent-hash/

README

Fluent Hash

fluent-hash is a wrapper on top of the ring cryptography library which provides a fluent interface for generating SHA-1 and SHA-2 hashes.

It provides convenience methods for generating hashes from the following types:

  • &[u8]
  • Vec<u8>
  • &str
  • std::fs::File

It also supports formatting hashes as bytes or hexadecimal.

Supported Hash Algorithms

The following SHA-1 and SHA-2 algorithms are supported:

  • SHA-1
  • SHA-256
  • SHA-384
  • SHA-512
  • SHA-512_256

Documentation

See the documentation at: https://docs.rs/fluent-hash/

Examples

Import the fluent_hash types.

use fluent_hash::Hashing::Sha1;
use fluent_hash::Hashing::Sha256;
use fluent_hash::Hashing::Sha384;
use fluent_hash::Hashing::Sha512;
use fluent_hash::Hashing::Sha512_256;
use fluent_hash::Hashing;
use fluent_hash::HashContext;
use fluent_hash::Hash;

Hash a byte array.

let result: Hash = Sha256.hash(b"hello, world");

Hash a byte vector.

let result: Hash = Sha256.hash_vec(b"hello, world".to_vec());

Hash a string.

let result: Hash = Sha256.hash_str("hello, world");

Hash a file.

let result: Hash = Sha256.hash_file("file.txt")?;

Format the hash.

let bytes: &[u8] = result.as_bytes();
let bytes_vec: Vec<u8> = result.to_vec();
let hex: String = result.to_hex();

See the Web3 Developer blog post which shows more fluent-hash usage examples here: https://web3developer.io/introducing-fluent-hash/

License

fluent-hash is distributed under the Apache License version 2.0.

Disclaimer

THE SOFTWARE IS PROVIDED "AS IS" THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Commit count: 11

cargo fmt