@@ -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 @@ |
+1
-1
| { | ||
| "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'); | ||
| }); | ||
| }); |
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
82257
1.27%2359
1.55%