diff --git a/lib/client/client.js b/lib/client/client.js index a765735..6dc9cde 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -454,8 +454,8 @@ Client.prototype.exop = function exop(name, value, controls, callback) { controls = []; value = ''; } - if (typeof (value) !== 'string') - throw new TypeError('value (string) required'); + if (!(Buffer.isBuffer(value) || typeof (value) === 'string')) + throw new TypeError('value (Buffer || string) required'); if (typeof (controls) === 'function') { callback = controls; controls = []; diff --git a/lib/messages/ext_request.js b/lib/messages/ext_request.js index 0329cdc..6147279 100644 --- a/lib/messages/ext_request.js +++ b/lib/messages/ext_request.js @@ -27,8 +27,8 @@ function ExtendedRequest(options) { throw new TypeError('options must be an object'); if (options.requestName && typeof (options.requestName) !== 'string') throw new TypeError('options.requestName must be a string'); - if (options.requestValue && typeof (options.requestValue) !== 'string') - throw new TypeError('options.requestValue must be a string'); + if (options.requestValue && !(Buffer.isBuffer(options.requestValue) || typeof (options.requestValue) === 'string')) + throw new TypeError('options.requestValue must be a buffer or a string'); } else { options = {}; } @@ -54,8 +54,8 @@ function ExtendedRequest(options) { this.requestName = name; }); this.__defineSetter__('value', function (val) { - if (typeof (val) !== 'string') - throw new TypeError('value must be a string'); + if (!(Buffer.isBuffer(val) || typeof (val) === 'string')) + throw new TypeError('value must be a buffer or a string'); this.requestValue = val; }); @@ -69,7 +69,11 @@ ExtendedRequest.prototype._parse = function (ber) { this.requestName = ber.readString(0x80); if (ber.peek() === 0x81) - this.requestValue = ber.readString(0x81); + try { + this.requestValue = ber.readString(0x81); + } catch (e) { + this.requestValue = ber.readBuffer(0x81); + } return true; }; @@ -79,7 +83,9 @@ ExtendedRequest.prototype._toBer = function (ber) { assert.ok(ber); ber.writeString(this.requestName, 0x80); - if (this.requestValue) + if (Buffer.isBuffer(this.requestValue)) + ber.writeBuffer(this.requestValue, 0x81); + else ber.writeString(this.requestValue, 0x81); return ber; @@ -90,7 +96,7 @@ ExtendedRequest.prototype._json = function (j) { assert.ok(j); j.requestName = this.requestName; - j.requestValue = this.requestValue; + j.requestValue = (Buffer.isBuffer(this.requestValue)) ? this.requestValue.toString('hex') : this.requestValue; return j; };