This commit is contained in:
chrosey
2017-09-13 07:52:34 +02:00
parent a1f16c37f4
commit 2340b0226b
24621 changed files with 2912161 additions and 149 deletions
+3
View File
@@ -0,0 +1,3 @@
{
"extends": ["standard"]
}
+6
View File
@@ -0,0 +1,6 @@
language: node_js
node_js:
- "0.11"
- "0.10"
- "0.12"
- "iojs"
+90
View File
@@ -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
}
+96
View File
@@ -0,0 +1,96 @@
{
"_args": [
[
{
"raw": "cipher-base@^1.0.0",
"scope": null,
"escapedName": "cipher-base",
"name": "cipher-base",
"rawSpec": "^1.0.0",
"spec": ">=1.0.0 <2.0.0",
"type": "range"
},
"c:\\xampp\\htdocs\\laravel\\node_modules\\browserify-aes"
]
],
"_from": "cipher-base@>=1.0.0 <2.0.0",
"_id": "cipher-base@1.0.3",
"_inCache": true,
"_location": "/cipher-base",
"_nodeVersion": "5.12.0",
"_npmOperationalInternal": {
"host": "packages-16-east.internal.npmjs.com",
"tmp": "tmp/cipher-base-1.0.3.tgz_1473767078206_0.1380389309488237"
},
"_npmUser": {
"name": "cwmma",
"email": "calvin.metcalf@gmail.com"
},
"_npmVersion": "3.8.6",
"_phantomChildren": {},
"_requested": {
"raw": "cipher-base@^1.0.0",
"scope": null,
"escapedName": "cipher-base",
"name": "cipher-base",
"rawSpec": "^1.0.0",
"spec": ">=1.0.0 <2.0.0",
"type": "range"
},
"_requiredBy": [
"/browserify-aes",
"/browserify-des",
"/create-hash",
"/create-hmac"
],
"_resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.3.tgz",
"_shasum": "eeabf194419ce900da3018c207d212f2a6df0a07",
"_shrinkwrap": null,
"_spec": "cipher-base@^1.0.0",
"_where": "c:\\xampp\\htdocs\\laravel\\node_modules\\browserify-aes",
"author": {
"name": "Calvin Metcalf",
"email": "calvin.metcalf@gmail.com"
},
"bugs": {
"url": "https://github.com/crypto-browserify/cipher-base/issues"
},
"dependencies": {
"inherits": "^2.0.1"
},
"description": "abstract base class for crypto-streams",
"devDependencies": {
"tap-spec": "^4.1.0",
"tape": "^4.2.0"
},
"directories": {},
"dist": {
"shasum": "eeabf194419ce900da3018c207d212f2a6df0a07",
"tarball": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.3.tgz"
},
"gitHead": "de2af9758ce75ef5f9a9bdaf0ba5312609a7e59a",
"homepage": "https://github.com/crypto-browserify/cipher-base#readme",
"keywords": [
"cipher",
"stream"
],
"license": "MIT",
"main": "index.js",
"maintainers": [
{
"name": "cwmma",
"email": "calvin.metcalf@gmail.com"
}
],
"name": "cipher-base",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/crypto-browserify/cipher-base.git"
},
"scripts": {
"test": "node test.js | tspec"
},
"version": "1.0.3"
}
+17
View File
@@ -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.
+108
View File
@@ -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)
})
})