UNPKG

@hazae41/kdbx

Version:

Rust-like KeePass (KDBX 4) file format for TypeScript

146 lines (145 loc) 5.97 kB
// deno-lint-ignore-file no-namespace import { BytesAsUuid, StringAsUuid } from "../../../../../libs/uuid/mod.js"; export var Cipher; (function (Cipher) { let Aes128Cbc; (function (Aes128Cbc) { Aes128Cbc.uuid = "61ab05a1-9464-41c3-8d74-3a563df8dd35"; function cloneOrThrow() { return Aes128Cbc; } Aes128Cbc.cloneOrThrow = cloneOrThrow; function sizeOrThrow() { return 16; } Aes128Cbc.sizeOrThrow = sizeOrThrow; function writeOrThrow(cursor) { cursor.writeOrThrow(BytesAsUuid.from(Aes128Cbc.uuid)); } Aes128Cbc.writeOrThrow = writeOrThrow; let IV; (function (IV) { IV.length = 16; })(IV = Aes128Cbc.IV || (Aes128Cbc.IV = {})); async function encryptOrThrow(key, iv, data) { const encrypter = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["encrypt"]); const encrypted = new Uint8Array(await crypto.subtle.encrypt({ name: "AES-CBC", iv }, encrypter, data)); return encrypted; } Aes128Cbc.encryptOrThrow = encryptOrThrow; async function decryptOrThrow(key, iv, data) { const decrypter = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["decrypt"]); const decrypted = new Uint8Array(await crypto.subtle.decrypt({ name: "AES-CBC", iv }, decrypter, data)); return decrypted; } Aes128Cbc.decryptOrThrow = decryptOrThrow; })(Aes128Cbc = Cipher.Aes128Cbc || (Cipher.Aes128Cbc = {})); let Aes256Cbc; (function (Aes256Cbc) { Aes256Cbc.uuid = "31c1f2e6-bf71-4350-be58-05216afc5aff"; function cloneOrThrow() { return Aes256Cbc; } Aes256Cbc.cloneOrThrow = cloneOrThrow; function sizeOrThrow() { return 16; } Aes256Cbc.sizeOrThrow = sizeOrThrow; function writeOrThrow(cursor) { cursor.writeOrThrow(BytesAsUuid.from(Aes256Cbc.uuid)); } Aes256Cbc.writeOrThrow = writeOrThrow; let IV; (function (IV) { IV.length = 16; })(IV = Aes256Cbc.IV || (Aes256Cbc.IV = {})); async function encryptOrThrow(key, iv, data) { const encrypter = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["encrypt"]); const encrypted = new Uint8Array(await crypto.subtle.encrypt({ name: "AES-CBC", iv }, encrypter, data)); return encrypted; } Aes256Cbc.encryptOrThrow = encryptOrThrow; async function decryptOrThrow(key, iv, data) { const decrypter = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["decrypt"]); const decrypted = new Uint8Array(await crypto.subtle.decrypt({ name: "AES-CBC", iv }, decrypter, data)); return decrypted; } Aes256Cbc.decryptOrThrow = decryptOrThrow; })(Aes256Cbc = Cipher.Aes256Cbc || (Cipher.Aes256Cbc = {})); let TwoFishCbc; (function (TwoFishCbc) { TwoFishCbc.uuid = "ad68f29f-576f-4bb9-a36a-d47af965346c"; function cloneOrThrow() { return TwoFishCbc; } TwoFishCbc.cloneOrThrow = cloneOrThrow; function sizeOrThrow() { return 16; } TwoFishCbc.sizeOrThrow = sizeOrThrow; function writeOrThrow(cursor) { cursor.writeOrThrow(BytesAsUuid.from(TwoFishCbc.uuid)); } TwoFishCbc.writeOrThrow = writeOrThrow; let IV; (function (IV) { IV.length = 16; })(IV = TwoFishCbc.IV || (TwoFishCbc.IV = {})); // deno-lint-ignore require-await async function encryptOrThrow(key, iv, data) { throw new Error("TwoFishCbc encryption is not implemented"); } TwoFishCbc.encryptOrThrow = encryptOrThrow; // deno-lint-ignore require-await async function decryptOrThrow(key, iv, data) { throw new Error("TwoFishCbc decryption is not implemented"); } TwoFishCbc.decryptOrThrow = decryptOrThrow; })(TwoFishCbc = Cipher.TwoFishCbc || (Cipher.TwoFishCbc = {})); let ChaCha20; (function (ChaCha20) { ChaCha20.uuid = "d6038a2b-8b6f-4cb5-a524-339a31dbb59a"; function cloneOrThrow() { return ChaCha20; } ChaCha20.cloneOrThrow = cloneOrThrow; function sizeOrThrow() { return 16; } ChaCha20.sizeOrThrow = sizeOrThrow; function writeOrThrow(cursor) { cursor.writeOrThrow(BytesAsUuid.from(ChaCha20.uuid)); } ChaCha20.writeOrThrow = writeOrThrow; let IV; (function (IV) { IV.length = 12; })(IV = ChaCha20.IV || (ChaCha20.IV = {})); // deno-lint-ignore require-await async function encryptOrThrow(key, iv, data) { throw new Error("ChaCha20 encryption is not implemented"); } ChaCha20.encryptOrThrow = encryptOrThrow; // deno-lint-ignore require-await async function decryptOrThrow(key, iv, data) { throw new Error("ChaCha20 decryption is not implemented"); } ChaCha20.decryptOrThrow = decryptOrThrow; })(ChaCha20 = Cipher.ChaCha20 || (Cipher.ChaCha20 = {})); })(Cipher || (Cipher = {})); (function (Cipher) { function readOrThrow(cursor) { const bytes = cursor.readOrThrow(16); const uuid = StringAsUuid.from(bytes); if (uuid === Cipher.Aes256Cbc.uuid) return Cipher.Aes256Cbc; if (uuid === Cipher.Aes128Cbc.uuid) return Cipher.Aes128Cbc; if (uuid === Cipher.TwoFishCbc.uuid) return Cipher.TwoFishCbc; if (uuid === Cipher.ChaCha20.uuid) return Cipher.ChaCha20; throw new Error(); } Cipher.readOrThrow = readOrThrow; })(Cipher || (Cipher = {}));