[Pkg-javascript-commits] [node-asn1.js] 29/202: decoder: fix .any() support
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Apr 20 19:18:51 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 86f7518c612708aecf7a996e5433cca934b371bb
Author: Fedor Indutny <fedor.indutny at gmail.com>
Date: Sun Jan 19 20:46:49 2014 +0000
decoder: fix .any() support
---
lib/asn1/base/buffer.js | 4 ++--
lib/asn1/base/node.js | 13 ++++++++++---
lib/asn1/decoders/der.js | 17 +++++++++++------
test/ping-pong-test.js | 3 ++-
4 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/lib/asn1/base/buffer.js b/lib/asn1/base/buffer.js
index 524b545..81a8405 100644
--- a/lib/asn1/base/buffer.js
+++ b/lib/asn1/base/buffer.js
@@ -58,8 +58,8 @@ DecoderBuffer.prototype.skip = function skip(bytes, fail) {
return res;
}
-DecoderBuffer.prototype.raw = function raw() {
- return this.base.slice(this.offset, this.length);
+DecoderBuffer.prototype.raw = function raw(save) {
+ return this.base.slice(save ? save.offset : this.offset, this.length);
}
function EncoderBuffer(value, reporter) {
diff --git a/lib/asn1/base/node.js b/lib/asn1/base/node.js
index cb18394..a8e075e 100644
--- a/lib/asn1/base/node.js
+++ b/lib/asn1/base/node.js
@@ -278,7 +278,9 @@ Node.prototype._decode = function decode(input) {
}
// Unwrap implicit and normal values
- if (state.use === null && !state.any && state.choice === null) {
+ if (state.use === null && state.choice === null) {
+ if (state.any)
+ var save = input.save();
var body = this._decodeTag(
input,
state.implicit !== null ? state.implicit : state.tag,
@@ -286,16 +288,21 @@ Node.prototype._decode = function decode(input) {
);
if (input.isError(body))
return body;
- input = body;
+
+ if (state.any)
+ result = input.raw(save);
+ else
+ input = body;
}
// Select proper method for tag
if (state.any)
- result = input.raw();
+ result = result;
else if (state.choice === null)
result = this._decodeGeneric(state.tag, input);
else
result = this._decodeChoice(input);
+
if (input.isError(result))
return result;
diff --git a/lib/asn1/decoders/der.js b/lib/asn1/decoders/der.js
index 5699c6d..b90f2a8 100644
--- a/lib/asn1/decoders/der.js
+++ b/lib/asn1/decoders/der.js
@@ -70,14 +70,14 @@ DERNode.prototype._decodeTag = function decodeTag(buffer, tag, any) {
return buffer.skip(len, 'Failed to match body of: "' + tag + '"');
// Indefinite length... find END tag
- var state = buffer.save();
+ var state = buffer.start();
var res = this._skipUntilEnd(
buffer,
'Failed to skip indefinite length body: "' + this.tag + '"');
if (buffer.isError(res))
return res;
- return buffer.restore(state);
+ return buffer.cut(state);
};
DERNode.prototype._skipUntilEnd = function skipUntilEnd(buffer, fail) {
@@ -120,12 +120,17 @@ DERNode.prototype._decodeList = function decodeList(buffer, tag, decoder) {
};
DERNode.prototype._decodeStr = function decodeStr(buffer, tag) {
- if (tag === 'octstr')
+ if (tag === 'octstr') {
return buffer.raw();
- else if (tag === 'bitstr')
- return { unused: buffer.raw()[0], data: buffer.raw().slice(1) };
- else
+ } else if (tag === 'bitstr') {
+ var unused = buffer.readUInt8();
+ if (buffer.isError(unused))
+ return unused;
+
+ return { unused: unused, data: buffer.raw() };
+ } else {
return this.error('Decoding of string type: ' + tag + ' unsupported');
+ }
};
DERNode.prototype._decodeObjid = function decodeObjid(buffer, values, relative) {
diff --git a/test/ping-pong-test.js b/test/ping-pong-test.js
index 62fbf1f..8537096 100644
--- a/test/ping-pong-test.js
+++ b/test/ping-pong-test.js
@@ -59,7 +59,8 @@ describe('asn1.js ping/pong', function() {
test('any', function() {
this.any();
- }, new Buffer('ok any'));
+ }, new Buffer('02210081347a0d3d674aeeb563061d94a3aea5f6a7' +
+ 'c6dc153ea90a42c1ca41929ac1b9', 'hex'));
test('default explicit', function() {
this.def('v1').explicit(0).int({
--
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