[Pkg-javascript-commits] [node-asn1.js] 47/202: Fix both explicit and implicit tags for submodel

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 1c30d58fe035bb20d2d394f919af43513992bd48
Author: Ilya Petrov <ilya.muromec at gmail.com>
Date:   Fri Aug 8 18:00:40 2014 +0300

    Fix both explicit and implicit tags for submodel
---
 lib/asn1/base/node.js |  5 +++--
 test/use-test.js      | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/lib/asn1/base/node.js b/lib/asn1/base/node.js
index 25943b6..1707ea4 100644
--- a/lib/asn1/base/node.js
+++ b/lib/asn1/base/node.js
@@ -489,7 +489,7 @@ Node.prototype._encode = function encode(data, reporter) {
           return this._getUse(state.args[0])._encode(item, reporter);
         }, this));
       } else if (state.use !== null) {
-        return this._getUse(state.use)._encode(data, reporter);
+        result = this._getUse(state.use)._encode(data, reporter);
       } else {
         content = this._encodePrimitive(state.tag, data);
         primitive = true;
@@ -509,7 +509,8 @@ Node.prototype._encode = function encode(data, reporter) {
       if (state.use === null)
         reporter.error('Tag could be ommited only for .use()');
     } else {
-      result = this._encodeComposite(tag, primitive, cls, content);
+      if (state.use === null)
+        result = this._encodeComposite(tag, primitive, cls, content);
     }
   }
 
diff --git a/test/use-test.js b/test/use-test.js
index 8827707..dad8999 100644
--- a/test/use-test.js
+++ b/test/use-test.js
@@ -45,6 +45,28 @@ describe('asn1.js models', function() {
       assert.deepEqual(back, data);
 
     });
+
+    it('should honour explicit tag from parent', function() {
+      var SubModel = asn1.define('SubModel', function() {
+        this.seq().obj(
+          this.key('x').octstr()
+        )
+      });
+      var Model = asn1.define('Model', function() {
+        this.seq().obj(
+          this.key('a').int(),
+          this.key('sub').use(SubModel).explicit(0)
+        );
+      });
+
+      var data = {a: 1, sub: {x: new Buffer("123")}};
+      var wire = Model.encode(data, 'der');
+      assert.equal(wire.toString('hex'), '300c020101a00730050403313233');
+      var back = Model.decode(wire, 'der');
+      assert.deepEqual(back, data);
+
+    });
+
   });
 });
 

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