From fce043d6d0261cd7d55f1576d7b4285e2b7c0229 Mon Sep 17 00:00:00 2001 From: Gonzalo Huerta-Canepa Date: Fri, 3 Jan 2014 12:47:42 +0000 Subject: [PATCH] Allow ext request message to have a buffer value in order to accomodate rfc3062 exop --- lib/messages/ext_request.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) 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; };