Comparing version 4.3.1 to 4.4.0
var Reporter = require('../base').Reporter; | ||
var EncoderBuffer = require('../base').EncoderBuffer; | ||
var DecoderBuffer = require('../base').DecoderBuffer; | ||
var assert = require('minimalistic-assert'); | ||
@@ -15,3 +16,3 @@ | ||
'key', 'obj', 'use', 'optional', 'explicit', 'implicit', 'def', 'choice', | ||
'any' | ||
'any', 'contains' | ||
].concat(tags); | ||
@@ -52,2 +53,3 @@ | ||
state.implicit = null; | ||
state.contains = null; | ||
@@ -257,2 +259,11 @@ // Should create new instance on each method | ||
Node.prototype.contains = function contains(item) { | ||
var state = this._baseState; | ||
assert(state.use === null); | ||
state.contains = item; | ||
return this; | ||
}; | ||
// | ||
@@ -360,2 +371,8 @@ // Decoding | ||
} | ||
// Decode contained/encoded by schema, only in bit or octet strings | ||
if (state.contains && (state.tag === 'octstr' || state.tag === 'bitstr')) { | ||
var data = new DecoderBuffer(result); | ||
result = this._getUse(state.contains, input._reporterState.obj)._decode(data); | ||
} | ||
} | ||
@@ -504,2 +521,5 @@ | ||
result = this._encodeChoice(data, reporter); | ||
} else if (state.contains) { | ||
content = this._getUse(state.contains, parent)._encode(data, reporter); | ||
primitive = true; | ||
} else if (state.children) { | ||
@@ -524,3 +544,2 @@ content = state.children.map(function(child) { | ||
}); | ||
content = this._createEncoderBuffer(content); | ||
@@ -617,2 +636,2 @@ } else { | ||
return /^[A-Za-z0-9 '\(\)\+,\-\.\/:=\?]*$/.test(str); | ||
}; | ||
}; |
{ | ||
"name": "asn1.js", | ||
"version": "4.3.1", | ||
"version": "4.4.0", | ||
"description": "ASN.1 encoder and decoder", | ||
@@ -5,0 +5,0 @@ "main": "lib/asn1.js", |
@@ -93,2 +93,16 @@ var assert = require('assert'); | ||
}, '060a2a830e030a0101010202', 'yes'); | ||
it('should decode encapsulated models', function() { | ||
var B = asn1.define('B', function() { | ||
this.seq().obj( | ||
this.key('nested').int() | ||
); | ||
}); | ||
var A = asn1.define('A', function() { | ||
this.octstr().contains(B); | ||
}); | ||
var out = A.decode(new Buffer('04053003020105', 'hex'), 'der'); | ||
assert.equal(out.nested.toString(10), '5'); | ||
}); | ||
}); |
@@ -103,2 +103,16 @@ var assert = require('assert'); | ||
}, 'Привет', '1e0c041f04400438043204350442'); | ||
it('should encode encapsulated models', function() { | ||
var B = asn1.define('B', function() { | ||
this.seq().obj( | ||
this.key('nested').int() | ||
); | ||
}); | ||
var A = asn1.define('A', function() { | ||
this.octstr().contains(B); | ||
}); | ||
var out = A.encode({ nested: 5 }, 'der') | ||
assert.equal(out.toString('hex'), '04053003020105'); | ||
}); | ||
}); |
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
89109
2537