All files / crypto/src/mipher AES_CBC_ZeroPadding.js

100% Statements 7/7
100% Branches 0/0
100% Functions 3/3
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50              1x 1x                     107x 107x                       1x                       106x       1x  
/**
 * Copyright (c) Benjamin Ansbach - all rights reserved.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
 
const mipherAES = require('mipher/dist/aes');
const mipherPadding = require('mipher/dist/padding');
 
/**
 * AES-CBC + ZeroPadding integration using the mipher library
 */
class AES_CBC_ZeroPadding {
 
  /**
   * Constructor
   */
  constructor() {
    this.cipher = new mipherAES.AES_CBC();
    this.padding = new mipherPadding.ZeroPadding();
  }
 
  /**
   * Encrypts using the given values.
   *
   * @param key
   * @param pt
   * @param iv
   * @returns {Uint8Array}
   */
  encrypt(key, pt, iv) {
    return this.cipher.encrypt(key, this.padding.pad(pt, this.cipher.cipher.blockSize), iv);
  }
 
  /**
   * Decrypts using the given values.
   *
   * @param key
   * @param ct
   * @param iv
   * @returns {Uint8Array}
   */
  decrypt(key, ct, iv) {
    return this.padding.strip(this.cipher.decrypt(key, ct, iv));
  };
}
 
module.exports = AES_CBC_ZeroPadding;