[Pkg-javascript-commits] [node-asn1.js] 21/202: der: proper encoding of bitstr

Bastien Roucariès rouca at moszumanska.debian.org
Thu Apr 20 19:18:50 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 ef2390a9fd4b27a2805aeaba42d032061b7cd679
Author: Fedor Indutny <fedor.indutny at gmail.com>
Date:   Mon Dec 2 01:37:02 2013 +0400

    der: proper encoding of bitstr
---
 lib/asn1/decoders/der.js | 7 ++++++-
 lib/asn1/encoders/der.js | 6 +++---
 test/ping-pong-test.js   | 4 ++++
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/lib/asn1/decoders/der.js b/lib/asn1/decoders/der.js
index 26943a9..385fb65 100644
--- a/lib/asn1/decoders/der.js
+++ b/lib/asn1/decoders/der.js
@@ -93,7 +93,12 @@ DERNode.prototype._decodeList = function decodeList(buffer, tag, decoder) {
 };
 
 DERNode.prototype._decodeStr = function decodeStr(buffer, tag) {
-  return buffer.raw();
+  if (tag === 'octstr')
+    return buffer.raw();
+  else if (tag === 'bitstr')
+    return { unused: buffer.raw()[0], data: buffer.raw().slice(1) };
+  else
+    assert(0, 'Decoding of string type: ' + tag + ' unsupported');
 };
 
 DERNode.prototype._decodeObjid = function decodeObjid(buffer, values, relative) {
diff --git a/lib/asn1/encoders/der.js b/lib/asn1/encoders/der.js
index 243977a..5d2d064 100644
--- a/lib/asn1/encoders/der.js
+++ b/lib/asn1/encoders/der.js
@@ -62,10 +62,10 @@ DERNode.prototype._encodeComposite = function encodeComposite(tag,
 DERNode.prototype._encodeStr = function encodeStr(str, tag) {
   if (tag === 'octstr')
     return new base.EncoderBuffer(str);
-
-  // TODO(indunty): support first octet
   else if (tag === 'bitstr')
-    return new base.EncoderBuffer(str);
+    return new base.EncoderBuffer([ str.unused | 0, str.data ]);
+  else
+    assert(0, 'Encoding of string type: ' + tag + ' unsupported');
 };
 
 DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) {
diff --git a/test/ping-pong-test.js b/test/ping-pong-test.js
index c5d0cfb..62fbf1f 100644
--- a/test/ping-pong-test.js
+++ b/test/ping-pong-test.js
@@ -27,6 +27,10 @@ describe('asn1.js ping/pong', function() {
       this.octstr();
     }, new Buffer('hello'));
 
+    test('bitstr', function() {
+      this.bitstr();
+    }, { unused: 4, data: new Buffer('hello!') });
+
     test('gentime', function() {
       this.gentime();
     }, 1385921175000);

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