INNER CODE UNIT · JavaScript
sha256Hex
agent-sh/agentsys · lib/binary/index.js:254
function sha256Hex(buf) {
return crypto.createHash('sha256').update(buf).digest('hex');
}
/**
* Verify a downloaded buffer against an expected hex digest.
* Throws with a security-focused message on mismatch.
* @param {Buffer} buf
* @param {string} expectedHex
* @param {string} filename user-facing name for the error message
*/
function verifySha256(buf, expectedHex, filename) {
const expected = String(expectedHex || '').toLowerCase();
const actual = sha256Hex(buf);
if (expected !== actual) {
throw new Error(
'SHA-256 verification failed for ' + filename + ': ' +
'expected ' + expected + ', got ' + actual + '. ' +