[Pkg-javascript-commits] [node-asn1.js] 156/202: api: default to DER

Bastien Roucariès rouca at moszumanska.debian.org
Thu Apr 20 19:19:03 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 82e83b96a1ecc7431a24674b9e36f64c69d8277e
Author: felix <felix at userspace.com.au>
Date:   Fri Oct 16 13:53:09 2015 +0700

    api: default to DER
---
 lib/asn1/api.js         |  2 ++
 test/der-decode-test.js | 11 +++++++++++
 test/der-encode-test.js | 11 +++++++++++
 3 files changed, 24 insertions(+)

diff --git a/lib/asn1/api.js b/lib/asn1/api.js
index 0e8a201..7c223cc 100644
--- a/lib/asn1/api.js
+++ b/lib/asn1/api.js
@@ -37,6 +37,7 @@ Entity.prototype._createNamed = function createNamed(base) {
 };
 
 Entity.prototype._getDecoder = function _getDecoder(enc) {
+  enc = enc || 'der';
   // Lazily create decoder
   if (!this.decoders.hasOwnProperty(enc))
     this.decoders[enc] = this._createNamed(asn1.decoders[enc]);
@@ -48,6 +49,7 @@ Entity.prototype.decode = function decode(data, enc, options) {
 };
 
 Entity.prototype._getEncoder = function _getEncoder(enc) {
+  enc = enc || 'der';
   // Lazily create encoder
   if (!this.encoders.hasOwnProperty(enc))
     this.encoders[enc] = this._createNamed(asn1.encoders[enc]);
diff --git a/test/der-decode-test.js b/test/der-decode-test.js
index 0f1ad86..ee4e4fd 100644
--- a/test/der-decode-test.js
+++ b/test/der-decode-test.js
@@ -146,4 +146,15 @@ describe('asn1.js DER decoder', function() {
     assert.equal(out.test1[1].num.toString(10), 2);
     assert.equal(out.test2, undefined);
   });
+
+  it('should not require decoder param', function() {
+     var M = asn1.define('Model', function() {
+       this.choice({
+         apple: this.bool(),
+       });
+     });
+     // Note no decoder specified, defaults to 'der'
+     var decoded = M.decode(new Buffer('0101ff', 'hex'));
+     assert.deepEqual(decoded, { 'type': 'apple', 'value': true });
+  });
 });
diff --git a/test/der-encode-test.js b/test/der-encode-test.js
index af37293..c089267 100644
--- a/test/der-encode-test.js
+++ b/test/der-encode-test.js
@@ -130,4 +130,15 @@ describe('asn1.js DER encoder', function() {
   test('should properly encode ISO646 string', function() {
     this.iso646str();
   }, 'septic tank', '1A0B7365707469632074616E6B');
+
+  it('should not require encoder param', function() {
+     var M = asn1.define('Model', function() {
+       this.choice({
+         apple: this.bool(),
+       });
+     });
+     // Note no encoder specified, defaults to 'der'
+     var encoded = M.encode({ 'type': 'apple', 'value': true });
+     assert.deepEqual(encoded, new Buffer('0101ff', 'hex'));
+  });
 });

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