[Pkg-javascript-commits] [node-asn1.js] 36/202: node: use context-specific class for explicit

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 9380a7ba16a6d719d3c1170392efd2baa7ce9405
Author: Ilya Petrov <ilya.muromec at gmail.com>
Date:   Fri May 30 23:51:23 2014 +0300

    node: use context-specific class for explicit
    
    Explicit tag should be coded as 0xA0 | tag.
    
    Signed-off-by: Fedor Indutny <fedor at indutny.com>
---
 lib/asn1/base/node.js    |  4 ++--
 lib/asn1/encoders/der.js |  3 ++-
 test/der-encode-test.js  | 22 ++++++++++++++++++++++
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/lib/asn1/base/node.js b/lib/asn1/base/node.js
index a8e075e..dbfe2a5 100644
--- a/lib/asn1/base/node.js
+++ b/lib/asn1/base/node.js
@@ -475,13 +475,13 @@ 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, content);
+      result = this._encodeComposite(tag, primitive, 'universal', content);
     }
   }
 
   // Wrap in explicit
   if (state.explicit !== null)
-    result = this._encodeComposite(state.explicit, false, result);
+    result = this._encodeComposite(state.explicit, false, 'context', result);
 
   return result;
 };
diff --git a/lib/asn1/encoders/der.js b/lib/asn1/encoders/der.js
index 203b34e..68b7ca6 100644
--- a/lib/asn1/encoders/der.js
+++ b/lib/asn1/encoders/der.js
@@ -32,8 +32,9 @@ util.inherits(DERNode, base.Node);
 
 DERNode.prototype._encodeComposite = function encodeComposite(tag,
                                                               primitive,
+                                                              cls,
                                                               content) {
-  var encodedTag = encodeTag(tag, primitive, this.reporter);
+  var encodedTag = encodeTag(tag, primitive, cls, this.reporter);
 
   // Short form
   if (content.length < 0x80) {
diff --git a/test/der-encode-test.js b/test/der-encode-test.js
new file mode 100644
index 0000000..f30ab65
--- /dev/null
+++ b/test/der-encode-test.js
@@ -0,0 +1,22 @@
+var assert = require('assert');
+var asn1 = require('..');
+
+var Buffer = require('buffer').Buffer;
+
+describe('asn1.js DER encoder', function() {
+  /*
+   * Explicit value shold be wrapped with A0 | EXPLICIT tag
+   * this adds two more bytes to resulting buffer.
+   * */
+  it('should code explicit tag as 0xA2', function() {
+    var E = asn1.define('E', function() {
+      this.explicit(2).octstr()
+    });
+
+    var encoded = E.encode('X', 'der');
+
+    // <Explicit tag> <wrapped len> <str tag> <len> <payload>
+    assert.equal(encoded.toString('hex'), 'a203040158');
+    assert.equal(encoded.length, 5);
+  })
+});

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