Skip to main content

digest_of

Function digest_of 

Source
pub fn digest_of(bytes: &[u8]) -> String
Expand description

sha256:<hex> of some bytes, the one spelling used in the ledger.

The algorithm is named in the value rather than assumed by the reader, so a ledger written before a change of algorithm stays readable and says which one produced it.

use majordomus_cli::evidence::digest_of;

let d = digest_of(b"echo ok\n");
assert!(d.starts_with("sha256:"), "{d}");
assert_eq!(d.len(), "sha256:".len() + 64);
assert_eq!(d, digest_of(b"echo ok\n"), "the same bytes hash the same");
assert_ne!(d, digest_of(b"echo ok"), "a trailing newline is a different file");