{"version":3,"file":"ecb.cjs","sources":["../src/ecb.ts"],"sourcesContent":["import { assertBlockMultiple as assertCoreBlockMultiple, type BlockCipher, type ModeComponent, type PresetComponent, type Transform } from '@jscrypto/core';\n\nexport const ecb: ModeComponent<'ECB'> = {\n  kind: 'mode',\n  name: 'ECB',\n  requiresPadding: true,\n  getIvSize: () => 0,\n  createEncryptor({ cipher, options }) {\n    return createEcbEncryptor(cipher, getMutableInput(options));\n  },\n  createDecryptor({ cipher, options }) {\n    return createEcbDecryptor(cipher, getMutableInput(options));\n  },\n};\n\nexport const ecbPreset: PresetComponent<'ecb'> = {\n  kind: 'preset',\n  name: 'ecb',\n  components() {\n    return [ecb];\n  },\n};\n\nfunction createEcbEncryptor(cipher: BlockCipher, mutableInput: boolean): Transform {\n  return {\n    process(input) {\n      assertBlockMultiple(cipher.blockSize, input);\n      const output = mutableInput ? input : new Uint8Array(input.length);\n      return cipher.encrypt(input, output);\n    },\n\n    finalize(input = new Uint8Array(0)) {\n      return input.length === 0 ? new Uint8Array(0) : this.process(input);\n    },\n  };\n}\n\nfunction createEcbDecryptor(cipher: BlockCipher, mutableInput: boolean): Transform {\n  return {\n    process(input) {\n      assertBlockMultiple(cipher.blockSize, input);\n      const output = mutableInput ? input : new Uint8Array(input.length);\n      return cipher.decrypt(input, output);\n    },\n\n    finalize(input = new Uint8Array(0)) {\n      return input.length === 0 ? new Uint8Array(0) : this.process(input);\n    },\n  };\n}\n\nfunction assertBlockMultiple(blockSize: number, input: Uint8Array): void {\n  assertCoreBlockMultiple(input, blockSize, 'ECB');\n}\n\nfunction getMutableInput(options: unknown): boolean {\n  if (typeof options !== 'object' || options === null) {\n    return false;\n  }\n  return 'mutableInput' in options && options.mutableInput === true;\n}\n"],"names":["assertCoreBlockMultiple"],"mappings":";;;;;;;;;AAEO,MAAM,GAAG,GAAyB;AACvC,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,IAAI,EAAE,KAAK;AACX,IAAA,eAAe,EAAE,IAAI;AACrB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