diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-03 15:35:00 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-03 15:35:00 +0200 |
commit | de98e0b232509d5f40c135d540a70e415272ff85 (patch) | |
tree | a79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/cipher-base | |
parent | e0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff) | |
download | wallet-core-de98e0b232509d5f40c135d540a70e415272ff85.tar.xz |
node_modules
Diffstat (limited to 'node_modules/cipher-base')
-rw-r--r-- | node_modules/cipher-base/.eslintrc | 3 | ||||
-rw-r--r-- | node_modules/cipher-base/.travis.yml | 6 | ||||
-rw-r--r-- | node_modules/cipher-base/index.js | 90 | ||||
-rw-r--r-- | node_modules/cipher-base/package.json | 30 | ||||
-rw-r--r-- | node_modules/cipher-base/readme.md | 17 | ||||
-rw-r--r-- | node_modules/cipher-base/test.js | 108 |
6 files changed, 254 insertions, 0 deletions
diff --git a/node_modules/cipher-base/.eslintrc b/node_modules/cipher-base/.eslintrc new file mode 100644 index 000000000..a755cdbfe --- /dev/null +++ b/node_modules/cipher-base/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": ["standard"] +} diff --git a/node_modules/cipher-base/.travis.yml b/node_modules/cipher-base/.travis.yml new file mode 100644 index 000000000..eb83acd99 --- /dev/null +++ b/node_modules/cipher-base/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - "0.11" + - "0.10" + - "0.12" + - "iojs" diff --git a/node_modules/cipher-base/index.js b/node_modules/cipher-base/index.js new file mode 100644 index 000000000..1a661d626 --- /dev/null +++ b/node_modules/cipher-base/index.js @@ -0,0 +1,90 @@ +var Transform = require('stream').Transform +var inherits = require('inherits') +var StringDecoder = require('string_decoder').StringDecoder +module.exports = CipherBase +inherits(CipherBase, Transform) +function CipherBase (hashMode) { + Transform.call(this) + this.hashMode = typeof hashMode === 'string' + if (this.hashMode) { + this[hashMode] = this._finalOrDigest + } else { + this.final = this._finalOrDigest + } + this._decoder = null + this._encoding = null +} +CipherBase.prototype.update = function (data, inputEnc, outputEnc) { + if (typeof data === 'string') { + data = new Buffer(data, inputEnc) + } + var outData = this._update(data) + if (this.hashMode) { + return this + } + if (outputEnc) { + outData = this._toString(outData, outputEnc) + } + return outData +} + +CipherBase.prototype.setAutoPadding = function () {} + +CipherBase.prototype.getAuthTag = function () { + throw new Error('trying to get auth tag in unsupported state') +} + +CipherBase.prototype.setAuthTag = function () { + throw new Error('trying to set auth tag in unsupported state') +} + +CipherBase.prototype.setAAD = function () { + throw new Error('trying to set aad in unsupported state') +} + +CipherBase.prototype._transform = function (data, _, next) { + var err + try { + if (this.hashMode) { + this._update(data) + } else { + this.push(this._update(data)) + } + } catch (e) { + err = e + } finally { + next(err) + } +} +CipherBase.prototype._flush = function (done) { + var err + try { + this.push(this._final()) + } catch (e) { + err = e + } finally { + done(err) + } +} +CipherBase.prototype._finalOrDigest = function (outputEnc) { + var outData = this._final() || new Buffer('') + if (outputEnc) { + outData = this._toString(outData, outputEnc, true) + } + return outData +} + +CipherBase.prototype._toString = function (value, enc, fin) { + if (!this._decoder) { + this._decoder = new StringDecoder(enc) + this._encoding = enc + } + if (this._encoding !== enc) { + throw new Error('can\'t switch encodings') + } + var out = this._decoder.write(value) + if (fin) { + out += this._decoder.end() + } + return out +} diff --git a/node_modules/cipher-base/package.json b/node_modules/cipher-base/package.json new file mode 100644 index 000000000..1203f7d43 --- /dev/null +++ b/node_modules/cipher-base/package.json @@ -0,0 +1,30 @@ +{ + "name": "cipher-base", + "version": "1.0.3", + "description": "abstract base class for crypto-streams", + "main": "index.js", + "scripts": { + "test": "node test.js | tspec" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/crypto-browserify/cipher-base.git" + }, + "keywords": [ + "cipher", + "stream" + ], + "author": "Calvin Metcalf <calvin.metcalf@gmail.com>", + "license": "MIT", + "bugs": { + "url": "https://github.com/crypto-browserify/cipher-base/issues" + }, + "homepage": "https://github.com/crypto-browserify/cipher-base#readme", + "dependencies": { + "inherits": "^2.0.1" + }, + "devDependencies": { + "tap-spec": "^4.1.0", + "tape": "^4.2.0" + } +} diff --git a/node_modules/cipher-base/readme.md b/node_modules/cipher-base/readme.md new file mode 100644 index 000000000..db9a78141 --- /dev/null +++ b/node_modules/cipher-base/readme.md @@ -0,0 +1,17 @@ +cipher-base +=== + +[![Build Status](https://travis-ci.org/crypto-browserify/cipher-base.svg)](https://travis-ci.org/crypto-browserify/cipher-base) + +Abstract base class to inherit from if you want to create streams implementing +the same api as node crypto streams. + +Requires you to implement 2 methods `_final` and `_update`. `_update` takes a +buffer and should return a buffer, `_final` takes no arguments and should return +a buffer. + + +The constructor takes one argument and that is a string which if present switches +it into hash mode, i.e. the object you get from crypto.createHash or +crypto.createSign, this switches the name of the final method to be the string +you passed instead of `final` and returns `this` from update. diff --git a/node_modules/cipher-base/test.js b/node_modules/cipher-base/test.js new file mode 100644 index 000000000..57d144a55 --- /dev/null +++ b/node_modules/cipher-base/test.js @@ -0,0 +1,108 @@ +var test = require('tape') +var CipherBase = require('./') +var inherits = require('inherits') + +test('basic version', function (t) { + inherits(Cipher, CipherBase) + function Cipher () { + CipherBase.call(this) + } + Cipher.prototype._update = function (input) { + t.ok(Buffer.isBuffer(input)) + return input + } + Cipher.prototype._final = function () { + // noop + } + var cipher = new Cipher() + var utf8 = 'abc123abcd' + var update = cipher.update(utf8, 'utf8', 'base64') + cipher.final('base64') + var string = (new Buffer(update, 'base64')).toString() + t.equals(utf8, string) + t.end() +}) +test('hash mode', function (t) { + inherits(Cipher, CipherBase) + function Cipher () { + CipherBase.call(this, 'finalName') + this._cache = [] + } + Cipher.prototype._update = function (input) { + t.ok(Buffer.isBuffer(input)) + this._cache.push(input) + } + Cipher.prototype._final = function () { + return Buffer.concat(this._cache) + } + var cipher = new Cipher() + var utf8 = 'abc123abcd' + var update = cipher.update(utf8, 'utf8').finalName('base64') + var string = (new Buffer(update, 'base64')).toString() + + t.equals(utf8, string) + t.end() +}) +test('hash mode as stream', function (t) { + inherits(Cipher, CipherBase) + function Cipher () { + CipherBase.call(this, 'finalName') + this._cache = [] + } + Cipher.prototype._update = function (input) { + t.ok(Buffer.isBuffer(input)) + this._cache.push(input) + } + Cipher.prototype._final = function () { + return Buffer.concat(this._cache) + } + var cipher = new Cipher() + cipher.on('error', function (e) { + t.notOk(e) + }) + var utf8 = 'abc123abcd' + cipher.end(utf8, 'utf8') + var update = cipher.read().toString('base64') + var string = (new Buffer(update, 'base64')).toString() + + t.equals(utf8, string) + t.end() +}) +test('encodings', function (t) { + inherits(Cipher, CipherBase) + function Cipher () { + CipherBase.call(this) + } + Cipher.prototype._update = function (input) { + return input + } + Cipher.prototype._final = function () { + // noop + } + t.test('mix and match encoding', function (t) { + t.plan(2) + + var cipher = new Cipher() + cipher.update('foo', 'utf8', 'utf8') + t.throws(function () { + cipher.update('foo', 'utf8', 'base64') + }) + cipher = new Cipher() + cipher.update('foo', 'utf8', 'base64') + t.doesNotThrow(function () { + cipher.update('foo', 'utf8') + cipher.final('base64') + }) + }) + t.test('handle long uft8 plaintexts', function (t) { + t.plan(1) + var txt = 'ふっかつ あきる すぶり はやい つける まゆげ たんさん みんぞく ねほりはほり せまい たいまつばな ひはん' + + var cipher = new Cipher() + var decipher = new Cipher() + var enc = decipher.update(cipher.update(txt, 'utf8', 'base64'), 'base64', 'utf8') + enc += decipher.update(cipher.final('base64'), 'base64', 'utf8') + enc += decipher.final('utf8') + + t.equals(txt, enc) + }) +}) |