import { createHash } from "node:crypto";

export function sha256(data) {
  return createHash("sha256").update(data).digest("hex");
}

export function checksumLine(digest, fileName) {
  if (!/^[a-f0-9]{64}$/u.test(digest) || /[\/\r\n]/u.test(fileName)) {
    throw new Error("Invalid checksum output");
  }
  return `${digest}  ${fileName}\n`;
}
