[Pkg-javascript-commits] [node-browserify-aes] 29/43: no un-instanced new

Bastien Roucariès rouca at moszumanska.debian.org
Thu Sep 7 14:41:59 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 79d99d621a2cb2525d8f14a73861a31c85d649c9
Author: Daniel Cousens <github at dcousens.com>
Date:   Sat May 27 12:09:43 2017 +1000

    no un-instanced new
---
 authCipher.js   | 31 ++++++++++++++++---------------
 streamCipher.js |  1 -
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/authCipher.js b/authCipher.js
index 6d01891..6757212 100644
--- a/authCipher.js
+++ b/authCipher.js
@@ -4,11 +4,20 @@ var Transform = require('cipher-base')
 var inherits = require('inherits')
 var GHASH = require('./ghash')
 var xor = require('buffer-xor')
-inherits(StreamCipher, Transform)
-module.exports = StreamCipher
+
+function xorTest (a, b) {
+  var out = 0
+  if (a.length !== b.length) out++
+
+  var len = Math.min(a.length, b.length)
+  for (var i = 0; i < len; ++i) {
+    out += (a[i] ^ b[i])
+  }
+
+  return out
+}
 
 function StreamCipher (mode, key, iv, decrypt) {
-  if (!(this instanceof StreamCipher)) return new StreamCipher(mode, key, iv)
   Transform.call(this)
 
   this._finID = Buffer.concat([iv, Buffer.from([0, 0, 0, 1])])
@@ -29,6 +38,8 @@ function StreamCipher (mode, key, iv, decrypt) {
   this._called = false
 }
 
+inherits(StreamCipher, Transform)
+
 StreamCipher.prototype._update = function (chunk) {
   if (!this._called && this._alen) {
     var rump = 16 - (this._alen % 16)
@@ -38,6 +49,7 @@ StreamCipher.prototype._update = function (chunk) {
       this._ghash.update(rump)
     }
   }
+
   this._called = true
   var out = this._mode.encrypt(this, chunk)
   if (this._decrypt) {
@@ -78,15 +90,4 @@ StreamCipher.prototype.setAAD = function setAAD (buf) {
   this._alen += buf.length
 }
 
-function xorTest (a, b) {
-  var out = 0
-  if (a.length !== b.length) {
-    out++
-  }
-  var len = Math.min(a.length, b.length)
-  var i = -1
-  while (++i < len) {
-    out += (a[i] ^ b[i])
-  }
-  return out
-}
+module.exports = StreamCipher
diff --git a/streamCipher.js b/streamCipher.js
index 6355732..1877fa0 100644
--- a/streamCipher.js
+++ b/streamCipher.js
@@ -4,7 +4,6 @@ var Transform = require('cipher-base')
 var inherits = require('inherits')
 
 function StreamCipher (mode, key, iv, decrypt) {
-  if (!(this instanceof StreamCipher)) return new StreamCipher(mode, key, iv)
   Transform.call(this)
 
   this._cipher = new aes.AES(key)

-- 
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