text: import * as core from "../core";
  import { Mechanism } from "../mech";
  const DEFAULT_BLOCK_SIZE = 256 >> 3;
  export class Decipher extends core.BaseObject {
      constructor(session, alg, key, blockSize, lib) {
          super(lib);
          this.blockSize = DEFAULT_BLOCK_SIZE;
          this.session = session;
          this.blockSize = blockSize || DEFAULT_BLOCK_SIZE;
          this.init(alg, key);
      }
      update(data) {
          try {
              const len = Math.ceil(data.length / this.blockSize) * this.blockSize;
              const dec = Buffer.alloc(len);
              const res = this.lib.C_DecryptUpdate(this.session.handle, data, dec);
              return res;
          }
          catch (e) {
              try {
                  this.final();
              }
              catch (e) {
              }
              throw e;
          }
      }
      final() {
          const dec = Buffer.alloc(this.blockSize);
          const res = this.lib.C_DecryptFinal(this.session.handle, dec);
          return res;
      }
      once(data, dec, cb) {
          if (cb) {
              this.lib.C_Decrypt(this.session.handle, data, dec, cb);
          }
          else {
              return this.lib.C_Decrypt(this.session.handle, data, dec);
          }
      }
      init(alg, key) {
          const pMech = Mechanism.create(alg);
          this.lib.C_DecryptInit(this.session.handle, pMech, key.handle);
      }
  }
  