[Pkg-javascript-commits] [node-asn1.js] 02/202: der: support indefinite length

Bastien Roucariès rouca at moszumanska.debian.org
Thu Apr 20 19:18:48 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 f76f9a3aeb4ef9486f56d203e62b0aad6f7a8c34
Author: Fedor Indutny <fedor.indutny at gmail.com>
Date:   Sun Dec 1 17:02:29 2013 +0400

    der: support indefinite length
---
 lib/asn1/base/buffer.js  |  7 +++++++
 lib/asn1/base/node.js    |  2 +-
 lib/asn1/decoders/der.js | 31 ++++++++++++++++++++++++++++---
 3 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/lib/asn1/base/buffer.js b/lib/asn1/base/buffer.js
index 2c484e2..bab837f 100644
--- a/lib/asn1/base/buffer.js
+++ b/lib/asn1/base/buffer.js
@@ -15,7 +15,14 @@ DecoderBuffer.prototype.save = function save() {
 };
 
 DecoderBuffer.prototype.restore = function restore(save) {
+  // Return skipped data
+  var res = new DecoderBuffer(this.base);
+  res.offset = save.offset;
+  res.length = this.offset;
+
   this.offset = save.offset;
+
+  return res;
 };
 
 DecoderBuffer.prototype.isEmpty = function isEmpty() {
diff --git a/lib/asn1/base/node.js b/lib/asn1/base/node.js
index da081f6..d7d8a59 100644
--- a/lib/asn1/base/node.js
+++ b/lib/asn1/base/node.js
@@ -178,7 +178,7 @@ Node.prototype._execChoice = function execChoice(input, obj) {
     var save = input.save();
     var node = state.choice[key];
     try {
-      result = node._exec(input, obj);
+      result = { type: key, value: node._exec(input, obj) };
       match = true;
     } catch (e) {
       input.restore(save);
diff --git a/lib/asn1/decoders/der.js b/lib/asn1/decoders/der.js
index 59e8c83..5ef28e8 100644
--- a/lib/asn1/decoders/der.js
+++ b/lib/asn1/decoders/der.js
@@ -54,13 +54,38 @@ DERNode.prototype._execTag = function execTag(buffer, tag, any) {
   if (decodedTag.primitive || len !== null)
     return buffer.skip(len);
 
-  assert(0, 'Indefinite length not implemented yet');
+  // Indefinite length... find END tag
+  var state = buffer.save();
+  this._skipUntilEnd(buffer);
+  return buffer.restore(state);
+};
+
+DERNode.prototype._skipUntilEnd = function skipUntilEnd(buffer) {
+  while (true) {
+    var tag = decodeTag(buffer);
+    var len = decodeLen(buffer, tag.primitive);
+
+    if (tag.primitive || len !== null)
+      buffer.skip(len)
+    else
+      this._skipUntilEnd(buffer);
+
+    if (tag.tagStr === 'end')
+      break;
+  }
 };
 
 DERNode.prototype._execOf = function execOf(buffer, tag, decoder) {
   var result = [];
-  while (!buffer.isEmpty())
-    result.push(decoder.decode(buffer, 'der'));
+  while (!buffer.isEmpty()) {
+    try {
+      var possibleEnd = this._peekTag(buffer, 'end');
+      result.push(decoder.decode(buffer, 'der'));
+    } catch (e) {
+      if (possibleEnd)
+        break;
+    }
+  }
   return result;
 };
 

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