Merge pull request #8 from wagesj45/codex/change-cache-key-generation-to-use-sha256-hashing

Hash cache keys using SHA256
This commit is contained in:
Jordan Wages 2025-06-20 01:13:38 -05:00 committed by GitHub
commit 2c0628fc30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,6 +6,15 @@ var { NetUtil } = ChromeUtils.importESModule("resource://gre/modules/Net
var { MimeParser } = ChromeUtils.importESModule("resource:///modules/mimeParser.sys.mjs");
var { FileUtils } = ChromeUtils.importESModule("resource://gre/modules/FileUtils.sys.mjs");
function sha256Hex(str) {
const hasher = Cc["@mozilla.org/security/hash;1"].createInstance(Ci.nsICryptoHash);
hasher.init(Ci.nsICryptoHash.SHA256);
const data = new TextEncoder().encode(str);
hasher.update(data, data.length);
const binary = hasher.finish(false);
return Array.from(binary, c => ("0" + c.charCodeAt(0).toString(16)).slice(-2)).join("");
}
var EXPORTED_SYMBOLS = ["AIFilter", "ClassificationTerm"];
const SYSTEM_PREFIX = `You are an email-classification assistant.
@ -208,7 +217,7 @@ class ClassificationTerm extends CustomerTermBase {
op === Ci.nsMsgSearchOp.DoesntMatch ? "doesn't match" : `unknown (${op})`;
console.log(`[ai-filter][ExpressionSearchFilter] Matching message ${msgHdr.messageId} using op "${opName}" and value "${value}"`);
let key = msgHdr.messageId + "|" + op + "|" + value;
let key = [msgHdr.messageId, op, value].map(sha256Hex).join("|");
if (this.cache.has(key)) {
console.log(`[ai-filter][ExpressionSearchFilter] Cache hit for key: ${key}`);
return this.cache.get(key);