#hash #from-str #arc #si-crypto-hashes

si-crypto-hashes

This crate provides a reusable functionality for working with typical cryptographic hashes

1 unstable release

Uses new Rust 2024

new 0.1.0 May 16, 2025

#2118 in Cryptography

MIT/Apache

13KB
269 lines

Silitics' Rust Libraries

This repository contains Rust crates for internal use within Silitics. While the crates are open-source and you are free to use them for whatever purpose you see, we will not accept any contributions other than bug fixes.


lib.rs:

This crate provides a reusable functionality for working with typical cryptographic hashes.

#
let expected = "sha256_dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f";

// Parse the string representation of the expected hash.
let digest = HashDigest::<Arc<[u8]>>::from_str(expected).unwrap();
assert_eq!(digest.algorithm(), HashAlgorithm::Sha256);
assert_eq!(digest.to_string(), expected);

// Compute a digest.
let mut hasher = digest.algorithm().hasher();
hasher.update(b"Hello, World!");
assert_eq!(hasher.finalize(), digest);

For parsing, the string representation is expected to be in the format <algorithm>_<digest> or <algorithm>:<digest>.

The algorithm must be one of the following:

  • sha256
  • sha512_256 or sha512-256
  • sha512

Note that the underscore representation is preferred as it can be selected by double clicking in most applications.

In the future, we may add additional hash algorithms.

Dependencies

~0.7–1MB
~25K SLoC