All files / crypto/src/mipher MD5Mipher.js

12.5% Statements 2/16
0% Branches 0/3
0% Functions 0/8
12.5% Lines 2/16

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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81              1x                                                                                                                                               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 MD5 = require('md5.js');
 
/**
 * SHA512 class
 */
class MD5Mipher {
 
  get hashSize() {
    return 32;
  }
  /**
     * SHA512 ctor
     */
  constructor() {
    this.updates = [];
  }
  /**
     * Init the hash
     * @return {Object} this
     */
  init() {
    // return new MD5Mipher();
    this.updates = [];
    return this;
  }
 
  /**
     * Update the hash with additional message data
     * @param {Uint8Array} msg Additional message data as byte array
     * @return {SHA512} this
     */
  update(msg) {
    this.updates.push(Buffer.from(msg));
    return this;
  }
 
  /**
     * Finalize the hash with additional message data
     * @param {Uint8Array} msg Additional message data as byte array
     * @return {Uint8Array} Hash as 64 byte array
     */
  digest(msg = null) {
    if (msg !== null) {
      this.update(msg);
    }
 
    let sponge = new MD5();
 
    this.updates.forEach((update) => {
      sponge.update(update);
    });
 
    return sponge.digest('hex');
  }
 
  /**
     * All in one step
     * @param {Uint8Array} msg Additional message data
     * @return {Uint8Array} Hash as 64 byte array
     */
  hash(msg) {
    return new MD5Mipher().update(msg).digest();
  }
  /**
     * Performs a quick selftest
     * @return {Boolean} True if successful
     */
  selftest() {
    return true;
  }
}
 
module.exports = MD5Mipher;