Add duck-type check for BerWriter in filter#toBer mixin

For #629
This commit is contained in:
Robert Kawecki 2020-07-16 16:10:54 +02:00
parent 3c5138de26
commit b0b5e935c7
1 changed files with 9 additions and 1 deletions

View File

@ -34,9 +34,17 @@ function isFilter (filter) {
return false
}
function isBerWriter (ber) {
return (
typeof (ber) === 'object' &&
typeof (ber.startSequence) === 'function' &&
typeof (ber.endSequence) === 'function'
)
}
function mixin (target) {
target.prototype.toBer = function toBer (ber) {
if (!ber) { throw new TypeError('ber (BerWriter) required') }
if (!ber || !isBerWriter(ber)) { throw new TypeError('ber (BerWriter) required') }
ber.startSequence(TYPES[this.type])
ber = this._toBer(ber)