// mdb-reader's browser environment, rewritten for this site: AES and the hashes // come from @noble/ciphers and @noble/hashes (MIT, synchronous, no Node // streams), in place of browserify-aes and create-hash, whose Buffer polyfill // differs from mdb-reader's and returned short pages for encrypted .accdb files. import { inflate as pakoInflate } from 'pako'; import { cbc, ecb, cfb } from '@noble/ciphers/aes.js'; import { sha1, md5 } from '@noble/hashes/legacy.js'; import { sha256, sha384, sha512 } from '@noble/hashes/sha2.js'; const HASHES = { sha1, sha256, sha384, sha512, md5 }; export function createHash(algorithm) { const fn = HASHES[String(algorithm).toLowerCase().replace(/-/g, '')]; if (!fn) throw new Error(`Unsupported hash ${algorithm}`); const h = fn.create(); return { update(data) { h.update(data); return this; }, digest() { return Buffer.from(h.digest()); }, }; } export function createDecipheriv(algorithm, key, iv) { const mode = String(algorithm).toLowerCase().split('-').pop(); const k = new Uint8Array(key); const make = mode === 'cbc' ? () => cbc(k, new Uint8Array(iv).subarray(0, 16), { disablePadding: true }) : mode === 'ecb' ? () => ecb(k, { disablePadding: true }) : mode === 'cfb' ? () => cfb(k, new Uint8Array(iv).subarray(0, 16)) : null; if (!make) throw new Error(`Unsupported cipher ${algorithm}`); return { setAutoPadding() { return this; }, update(data) { return Buffer.from(make().decrypt(new Uint8Array(data))); }, }; } export const environment = { inflate: (data) => Buffer.from(pakoInflate(data)), };