mode.ts 559 B

123456789101112131415161718192021
  1. import { AES } from "./aes.js";
  2. export abstract class ModeOfOperation {
  3. readonly aes!: AES;
  4. readonly name!: string;
  5. constructor(name: string, key: Uint8Array, cls?: any) {
  6. if (cls && !(this instanceof cls)) {
  7. throw new Error(`${ name } must be instantiated with "new"`);
  8. }
  9. Object.defineProperties(this, {
  10. aes: { enumerable: true, value: new AES(key) },
  11. name: { enumerable: true, value: name }
  12. });
  13. }
  14. abstract encrypt(plaintext: Uint8Array): Uint8Array;
  15. abstract decrypt(ciphertext: Uint8Array): Uint8Array;
  16. }