[Pkg-javascript-commits] [node-browserify-aes] 17/43: encrypter: compare to PADDING, not hex

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 699f1607a743dd337c7c58386baf7d9742541301
Author: Daniel Cousens <github at dcousens.com>
Date:   Fri May 19 14:39:03 2017 +1000

    encrypter: compare to PADDING, not hex
---
 encrypter.js  | 6 +++++-
 test/index.js | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/encrypter.js b/encrypter.js
index b4363da..5b52217 100644
--- a/encrypter.js
+++ b/encrypter.js
@@ -33,13 +33,17 @@ Cipher.prototype._update = function (data) {
   return Buffer.concat(out)
 }
 
+var PADDING = Buffer.alloc(16, 0x10)
+
 Cipher.prototype._final = function () {
   var chunk = this._cache.flush()
   if (this._autopadding) {
     chunk = this._mode.encrypt(this, chunk)
     this._cipher.scrub()
     return chunk
-  } else if (chunk.toString('hex') !== '10101010101010101010101010101010') {
+  }
+
+  if (!chunk.equals(PADDING)) {
     this._cipher.scrub()
     throw new Error('data not multiple of block length')
   }
diff --git a/test/index.js b/test/index.js
index 473fbbc..20c45fe 100644
--- a/test/index.js
+++ b/test/index.js
@@ -536,7 +536,7 @@ test('autopadding false cipher throws', function (t) {
 
   t.throws(function () {
     mycipher.final()
-  }, 'mine')
+  }, /data not multiple of block length/)
 
   t.throws(function () {
     nodecipher.final()

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