xur_

> module

std::hash

cryptographic and non-cryptographic hashes

use std::hash; feature hash in the browser

std::hash provides common hash functions over bytes, such as a byte literal (b"hello") or a string's to_bytes(). MD5 and CRC-32 are not secure against deliberate collisions; use SHA-256 where that matters.

> functions

# crc32(data: bytes) -> i64

The CRC-32 (IEEE) checksum, as a non-negative integer.

# md5(data: bytes) -> str

MD5 digest as a lowercase hex string.

# sha256(data: bytes) -> str

SHA-256 digest as a lowercase hex string.

# sha256_bytes(data: bytes) -> bytes

SHA-256 digest as 32 raw bytes.

> examples

use std::hash;
use std::io;

fn main() {
    let data = "hello".to_bytes();
    io::println("sha256: {}", hash::sha256(data));
    io::println("md5:    {}", hash::md5(data));
    io::println("crc32:  {}", hash::crc32(data));
}