Skip to content

Commit

Permalink
Allow node < 4.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Feb 23, 2017
1 parent e64522e commit f8de1ce
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/api/keccak.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = function (KeccakState) {
Keccak.prototype.update = function (data, encoding) {
if (!Buffer.isBuffer(data) && typeof data !== 'string') throw new TypeError('Data must be a string or a buffer')
if (this._finalized) throw new Error('Digest already called')
if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding)
if (!Buffer.isBuffer(data)) data = new Buffer(data, encoding)

this._state.absorb(data)

Expand Down
2 changes: 1 addition & 1 deletion lib/api/shake.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = function (KeccakState) {
Shake.prototype.update = function (data, encoding) {
if (!Buffer.isBuffer(data) && typeof data !== 'string') throw new TypeError('Data must be a string or a buffer')
if (this._finalized) throw new Error('Squeeze already called')
if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding)
if (!Buffer.isBuffer(data)) data = new Buffer(data, encoding)

this._state.absorb(data)

Expand Down
2 changes: 1 addition & 1 deletion lib/keccak.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Keccak.prototype.absorbLastFewBits = function (bits) {
Keccak.prototype.squeeze = function (length) {
if (!this.squeezing) this.absorbLastFewBits(0x01)

var output = Buffer.allocUnsafe(length)
var output = new Buffer(length)
for (var i = 0; i < length; ++i) {
output[i] = (this.state[~~(this.count / 4)] >>> (8 * (this.count % 4))) & 0xff
this.count += 1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"tape": "^4.5.1"
},
"engines": {
"node": ">=4.5.0"
"node": ">=4.0.0"
},
"gypfile": true,
"browser": {
Expand Down
6 changes: 3 additions & 3 deletions test/api-sha3.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = (name, createHash) => {

t.plan(1)
hash.update = () => { throw err }
hash._transform(Buffer.allocUnsafe(0), 'buffer', (_err) => t.true(_err === err))
hash._transform(new Buffer(0), 'buffer', (_err) => t.true(_err === err))
t.end()
})

Expand All @@ -33,7 +33,7 @@ module.exports = (name, createHash) => {
test(`${name} Keccak#_flush`, (t) => {
t.test('should use Keccak#digest', (t) => {
const hash = createHash('sha3-256')
const buffer = Buffer.allocUnsafe(0)
const buffer = new Buffer(0)

t.plan(2)
hash.push = (data) => t.true(data === buffer)
Expand Down Expand Up @@ -78,7 +78,7 @@ module.exports = (name, createHash) => {
t.test('should return `this`', (t) => {
const hash = createHash('sha3-256')

t.same(hash.update(Buffer.allocUnsafe(0)), hash)
t.same(hash.update(new Buffer(0)), hash)
t.end()
})

Expand Down
8 changes: 4 additions & 4 deletions test/api-shake.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = (name, createHash) => {

t.plan(1)
hash.update = () => { throw err }
hash._transform(Buffer.allocUnsafe(0), 'buffer', (_err) => t.true(_err === err))
hash._transform(new Buffer(0), 'buffer', (_err) => t.true(_err === err))
t.end()
})

Expand All @@ -42,7 +42,7 @@ module.exports = (name, createHash) => {
}
})

let data = Buffer.allocUnsafe(0)
let data = new Buffer(0)
const squeezed = '46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762f'
const dst = stream.Writable({
write (chunk, encoding, callback) {
Expand Down Expand Up @@ -84,7 +84,7 @@ module.exports = (name, createHash) => {
t.test('should return `this`', (t) => {
const hash = createHash('shake256')

t.same(hash.update(Buffer.allocUnsafe(0)), hash)
t.same(hash.update(new Buffer(0)), hash)
t.end()
})

Expand Down Expand Up @@ -128,7 +128,7 @@ module.exports = (name, createHash) => {

const squeezed1 = hash1.squeeze(32, 'hex')
t.throws(() => {
hash1.update(Buffer.allocUnsafe(0))
hash1.update(new Buffer(0))
}, /^Error: Squeeze already called$/)
t.equal(hash2.squeeze(32, 'hex'), squeezed1)

Expand Down
4 changes: 2 additions & 2 deletions test/js-keccak.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function to32bin (x) {
test('absorb', (t) => {
const keccak = new Keccak()
keccak.initialize(56, 1544)
keccak.absorb(Buffer.allocUnsafe(10).fill(0x01))
keccak.absorb(new Buffer(10).fill(0x01))

t.equal(keccak.state[0], (0x01 << 24))
t.equal(keccak.state[1], (0x01 << 16) | (0x01 << 8) | (0x01 << 0))
Expand Down Expand Up @@ -48,7 +48,7 @@ test('absorbLastFewBits', (t) => {
test('squeeze', (t) => {
const keccak = new Keccak()
keccak.initialize(56, 1544)
keccak.absorb(Buffer.allocUnsafe(5).fill(0x01))
keccak.absorb(new Buffer(5).fill(0x01))

t.equal(keccak.squeeze(7).toString('hex'), '01010101010180')
t.equal(keccak.squeeze(3).toString('hex'), '010101')
Expand Down
2 changes: 1 addition & 1 deletion test/vectors-keccak.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const vectors = [{
module.exports = (name, createHash) => {
for (let i = 0; i < vectors.length; ++i) {
const vector = vectors[i]
const data = Buffer.from(vector.input, 'hex')
const data = new Buffer(vector.input, 'hex')

for (let hash of ['keccak224', 'keccak256', 'keccak384', 'keccak512']) {
test(`${name} ${hash} vector#${i}`, (t) => {
Expand Down

0 comments on commit f8de1ce

Please sign in to comment.