[Pkg-javascript-commits] [node-asn1.js] 106/202: lib: fix choice save/restore bug
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Apr 20 19:18:58 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 91f63791cc1941524e7e3cc45906cd4732bb20b9
Author: Fedor Indutny <fedor at indutny.com>
Date: Thu May 21 23:39:35 2015 +0200
lib: fix choice save/restore bug
* New features in rfc3280/rfc2560
---
lib/asn1/base/buffer.js | 5 +++--
lib/asn1/base/reporter.js | 13 +++++++++++++
lib/asn1/encoders/der.js | 4 ++--
rfc/2560/index.js | 47 +++++++++++++++++++++++++++++++++++++++++----
rfc/3280/index.js | 47 +++++++++++++++++++++++++++++++++++++++++++++
rfc/3280/test/basic-test.js | 12 ++++++++++++
6 files changed, 120 insertions(+), 8 deletions(-)
diff --git a/lib/asn1/base/buffer.js b/lib/asn1/base/buffer.js
index 7b1152f..186efb2 100644
--- a/lib/asn1/base/buffer.js
+++ b/lib/asn1/base/buffer.js
@@ -17,7 +17,7 @@ inherits(DecoderBuffer, Reporter);
exports.DecoderBuffer = DecoderBuffer;
DecoderBuffer.prototype.save = function save() {
- return { offset: this.offset };
+ return { offset: this.offset, reporter: Reporter.prototype.save.call(this) };
};
DecoderBuffer.prototype.restore = function restore(save) {
@@ -27,6 +27,7 @@ DecoderBuffer.prototype.restore = function restore(save) {
res.length = this.offset;
this.offset = save.offset;
+ Reporter.prototype.restore.call(this, save.reporter);
return res;
};
@@ -65,7 +66,7 @@ function EncoderBuffer(value, reporter) {
if (Array.isArray(value)) {
this.length = 0;
this.value = value.map(function(item) {
- if (!(item instanceof EncoderBuffer))
+ if (!item || item.constructor.name !== 'EncoderBuffer')
item = new EncoderBuffer(item, reporter);
this.length += item.length;
return item;
diff --git a/lib/asn1/base/reporter.js b/lib/asn1/base/reporter.js
index 7f02190..e0a8e89 100644
--- a/lib/asn1/base/reporter.js
+++ b/lib/asn1/base/reporter.js
@@ -14,6 +14,19 @@ Reporter.prototype.isError = function isError(obj) {
return obj instanceof ReporterError;
};
+Reporter.prototype.save = function save() {
+ var state = this._reporterState;
+
+ return { obj: state.obj, pathLen: state.path.length };
+};
+
+Reporter.prototype.restore = function restore(data) {
+ var state = this._reporterState;
+
+ state.obj = data.obj;
+ state.path = state.path.slice(0, data.pathLen);
+};
+
Reporter.prototype.enterKey = function enterKey(key) {
return this._reporterState.path.push(key);
};
diff --git a/lib/asn1/encoders/der.js b/lib/asn1/encoders/der.js
index dd0462c..0f6784d 100644
--- a/lib/asn1/encoders/der.js
+++ b/lib/asn1/encoders/der.js
@@ -169,9 +169,9 @@ DERNode.prototype._encodeInt = function encodeInt(num, values) {
}
// Bignum, assume big endian
- if (bignum !== null && num instanceof bignum) {
+ if (typeof num !== 'number' && !Buffer.isBuffer(num)) {
var numArray = num.toArray();
- if(num.sign === false && numArray[0] & 0x80) {
+ if (num.sign === false && numArray[0] & 0x80) {
numArray.unshift(0);
}
num = new Buffer(numArray);
diff --git a/rfc/2560/index.js b/rfc/2560/index.js
index f7b988c..ef26310 100644
--- a/rfc/2560/index.js
+++ b/rfc/2560/index.js
@@ -6,6 +6,42 @@ try {
var rfc3280 = require('../' + '3280');
}
+var OCSPRequest = asn1.define('OCSPRequest', function() {
+ this.seq().obj(
+ this.key('tbsRequest').use(TBSRequest),
+ this.key('optionalSignature').optional().explicit(0).use(Signature)
+ );
+});
+exports.OCSPRequest = OCSPRequest;
+
+var TBSRequest = asn1.define('TBSRequest', function() {
+ this.seq().obj(
+ this.key('version').def('v1').explicit(0).use(rfc3280.Version),
+ this.key('requestorName').optional().explicit(1).use(rfc3280.GeneralName),
+ this.key('requestList').seqof(Request),
+ this.key('requestExtensions').optional().explicit(2).use(rfc3280.Extensions)
+ );
+});
+exports.TBSRequest = TBSRequest;
+
+var Signature = asn1.define('Signature', function() {
+ this.seq().obj(
+ this.key('signatureAlgorithm').use(rfc3280.AlgorithmIdentifier),
+ this.key('signature').bitstr(),
+ this.key('certs').optional().explicit(0).seqof(rfc3280.Certificate)
+ );
+});
+exports.Signature = Signature;
+
+var Request = asn1.define('Request', function() {
+ this.seq().obj(
+ this.key('reqCert').use(CertID),
+ this.key('singleRequestExtensions').optional().explicit(0).use(
+ rfc3280.Extensions)
+ );
+});
+exports.Request = Request;
+
var OCSPResponse = asn1.define('OCSPResponse', function() {
this.seq().obj(
this.key('responseStatus').use(ResponseStatus),
@@ -72,7 +108,7 @@ var SingleResponse = asn1.define('SingleResponse', function() {
this.key('certStatus').use(CertStatus),
this.key('thisUpdate').gentime(),
this.key('nextUpdate').optional().explicit(0).gentime(),
- this.key('singleExtensions').optional().explicit(1).use(Extensions)
+ this.key('singleExtensions').optional().explicit(1).use(rfc3280.Extensions)
);
});
exports.SingleResponse = SingleResponse;
@@ -104,7 +140,10 @@ var CertID = asn1.define('CertID', function() {
});
exports.CertID = CertID;
-var Extensions = asn1.define('Extensions', function() {
- this.any();
+var Nonce = asn1.define('Nonce', function() {
+ this.octstr();
});
-exports.Extensions = Extensions;
+exports.Nonce = Nonce;
+
+exports['id-pkix-ocsp'] = [ 1, 3, 6, 1, 5, 5, 7, 48, 1 ];
+exports['id-pkix-ocsp-nonce'] = [ 1, 3, 6, 1, 5, 5, 7, 48, 1, 2 ];
diff --git a/rfc/3280/index.js b/rfc/3280/index.js
index 64f6ec3..c4f3c6c 100644
--- a/rfc/3280/index.js
+++ b/rfc/3280/index.js
@@ -150,3 +150,50 @@ var AttributeValue = asn1.define('AttributeValue', function() {
this.any();
});
exports.AttributeValue = AttributeValue;
+
+var GeneralNames = asn1.define('GeneralNames', function() {
+ this.seqof(GeneralName);
+});
+exports.GeneralNames = GeneralNames;
+
+var GeneralName = asn1.define('GeneralName', function() {
+ return this.choice({
+ otherName: this.implicit(0).use(AnotherName),
+ rfc822Name: this.implicit(1).ia5str(),
+ dNSName: this.implicit(2).ia5str(),
+ directoryName: this.implicit(4).use(Name),
+
+ // TODO(indutny): requires DirectoryString, ORAddress
+ // ediPartyName: this.implicit(5).use(EDIPartyName),
+ // x400Address: this.implicit(3).use(ORAddress),
+
+ uniformResourceIdentifier: this.implicit(6).ia5str(),
+ iPAddress: this.implicit(7).octstr(),
+ registeredID: this.implicit(8).objid()
+ });
+});
+exports.GeneralName = GeneralName;
+
+var AnotherName = asn1.define('AnotherName', function() {
+ return this.seq().obj(
+ this.key('type-id').objid(),
+ this.key('value').explicit(0).any()
+ );
+});
+exports.AnotherName = AnotherName;
+
+exports['id-pe-authorityInfoAccess'] = [ 1, 3, 6, 1, 5, 5, 7, 1, 1];
+
+var AuthorityInfoAccessSyntax = asn1.define('AuthorityInfoAccessSyntax',
+ function() {
+ this.seqof(AccessDescription);
+});
+exports.AuthorityInfoAccessSyntax = AuthorityInfoAccessSyntax;
+
+var AccessDescription = asn1.define('AccessDescription', function() {
+ this.seq().obj(
+ this.key('accessMethod').objid(),
+ this.key('accessLocation').use(GeneralName)
+ );
+});
+exports.AccessDescription = AccessDescription;
diff --git a/rfc/3280/test/basic-test.js b/rfc/3280/test/basic-test.js
index 0b891dc..f17e0fe 100644
--- a/rfc/3280/test/basic-test.js
+++ b/rfc/3280/test/basic-test.js
@@ -107,4 +107,16 @@ describe('asn1.js RFC3280', function() {
'Mm4g=='
);
});
+
+ it('should decode AuthorityInfoAccess', function() {
+ var data = new Buffer('305a302b06082b06010505073002861f687474703a2f2f70' +
+ '6b692e676f6f676c652e636f6d2f47494147322e63727430' +
+ '2b06082b06010505073001861f687474703a2f2f636c6965' +
+ '6e7473312e676f6f676c652e636f6d2f6f637370',
+ 'hex');
+
+ var info = rfc3280.AuthorityInfoAccessSyntax.decode(data, 'der');
+
+ assert(info[0].accessMethod);
+ });
});
--
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