browserify-aes
Advanced tools
Comparing version 0.6.1 to 0.7.1
@@ -31,3 +31,3 @@ var aes = require('./aes'); | ||
} | ||
StreamCipher.prototype._transform = function (chunk, _, next) { | ||
StreamCipher.prototype._update = function (chunk) { | ||
if (!this._called && this._alen) { | ||
@@ -49,5 +49,5 @@ var rump = 16 - (this._alen % 16); | ||
this._len += chunk.length; | ||
next(null, out); | ||
return out; | ||
}; | ||
StreamCipher.prototype._flush = function (next) { | ||
StreamCipher.prototype._final = function () { | ||
if (this._decrypt && !this._authTag) { | ||
@@ -65,3 +65,2 @@ throw new Error('Unsupported state or unable to authenticate data'); | ||
this._cipher.scrub(); | ||
next(); | ||
}; | ||
@@ -68,0 +67,0 @@ StreamCipher.prototype.getAuthTag = function getAuthTag () { |
@@ -9,9 +9,7 @@ var Transform = require('stream').Transform; | ||
} | ||
CipherBase.prototype.update = function (data, inputEnd, outputEnc) { | ||
this.write(data, inputEnd); | ||
var outData = new Buffer(''); | ||
var chunk; | ||
while ((chunk = this.read())) { | ||
outData = Buffer.concat([outData, chunk]); | ||
CipherBase.prototype.update = function (data, inputEnc, outputEnc) { | ||
if (typeof data === 'string') { | ||
data = new Buffer(data, inputEnc); | ||
} | ||
var outData = this._update(data); | ||
if (outputEnc) { | ||
@@ -22,9 +20,15 @@ outData = outData.toString(outputEnc); | ||
}; | ||
CipherBase.prototype._transform = function (data, _, next) { | ||
this.push(this._update(data)); | ||
next(); | ||
}; | ||
CipherBase.prototype._flush = function (next) { | ||
var chunk = this._final(); | ||
if (chunk) { | ||
this.push(chunk); | ||
} | ||
next(); | ||
}; | ||
CipherBase.prototype.final = function (outputEnc) { | ||
this.end(); | ||
var outData = new Buffer(''); | ||
var chunk; | ||
while ((chunk = this.read())) { | ||
outData = Buffer.concat([outData, chunk]); | ||
} | ||
var outData = this._final() || new Buffer(''); | ||
if (outputEnc) { | ||
@@ -31,0 +35,0 @@ outData = outData.toString(outputEnc); |
@@ -21,24 +21,26 @@ var aes = require('./aes'); | ||
this._mode = mode; | ||
this._autopadding = true; | ||
} | ||
Decipher.prototype._transform = function (data, _, next) { | ||
Decipher.prototype._update = function (data) { | ||
this._cache.add(data); | ||
var chunk; | ||
var thing; | ||
while ((chunk = this._cache.get())) { | ||
var out = []; | ||
while ((chunk = this._cache.get(this._autopadding))) { | ||
thing = this._mode.decrypt(this, chunk); | ||
this.push(thing); | ||
out.push(thing); | ||
} | ||
next(); | ||
return Buffer.concat(out); | ||
}; | ||
Decipher.prototype._flush = function (next) { | ||
Decipher.prototype._final = function () { | ||
var chunk = this._cache.flush(); | ||
if (!chunk) { | ||
return next; | ||
if (this._autopadding) { | ||
return unpad(this._mode.decrypt(this, chunk)); | ||
} else if (chunk) { | ||
throw new Error('data not multiple of block length'); | ||
} | ||
this.push(unpad(this._mode.decrypt(this, chunk))); | ||
next(); | ||
}; | ||
Decipher.prototype.setAutoPadding = function (setTo) { | ||
this._autopadding = !!setTo; | ||
}; | ||
function Splitter() { | ||
@@ -54,7 +56,16 @@ if (!(this instanceof Splitter)) { | ||
Splitter.prototype.get = function () { | ||
if (this.cache.length > 16) { | ||
var out = this.cache.slice(0, 16); | ||
this.cache = this.cache.slice(16); | ||
return out; | ||
Splitter.prototype.get = function (autoPadding) { | ||
var out; | ||
if (autoPadding) { | ||
if (this.cache.length > 16) { | ||
out = this.cache.slice(0, 16); | ||
this.cache = this.cache.slice(16); | ||
return out; | ||
} | ||
} else { | ||
if (this.cache.length >= 16) { | ||
out = this.cache.slice(0, 16); | ||
this.cache = this.cache.slice(16); | ||
return out; | ||
} | ||
} | ||
@@ -61,0 +72,0 @@ return null; |
@@ -19,21 +19,30 @@ var aes = require('./aes'); | ||
this._mode = mode; | ||
this._autopadding = true; | ||
} | ||
Cipher.prototype._transform = function (data, _, next) { | ||
Cipher.prototype._update = function (data) { | ||
this._cache.add(data); | ||
var chunk; | ||
var thing; | ||
var out = []; | ||
while ((chunk = this._cache.get())) { | ||
thing = this._mode.encrypt(this, chunk); | ||
this.push(thing); | ||
out.push(thing); | ||
} | ||
next(); | ||
return Buffer.concat(out); | ||
}; | ||
Cipher.prototype._flush = function (next) { | ||
Cipher.prototype._final = function () { | ||
var chunk = this._cache.flush(); | ||
this.push(this._mode.encrypt(this, chunk)); | ||
this._cipher.scrub(); | ||
next(); | ||
if (this._autopadding) { | ||
chunk = this._mode.encrypt(this, chunk); | ||
this._cipher.scrub(); | ||
return chunk; | ||
} else if (chunk.toString('hex') !== '10101010101010101010101010101010') { | ||
this._cipher.scrub(); | ||
throw new Error('data not multiple of block length'); | ||
} | ||
}; | ||
Cipher.prototype.setAutoPadding = function (setTo) { | ||
this._autopadding = !!setTo; | ||
}; | ||
function Splitter() { | ||
@@ -40,0 +49,0 @@ if (!(this instanceof Splitter)) { |
{ | ||
"name": "browserify-aes", | ||
"version": "0.6.1", | ||
"version": "0.7.1", | ||
"description": "aes, for browserify", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,6 +0,8 @@ | ||
browserify-aes [![Build Status](https://travis-ci.org/calvinmetcalf/browserify-aes.svg)](https://travis-ci.org/calvinmetcalf/browserify-aes) | ||
browserify-aes | ||
==== | ||
much of this taken from the aes implimentation in [triplesec](https://github.com/keybase/triplesec) which in turn based its implimentation on [crypto-js](https://code.google.com/p/crypto-js/). | ||
[![Build Status](https://travis-ci.org/calvinmetcalf/browserify-aes.svg)](https://travis-ci.org/calvinmetcalf/browserify-aes) | ||
EVP_BytesToKey is a strait up port of the same function from openssl as there is literally no documenation on it beyond it using 'undocumented extentions' for longer keys. | ||
Much of this library has been taken from the aes implementation in [triplesec](https://github.com/keybase/triplesec), a partial derivation of [crypto-js](https://code.google.com/p/crypto-js/). | ||
`EVP_BytesToKey` is a straight up port of the same function from OpenSSL as there is literally no documenation on it beyond it using 'undocumented extensions' for longer keys. |
@@ -20,8 +20,7 @@ var aes = require('./aes'); | ||
} | ||
StreamCipher.prototype._transform = function (chunk, _, next) { | ||
next(null, this._mode.encrypt(this, chunk, this._decrypt)); | ||
StreamCipher.prototype._update = function (chunk) { | ||
return this._mode.encrypt(this, chunk, this._decrypt); | ||
}; | ||
StreamCipher.prototype._flush = function (next) { | ||
StreamCipher.prototype._final = function () { | ||
this._cipher.scrub(); | ||
next(); | ||
}; |
@@ -424,3 +424,3 @@ var test = require('tape'); | ||
block1.fill(4); | ||
var cipher = _crypto.createCipher('aes128', new Buffer('password')); | ||
var cipher = crypto.createCipher('aes128', new Buffer('password')); | ||
cipher.setAutoPadding(false); | ||
@@ -456,1 +456,30 @@ var decipher = crypto.createDecipher('aes128', new Buffer('password')); | ||
incorectPaddingthrows(two); | ||
test('autopadding false decipher', function (t) { | ||
t.plan(2); | ||
var mycipher = crypto.createCipher('aes-128-ecb', new Buffer('password')); | ||
var nodecipher = _crypto.createCipher('aes-128-ecb', new Buffer('password')); | ||
var myEnc = mycipher.final(); | ||
var nodeEnc = nodecipher.final(); | ||
t.equals(myEnc.toString('hex'), nodeEnc.toString('hex'), 'same encryption'); | ||
var decipher = crypto.createDecipher('aes-128-ecb', new Buffer('password')); | ||
decipher.setAutoPadding(false); | ||
var decipher2 = _crypto.createDecipher('aes-128-ecb', new Buffer('password')); | ||
decipher2.setAutoPadding(false); | ||
t.equals(decipher.update(myEnc).toString('hex'), decipher2.update(nodeEnc).toString('hex'), 'same decryption'); | ||
}); | ||
test('autopadding false cipher throws', function (t) { | ||
t.plan(2); | ||
var mycipher = crypto.createCipher('aes-128-ecb', new Buffer('password')); | ||
mycipher.setAutoPadding(false); | ||
var nodecipher = _crypto.createCipher('aes-128-ecb', new Buffer('password')); | ||
nodecipher.setAutoPadding(false); | ||
mycipher.update('foo'); | ||
nodecipher.update('foo'); | ||
t.throws(function () { | ||
mycipher.final(); | ||
}, 'mine'); | ||
t.throws(function () { | ||
nodecipher.final(); | ||
}, 'node'); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
417112
3302
9