Comparing version 2.1.1 to 2.1.2
@@ -274,11 +274,29 @@ var Reporter = require('../base').Reporter; | ||
if (state.optional) { | ||
present = this._peekTag( | ||
input, | ||
state.explicit !== null ? state.explicit : | ||
state.implicit !== null ? state.implicit : | ||
state.tag || 0, | ||
state.any | ||
); | ||
if (input.isError(present)) | ||
return present; | ||
var tag = null; | ||
if (state.explicit !== null) | ||
tag = state.explicit; | ||
else if (state.implicit !== null) | ||
tag = state.implicit; | ||
else if (state.tag !== null) | ||
tag = state.tag; | ||
if (tag === null && !state.any) { | ||
// Trial and Error | ||
var save = input.save(); | ||
try { | ||
if (state.choice === null) | ||
this._decodeGeneric(state.tag, input); | ||
else | ||
this._decodeChoice(input); | ||
present = true; | ||
} catch (e) { | ||
present = false; | ||
} | ||
input.restore(save); | ||
} else { | ||
present = this._peekTag(input, tag, state.any); | ||
if (input.isError(present)) | ||
return present; | ||
} | ||
} | ||
@@ -285,0 +303,0 @@ |
{ | ||
"name": "asn1.js", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "ASN.1 encoder and decoder", | ||
@@ -5,0 +5,0 @@ "main": "lib/asn1.js", |
@@ -60,2 +60,14 @@ var assert = require('assert'); | ||
it('should decode optional and use', function() { | ||
var B = asn1.define('B', function() { | ||
this.int(); | ||
}); | ||
var A = asn1.define('A', function() { | ||
this.optional().use(B); | ||
}); | ||
var out = A.decode(new Buffer('020101', 'hex'), 'der'); | ||
assert.equal(out.toString(10), '1'); | ||
}); | ||
}); |
@@ -71,2 +71,15 @@ var assert = require('assert'); | ||
}, {required: false, value: 1}, '3003020101'); | ||
it('should encode optional and use', function() { | ||
var B = asn1.define('B', function() { | ||
this.int(); | ||
}); | ||
var A = asn1.define('A', function() { | ||
this.optional().use(B); | ||
}); | ||
var out = A.encode(1, 'der'); | ||
assert.equal(out.toString('hex'), '020101'); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82257
2359