[Pkg-javascript-commits] [node-asn1.js] 08/202: base: fix .use() encoding

Bastien Roucariès rouca at moszumanska.debian.org
Thu Apr 20 19:18:49 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 696f68a9cbd358647681f8c69c639b66fec1e670
Author: Fedor Indutny <fedor.indutny at gmail.com>
Date:   Sun Dec 1 23:06:57 2013 +0400

    base: fix .use() encoding
---
 lib/asn1/base/node.js       | 13 +++++++------
 lib/asn1/decoders/der.js    |  1 -
 lib/asn1/encoders/der.js    |  7 +++++--
 rfc/2560/test/basic-test.js | 14 ++++++++++++++
 4 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/lib/asn1/base/node.js b/lib/asn1/base/node.js
index 7686fda..f4945b2 100644
--- a/lib/asn1/base/node.js
+++ b/lib/asn1/base/node.js
@@ -403,7 +403,7 @@ Node.prototype._encode = function encode(data) {
           return this._use(state.args[0], item);
         }, this));
       } else if (state.use !== null) {
-        content = this._use(state.use, data);
+        result = this._use(state.use, data);
       } else {
         content = this._encodePrimitive(state.tag, data);
         primitive = true;
@@ -416,11 +416,12 @@ Node.prototype._encode = function encode(data) {
   // Encode data itself
   var result;
   if (!state.any && state.choice === null) {
-    result = this._encodeComposite(
-      state.implicit !== null ? state.implicit : state.tag,
-      primitive,
-      content
-    );
+    var tag = state.implicit !== null ? state.implicit : state.tag;
+
+    if (tag === null)
+      assert(state.use !== null, 'Tag could be ommited only for .use()');
+    else
+      result = this._encodeComposite(tag, primitive, content);
   }
 
   // Wrap in explicit
diff --git a/lib/asn1/decoders/der.js b/lib/asn1/decoders/der.js
index f21359e..852b140 100644
--- a/lib/asn1/decoders/der.js
+++ b/lib/asn1/decoders/der.js
@@ -22,7 +22,6 @@ DERDecoder.prototype.decode = function decode(data) {
   if (!(data instanceof base.DecoderBuffer))
     data = new base.DecoderBuffer(data);
 
-  debugger;
   return this.tree._decode(data);
 };
 
diff --git a/lib/asn1/encoders/der.js b/lib/asn1/encoders/der.js
index cc72d4e..5e0063f 100644
--- a/lib/asn1/encoders/der.js
+++ b/lib/asn1/encoders/der.js
@@ -144,6 +144,9 @@ DERNode.prototype._encodeInt = function encodeInt(num, values) {
     num = values[num];
   }
 
+  if (num < 0x100)
+    return new base.EncoderBuffer(num);
+
   var size = 1;
   for (var i = num; i >= 0x100; i >>= 8)
     size++;
@@ -184,10 +187,10 @@ function encodeTag(tag, primitive, cls) {
 
   assert(res < 0x1f, 'Multi-octet tag encoding unsupported');
 
-  if (primitive)
+  if (!primitive)
     res |= 0x20;
 
-  res |= der.tagClassByName[cls || 'universal'];
+  res |= (der.tagClassByName[cls || 'universal'] << 6);
 
   return res;
 }
diff --git a/rfc/2560/test/basic-test.js b/rfc/2560/test/basic-test.js
index 88d1cb1..b8a6005 100644
--- a/rfc/2560/test/basic-test.js
+++ b/rfc/2560/test/basic-test.js
@@ -33,4 +33,18 @@ describe('asn1.js RFC2560', function() {
     assert.equal(basic.tbsResponseData.version, 'v1');
     assert.equal(basic.tbsResponseData.producedAt, 1385797510000);
   });
+
+  it('should encode/decode OCSP response', function() {
+    var encoded = rfc2560.OCSPResponse.encode({
+      responseStatus: 'malformed_request',
+      responseBytes: {
+        responseType: 'id-pkix-ocsp-basic',
+        response: 'random-string'
+      }
+    }, 'der');
+    var decoded = rfc2560.OCSPResponse.decode(encoded, 'der');
+    assert.equal(decoded.responseStatus, 'malformed_request');
+    assert.equal(decoded.responseBytes.responseType, 'id-pkix-ocsp-basic');
+    assert.equal(decoded.responseBytes.response.toString(), 'random-string');
+  });
 });

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