[Pkg-javascript-commits] [node-asn1.js] 70/202: lib: fix implicit seqof encoding
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Apr 20 19:18:55 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 3451e3222bec8a9f15079b2543e8c2de9f6bb1f9
Author: Ilya Petrov <ilya.muromec at gmail.com>
Date: Sat Nov 15 14:58:02 2014 +0700
lib: fix implicit seqof encoding
Following schema encoding is broken:
[0] IMPLICIT SEQOF Attribute
Implicit tag is prepended to wrapping SEQ and to every element
inside it.
Implicit state should be reseted for SEQOF children
---
lib/asn1/base/node.js | 6 +++++-
test/der-encode-test.js | 14 ++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/lib/asn1/base/node.js b/lib/asn1/base/node.js
index 41b9f7a..aa3cdee 100644
--- a/lib/asn1/base/node.js
+++ b/lib/asn1/base/node.js
@@ -490,9 +490,13 @@ Node.prototype._encode = function encode(data, reporter, parent) {
if (!Array.isArray(data))
return reporter.error('seqof/setof, but data is not Array');
+ var child = this.clone();
+ child._baseState.implicit = null;
content = this._createEncoderBuffer(data.map(function(item) {
+ var state = this._baseState;
+
return this._getUse(state.args[0], data)._encode(item, reporter);
- }, this));
+ }, child));
} else if (state.use !== null) {
result = this._getUse(state.use, parent)._encode(data, reporter);
} else {
diff --git a/test/der-encode-test.js b/test/der-encode-test.js
index 69de4eb..8652707 100644
--- a/test/der-encode-test.js
+++ b/test/der-encode-test.js
@@ -35,4 +35,18 @@ describe('asn1.js DER encoder', function() {
});
}, { type: 'apple', value: true }, '0101ff');
+ test('should encode implicit seqof', function() {
+ var Int = asn1.define('Int', function() {
+ this.int();
+ });
+ this.implicit(0).seqof(Int);
+ }, [ 1 ], 'A003020101' );
+
+ test('should encode explicit seqof', function() {
+ var Int = asn1.define('Int', function() {
+ this.int();
+ });
+ this.explicit(0).seqof(Int);
+ }, [ 1 ], 'A0053003020101' );
+
});
--
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