Projekt

Obecné

Profil

Stáhnout (625 Bajtů) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
'use strict'
2
var inherits = require('inherits')
3
var MD5 = require('md5.js')
4
var RIPEMD160 = require('ripemd160')
5
var sha = require('sha.js')
6
var Base = require('cipher-base')
7
8
function Hash (hash) {
9
  Base.call(this, 'digest')
10
11
  this._hash = hash
12
}
13
14
inherits(Hash, Base)
15
16
Hash.prototype._update = function (data) {
17
  this._hash.update(data)
18
}
19
20
Hash.prototype._final = function () {
21
  return this._hash.digest()
22
}
23
24
module.exports = function createHash (alg) {
25
  alg = alg.toLowerCase()
26
  if (alg === 'md5') return new MD5()
27
  if (alg === 'rmd160' || alg === 'ripemd160') return new RIPEMD160()
28
29
  return new Hash(sha(alg))
30
}