import { type Binary } from '../binary.js'; import { type CryptoService, type DecryptResult, type EncryptResult, } from '../crypto/declarations.js'; export abstract class SymmetricCipher { cryptoService: CryptoService; name?: string; ivLength?: number; keyLength?: number; constructor(cryptoService: CryptoService) { this.cryptoService = cryptoService; } async generateInitializationVector(): Promise { if (!this.ivLength) { throw Error('No iv length'); } return this.cryptoService.generateInitializationVector(this.ivLength); } async generateKey(): Promise { if (!this.keyLength) { throw Error('No key length'); } return this.cryptoService.generateKey(this.keyLength); } abstract encrypt(payload: Binary, key: Binary, iv: Binary): Promise; abstract decrypt(payload: Uint8Array, key: Binary, iv?: Binary): Promise; }