[Pkg-javascript-commits] [node-asn1.js] 42/202: deps: use bn.js

Bastien Roucariès rouca at moszumanska.debian.org
Thu Apr 20 19:18:52 UTC 2017


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

rouca pushed a commit to branch master
in repository node-asn1.js.

commit 832399848e97c782f0a05378bef56f4e4b499726
Author: Fedor Indutny <fedor at indutny.com>
Date:   Fri Aug 15 23:05:19 2014 +0400

    deps: use bn.js
---
 lib/asn1.js              |  7 +------
 lib/asn1/decoders/der.js |  7 ++-----
 lib/asn1/encoders/der.js |  2 +-
 package.json             |  2 +-
 test/ping-pong-test.js   | 12 +++---------
 5 files changed, 8 insertions(+), 22 deletions(-)

diff --git a/lib/asn1.js b/lib/asn1.js
index 660848f..02bbdc1 100644
--- a/lib/asn1.js
+++ b/lib/asn1.js
@@ -1,11 +1,6 @@
 var asn1 = exports;
 
-// Optional bignum
-try {
-  asn1.bignum = require('bignum');
-} catch (e) {
-  asn1.bignum = null;
-}
+asn1.bignum = require('bn.js');
 
 asn1.define = require('./asn1/api').define;
 asn1.base = require('./asn1/base');
diff --git a/lib/asn1/decoders/der.js b/lib/asn1/decoders/der.js
index 3c86697..bd0a011 100644
--- a/lib/asn1/decoders/der.js
+++ b/lib/asn1/decoders/der.js
@@ -207,11 +207,8 @@ DERNode.prototype._decodeInt = function decodeInt(buffer, values) {
 
   // Bigint, return as it is (assume big endian)
   var raw = buffer.raw();
-  if (raw.length > 3) {
-    if (bignum !== null)
-      raw = bignum.fromBuffer(raw, { endian: 'big' });
-    return raw;
-  }
+  if (raw.length > 3)
+    return new bignum(raw);
 
   while (!buffer.isEmpty()) {
     res <<= 8;
diff --git a/lib/asn1/encoders/der.js b/lib/asn1/encoders/der.js
index c8424ed..bf9b6f4 100644
--- a/lib/asn1/encoders/der.js
+++ b/lib/asn1/encoders/der.js
@@ -166,7 +166,7 @@ DERNode.prototype._encodeInt = function encodeInt(num, values) {
 
   // Bignum, assume big endian
   if (bignum !== null && num instanceof bignum)
-    num = num.toBuffer({ endian: 'big' });
+    num = new Buffer(num.toArray());
 
   if (Buffer.isBuffer(num)) {
     var size = num.length;
diff --git a/package.json b/package.json
index 9979c32..696494f 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,6 @@
     "mocha": "~1.14.0"
   },
   "optionalDependencies": {
-    "bignum": "~0.6.2"
+    "bn.js": "~0.13.3"
   }
 }
diff --git a/test/ping-pong-test.js b/test/ping-pong-test.js
index cadf1cd..5d22ff1 100644
--- a/test/ping-pong-test.js
+++ b/test/ping-pong-test.js
@@ -19,15 +19,9 @@ describe('asn1.js ping/pong', function() {
       this.int();
     }, 0);
 
-    if (asn1.bignum !== null) {
-      test('bigint', function() {
-        this.int();
-      }, new asn1.bignum('0102030405060708', 16));
-    } else {
-      test('bigint', function() {
-        this.int();
-      }, new Buffer('0102030405060708', 'hex'));
-    }
+    test('bigint', function() {
+      this.int();
+    }, new asn1.bignum('0102030405060708', 16));
 
     test('enum', function() {
       this.enum({ 0: 'hello', 1: 'world' });

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



More information about the Pkg-javascript-commits mailing list