From fce043d6d0261cd7d55f1576d7b4285e2b7c0229 Mon Sep 17 00:00:00 2001 From: Gonzalo Huerta-Canepa Date: Fri, 3 Jan 2014 12:47:42 +0000 Subject: [PATCH 1/2] 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; }; From 737009ee1588e8fbdb65a6060c100970a66e2cc9 Mon Sep 17 00:00:00 2001 From: Gonzalo Huerta-Canepa Date: Fri, 3 Jan 2014 12:58:20 +0000 Subject: [PATCH 2/2] Modified client to allow buffer as a value for exop --- lib/client/client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 = [];