Sha256: ccc81229eeaa223ef84e5a2fa71e363b969ec06db9b434d3469e89f32a47c90f

Contents?: true

Size: 1.59 KB

Versions: 8

Compression:

Stored size: 1.59 KB

Contents

var sha = require('./sha')
var rng = require('./rng')
var md5 = require('./md5')

var algorithms = {
  sha1: {
    hex: sha.hex_sha1,
    binary: sha.b64_sha1,
    ascii: sha.str_sha1
  },
  md5: {
    hex: md5.hex_md5,
    binary: md5.b64_md5,
    ascii: md5.any_md5
  }
}

function error () {
  var m = [].slice.call(arguments).join(' ')
  throw new Error([
    m,
    'we accept pull requests',
    'http://github.com/dominictarr/crypto-browserify'
    ].join('\n'))
}

exports.createHash = function (alg) {
  alg = alg || 'sha1'
  if(!algorithms[alg])
    error('algorithm:', alg, 'is not yet supported')
  var s = ''
  var _alg = algorithms[alg]
  return {
    update: function (data) {
      s += data
      return this
    },
    digest: function (enc) {
      enc = enc || 'binary'
      var fn
      if(!(fn = _alg[enc]))
        error('encoding:', enc , 'is not yet supported for algorithm', alg)
      var r = fn(s)
      s = null //not meant to use the hash after you've called digest.
      return r
    }
  }
}

exports.randomBytes = function(size, callback) {
  if (callback && callback.call) {
    try {
      callback.call(this, undefined, rng(size));
    } catch (err) { callback(err); }
  } else {
    return rng(size);
  }
}

// the least I can do is make error messages for the rest of the node.js/crypto api.
;['createCredentials'
, 'createHmac'
, 'createCypher'
, 'createCypheriv'
, 'createDecipher'
, 'createDecipheriv'
, 'createSign'
, 'createVerify'
, 'createDeffieHellman'
, 'pbkdf2'].forEach(function (name) {
  exports[name] = function () {
    error('sorry,', name, 'is not implemented yet')
  }
})

Version data entries

8 entries across 6 versions & 3 rubygems

Version Path
snowball-0.1.22 node_modules/browserify/node_modules/crypto-browserify/index.js
sprockets-browserify-0.2.0 node_modules/browserify/node_modules/browser-resolve/node_modules/crypto-browserify/index.js
ruby-wisp-source-0.8.0 vendor/node_modules/browserify/node_modules/browser-resolve/node_modules/crypto-browserify/index.js
ruby-wisp-source-0.7.0 vendor/node_modules/browserify/node_modules/browser-resolve/node_modules/crypto-browserify/index.js
sprockets-browserify-0.1.2 node_modules/browserify/node_modules/crypto-browserify/index.js
sprockets-browserify-0.1.2 node_modules/module-deps/node_modules/browser-resolve/node_modules/crypto-browserify/index.js
sprockets-browserify-0.1.0 node_modules/module-deps/node_modules/browser-resolve/node_modules/crypto-browserify/index.js
sprockets-browserify-0.1.0 node_modules/browserify/node_modules/crypto-browserify/index.js