[Pkg-javascript-commits] [node-browserify-aes] 18/43: mv modes to modes/index.js

Bastien Roucariès rouca at moszumanska.debian.org
Thu Sep 7 14:41:58 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-browserify-aes.

commit 877529f79d59af3bd18e2e38886e87ec649c9818
Author: Daniel Cousens <github at dcousens.com>
Date:   Fri May 19 14:45:33 2017 +1000

    mv modes to modes/index.js
---
 browser.js                    |  2 +-
 decrypter.js                  | 32 +++++++++++---------------------
 encrypter.js                  | 23 ++++++-----------------
 modes/index.js                | 18 ++++++++++++++++++
 modes.json => modes/list.json |  0
 scripts/populateFixtures.js   |  2 +-
 test/index.js                 |  2 +-
 7 files changed, 38 insertions(+), 41 deletions(-)

diff --git a/browser.js b/browser.js
index dcb10cd..d47a5f6 100644
--- a/browser.js
+++ b/browser.js
@@ -1,6 +1,6 @@
 var ciphers = require('./encrypter')
 var deciphers = require('./decrypter')
-var modes = require('./modes.json')
+var modes = require('./modes/list.json')
 
 function getCiphers () {
   return Object.keys(modes)
diff --git a/decrypter.js b/decrypter.js
index 97b1ceb..a2f596b 100644
--- a/decrypter.js
+++ b/decrypter.js
@@ -1,10 +1,11 @@
-var aes = require('./aes')
-var Transform = require('cipher-base')
-var inherits = require('inherits')
-var modes = require('./modes.json')
-var StreamCipher = require('./streamCipher')
 var AuthCipher = require('./authCipher')
+var Buffer = require('safe-buffer').Buffer
+var MODES = require('./modes')
+var StreamCipher = require('./streamCipher')
+var Transform = require('cipher-base')
+var aes = require('./aes')
 var ebtk = require('evp_bytestokey')
+var inherits = require('inherits')
 
 function Decipher (mode, key, iv) {
   Transform.call(this)
@@ -89,19 +90,8 @@ function unpad (last) {
   return last.slice(0, 16 - padded)
 }
 
-var modelist = {
-  ECB: require('./modes/ecb'),
-  CBC: require('./modes/cbc'),
-  CFB: require('./modes/cfb'),
-  CFB8: require('./modes/cfb8'),
-  CFB1: require('./modes/cfb1'),
-  OFB: require('./modes/ofb'),
-  CTR: require('./modes/ctr'),
-  GCM: require('./modes/ctr')
-}
-
 function createDecipheriv (suite, password, iv) {
-  var config = modes[suite.toLowerCase()]
+  var config = MODES[suite.toLowerCase()]
   if (!config) throw new TypeError('invalid suite type')
 
   if (typeof iv === 'string') iv = Buffer.from(iv)
@@ -111,16 +101,16 @@ function createDecipheriv (suite, password, iv) {
   if (password.length !== config.key / 8) throw new TypeError('invalid key length ' + password.length)
 
   if (config.type === 'stream') {
-    return new StreamCipher(modelist[config.mode], password, iv, true)
+    return new StreamCipher(config.module, password, iv, true)
   } else if (config.type === 'auth') {
-    return new AuthCipher(modelist[config.mode], password, iv, true)
+    return new AuthCipher(config.module, password, iv, true)
   }
 
-  return new Decipher(modelist[config.mode], password, iv)
+  return new Decipher(config.module, password, iv)
 }
 
 function createDecipher (suite, password) {
-  var config = modes[suite.toLowerCase()]
+  var config = MODES[suite.toLowerCase()]
   if (!config) throw new TypeError('invalid suite type')
 
   var keys = ebtk(password, false, config.key, config.iv)
diff --git a/encrypter.js b/encrypter.js
index 5b52217..df2eab8 100644
--- a/encrypter.js
+++ b/encrypter.js
@@ -1,3 +1,4 @@
+var MODES = require('./modes')
 var AuthCipher = require('./authCipher')
 var Buffer = require('safe-buffer').Buffer
 var StreamCipher = require('./streamCipher')
@@ -5,7 +6,6 @@ var Transform = require('cipher-base')
 var aes = require('./aes')
 var ebtk = require('evp_bytestokey')
 var inherits = require('inherits')
-var modes = require('./modes.json')
 
 function Cipher (mode, key, iv) {
   Transform.call(this)
@@ -83,19 +83,8 @@ Splitter.prototype.flush = function () {
   return Buffer.concat([this.cache, padBuff])
 }
 
-var modelist = {
-  ECB: require('./modes/ecb'),
-  CBC: require('./modes/cbc'),
-  CFB: require('./modes/cfb'),
-  CFB8: require('./modes/cfb8'),
-  CFB1: require('./modes/cfb1'),
-  OFB: require('./modes/ofb'),
-  CTR: require('./modes/ctr'),
-  GCM: require('./modes/ctr')
-}
-
 function createCipheriv (suite, password, iv) {
-  var config = modes[suite.toLowerCase()]
+  var config = MODES[suite.toLowerCase()]
   if (!config) throw new TypeError('invalid suite type')
 
   if (typeof password === 'string') password = Buffer.from(password)
@@ -105,16 +94,16 @@ function createCipheriv (suite, password, iv) {
   if (iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length)
 
   if (config.type === 'stream') {
-    return new StreamCipher(modelist[config.mode], password, iv)
+    return new StreamCipher(config.module, password, iv)
   } else if (config.type === 'auth') {
-    return new AuthCipher(modelist[config.mode], password, iv)
+    return new AuthCipher(config.module, password, iv)
   }
 
-  return new Cipher(modelist[config.mode], password, iv)
+  return new Cipher(config.module, password, iv)
 }
 
 function createCipher (suite, password) {
-  var config = modes[suite.toLowerCase()]
+  var config = MODES[suite.toLowerCase()]
   if (!config) throw new TypeError('invalid suite type')
 
   var keys = ebtk(password, false, config.key, config.iv)
diff --git a/modes/index.js b/modes/index.js
new file mode 100644
index 0000000..767d6cb
--- /dev/null
+++ b/modes/index.js
@@ -0,0 +1,18 @@
+var modeModules = {
+  ECB: require('./ecb'),
+  CBC: require('./cbc'),
+  CFB: require('./cfb'),
+  CFB8: require('./cfb8'),
+  CFB1: require('./cfb1'),
+  OFB: require('./ofb'),
+  CTR: require('./ctr'),
+  GCM: require('./ctr')
+}
+
+var modes = require('./list.json')
+
+for (var key in modes) {
+  modes[key].module = modeModules[modes[key].mode]
+}
+
+module.exports = modes
diff --git a/modes.json b/modes/list.json
similarity index 100%
rename from modes.json
rename to modes/list.json
diff --git a/scripts/populateFixtures.js b/scripts/populateFixtures.js
index 9dd6bf2..e202f19 100644
--- a/scripts/populateFixtures.js
+++ b/scripts/populateFixtures.js
@@ -1,4 +1,4 @@
-var modes = require('./modes.json')
+var modes = require('./modes/list.json')
 var fixtures = require('./test/fixtures.json')
 var crypto = require('crypto')
 var types = ['aes-128-cfb1', 'aes-192-cfb1', 'aes-256-cfb1']
diff --git a/test/index.js b/test/index.js
index 20c45fe..80605d9 100644
--- a/test/index.js
+++ b/test/index.js
@@ -540,7 +540,7 @@ test('autopadding false cipher throws', function (t) {
 
   t.throws(function () {
     nodecipher.final()
-  }, 'node')
+  }, /./)
 })
 
 test('getCiphers works', function (t) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-browserify-aes.git



More information about the Pkg-javascript-commits mailing list