[Pkg-javascript-commits] [node-asn1.js] 150/202: der: fix peekTag's check for seqof and setof
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Apr 20 19:19:03 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 20069c768471d3915df1151c33f0899cdbe7cb61
Author: Felix Hanley <felix at userspace.com.au>
Date: Thu Feb 18 13:03:25 2016 +0700
der: fix peekTag's check for seqof and setof
---
lib/asn1/decoders/der.js | 3 ++-
test/der-decode-test.js | 26 ++++++++++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/lib/asn1/decoders/der.js b/lib/asn1/decoders/der.js
index 9acace6..92d892d 100644
--- a/lib/asn1/decoders/der.js
+++ b/lib/asn1/decoders/der.js
@@ -43,7 +43,8 @@ DERNode.prototype._peekTag = function peekTag(buffer, tag, any) {
buffer.restore(state);
- return decodedTag.tag === tag || decodedTag.tagStr === tag || any;
+ return decodedTag.tag === tag || decodedTag.tagStr === tag ||
+ (decodedTag.tagStr + 'of') === tag || any;
};
DERNode.prototype._decodeTag = function decodeTag(buffer, tag, any) {
diff --git a/test/der-decode-test.js b/test/der-decode-test.js
index 3eba72e..0f1ad86 100644
--- a/test/der-decode-test.js
+++ b/test/der-decode-test.js
@@ -120,4 +120,30 @@ describe('asn1.js DER decoder', function() {
test('should decode ISO646 string', function() {
this.iso646str();
}, '1A0B7365707469632074616E6B', 'septic tank');
+
+ it('should decode optional seqof', function() {
+ var B = asn1.define('B', function() {
+ this.seq().obj(
+ this.key('num').int()
+ );
+ });
+ var A = asn1.define('A', function() {
+ this.seq().obj(
+ this.key('test1').seqof(B),
+ this.key('test2').optional().seqof(B)
+ );
+ });
+
+ var out = A.decode(new Buffer(
+ '3018300A30030201013003020102300A30030201033003020104', 'hex'), 'der');
+ assert.equal(out.test1[0].num.toString(10), 1);
+ assert.equal(out.test1[1].num.toString(10), 2);
+ assert.equal(out.test2[0].num.toString(10), 3);
+ assert.equal(out.test2[1].num.toString(10), 4);
+
+ out = A.decode(new Buffer('300C300A30030201013003020102', 'hex'), 'der');
+ assert.equal(out.test1[0].num.toString(10), 1);
+ assert.equal(out.test1[1].num.toString(10), 2);
+ assert.equal(out.test2, undefined);
+ });
});
--
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