Skip to content

Use safe-buffer & License, drop Node<4 and md5.js #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ language: node_js
before_install:
- "npm install npm -g"
node_js:
- "0.10"
- "0.12"
- "4"
- "5"
- "6"
- "7"
env:
- TEST_SUITE=standard
- TEST_SUITE=unit
script: "npm run-script $TEST_SUITE"

matrix:
- TEST_SUITE=unit
matrix:
include:
- node_js: "7"
env: TEST_SUITE=standard
script: npm run $TEST_SUITE
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 crypto-browserify contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# create-hash

[![Build Status](https://travis-ci.org/crypto-browserify/createHash.svg)](https://travis-ci.org/crypto-browserify/createHash)

Node style hashes for use in the browser, with native hash functions in node.

API is the same as hashes in node:
```js
var createHash = require('create-hash')
var hash = createHash('sha224')
hash.update('synchronous write') // optional encoding parameter
hash.digest() // synchronously get result with optional encoding parameter

hash.write('write to it as a stream')
hash.end() // remember it's a stream
hash.read() // only if you ended it as a stream though
```

To get the JavaScript version even in node do `require('create-hash/browser')`
28 changes: 3 additions & 25 deletions browser.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
'use strict'
var inherits = require('inherits')
var md5 = require('./md5')
var MD5 = require('md5.js')
var RIPEMD160 = require('ripemd160')
var sha = require('sha.js')

var Base = require('cipher-base')

function HashNoConstructor (hash) {
Base.call(this, 'digest')

this._hash = hash
this.buffers = []
}

inherits(HashNoConstructor, Base)

HashNoConstructor.prototype._update = function (data) {
this.buffers.push(data)
}

HashNoConstructor.prototype._final = function () {
var buf = Buffer.concat(this.buffers)
var r = this._hash(buf)
this.buffers = null

return r
}

function Hash (hash) {
Base.call(this, 'digest')

Expand All @@ -45,8 +23,8 @@ Hash.prototype._final = function () {

module.exports = function createHash (alg) {
alg = alg.toLowerCase()
if (alg === 'md5') return new HashNoConstructor(md5)
if (alg === 'rmd160' || alg === 'ripemd160') return new Hash(new RIPEMD160())
if (alg === 'md5') return new MD5()
if (alg === 'rmd160' || alg === 'ripemd160') return new RIPEMD160()

return new Hash(sha(alg))
}
30 changes: 0 additions & 30 deletions make-hash.js

This file was deleted.

151 changes: 0 additions & 151 deletions md5.js

This file was deleted.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
"homepage": "https://github.com/crypto-browserify/createHash",
"devDependencies": {
"hash-test-vectors": "^1.3.2",
"standard": "^5.3.1",
"safe-buffer": "^5.0.1",
"standard": "^10.0.2",
"tap-spec": "^2.1.2",
"tape": "^3.0.3"
"tape": "^4.6.3"
},
"dependencies": {
"cipher-base": "^1.0.1",
"inherits": "^2.0.1",
"ripemd160": "^2.0.0",
"md5.js": "^1.3.4",
"ripemd160": "^2.0.1",
"sha.js": "^2.4.0"
}
}
19 changes: 0 additions & 19 deletions readme.md

This file was deleted.

7 changes: 4 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var test = require('tape')

var Buffer = require('safe-buffer').Buffer
var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160', 'ripemd160']
var encodings = ['hex', 'base64'] // ignore binary
var vectors = require('hash-test-vectors')
Expand All @@ -11,23 +12,23 @@ var createHash = require('./browser')
algorithms.forEach(function (algorithm) {
test('test ' + algorithm + ' against test vectors', function (t) {
vectors.forEach(function (obj, i) {
var input = new Buffer(obj.input, 'base64')
var input = Buffer.from(obj.input, 'base64')
var node = obj[algorithm]
var js = createHash(algorithm).update(input).digest('hex')
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node)
})

encodings.forEach(function (encoding) {
vectors.forEach(function (obj, i) {
var input = new Buffer(obj.input, 'base64').toString(encoding)
var input = Buffer.from(obj.input, 'base64').toString(encoding)
var node = obj[algorithm]
var js = createHash(algorithm).update(input, encoding).digest('hex')
t.equal(js, node, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + node)
})
})

vectors.forEach(function (obj, i) {
var input = new Buffer(obj.input, 'base64')
var input = Buffer.from(obj.input, 'base64')
var node = obj[algorithm]
var hash = createHash(algorithm)
hash.end(input)
Expand Down