compute_digest

Function compute_digest 

Source
pub fn compute_digest(
    content: &[u8],
    hash: DigestHash,
    encoding: DigestEncoding,
) -> String
Expand description

Computes a cryptographic digest of content.

This is a low-level function for computing digests. For descriptor digests, prefer using the Descriptor::digest method which knows the correct content range to hash.

§Arguments

  • content - The content to hash
  • hash - The hash algorithm to use
  • encoding - The output encoding format

§Returns

The digest as a string in the specified encoding.

§Example

use stem_rs::descriptor::{compute_digest, DigestHash, DigestEncoding};

let content = b"test content";

// SHA-1 in hex
let sha1_hex = compute_digest(content, DigestHash::Sha1, DigestEncoding::Hex);
assert_eq!(sha1_hex.len(), 40);

// SHA-256 in base64
let sha256_b64 = compute_digest(content, DigestHash::Sha256, DigestEncoding::Base64);