Files
metal2vulkan/crates/metal2vulkan-validation/src/hash.rs
T
Anees Iqbal c1e9b6b2b9 Name a line pipeline's record as its triangle sibling's, so its making converts nothing again
The steps this packet landed as, in order:
- Read no data back from a making the driver found in its record, which MoltenVK rewrote each time
- Hash with sha2 0.11, which runs SHA-256 on ARMv8's SHA2 instructions

Content: the tree of `development` at 457e874745, unchanged.
2026-10-26 13:19:03 +02:00

38 lines
1.1 KiB
Rust

use sha2::{Digest, Sha256};
use std::fs::File;
use std::io::Read;
use std::path::Path;
pub fn sha256_bytes(bytes: &[u8]) -> String {
let mut hasher = Sha256::new();
hasher.update(bytes);
hex_encode(hasher.finalize())
}
pub fn sha256_file(path: &Path) -> std::io::Result<String> {
let mut file = File::open(path)?;
let mut hasher = Sha256::new();
// sha2 0.11's hashers implement no `io::Write`: the file in chunks.
let mut chunk = vec![0u8; 1 << 16];
loop {
match file.read(&mut chunk) {
Ok(0) => break,
Ok(read) => hasher.update(&chunk[..read]),
Err(error) if error.kind() == std::io::ErrorKind::Interrupted => {}
Err(error) => return Err(error),
}
}
Ok(hex_encode(hasher.finalize()))
}
pub fn hex_encode(bytes: impl AsRef<[u8]>) -> String {
const HEX: &[u8; 16] = b"0123456789abcdef";
let bytes = bytes.as_ref();
let mut out = String::with_capacity(bytes.len() * 2);
for &byte in bytes {
out.push(HEX[(byte >> 4) as usize] as char);
out.push(HEX[(byte & 0xf) as usize] as char);
}
out
}