Merge pull request #159 from gfhuertac/master

Allow ext request message to have a buffer value
This commit is contained in:
Mark Cavage 2014-01-16 07:41:57 -08:00
commit 2f1b0790f6
2 changed files with 15 additions and 9 deletions

View File

@ -454,8 +454,8 @@ Client.prototype.exop = function exop(name, value, controls, callback) {
controls = []; controls = [];
value = ''; value = '';
} }
if (typeof (value) !== 'string') if (!(Buffer.isBuffer(value) || typeof (value) === 'string'))
throw new TypeError('value (string) required'); throw new TypeError('value (Buffer || string) required');
if (typeof (controls) === 'function') { if (typeof (controls) === 'function') {
callback = controls; callback = controls;
controls = []; controls = [];

View File

@ -27,8 +27,8 @@ function ExtendedRequest(options) {
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
if (options.requestName && typeof (options.requestName) !== 'string') if (options.requestName && typeof (options.requestName) !== 'string')
throw new TypeError('options.requestName must be a string'); throw new TypeError('options.requestName must be a string');
if (options.requestValue && typeof (options.requestValue) !== 'string') if (options.requestValue && !(Buffer.isBuffer(options.requestValue) || typeof (options.requestValue) === 'string'))
throw new TypeError('options.requestValue must be a string'); throw new TypeError('options.requestValue must be a buffer or a string');
} else { } else {
options = {}; options = {};
} }
@ -54,8 +54,8 @@ function ExtendedRequest(options) {
this.requestName = name; this.requestName = name;
}); });
this.__defineSetter__('value', function (val) { this.__defineSetter__('value', function (val) {
if (typeof (val) !== 'string') if (!(Buffer.isBuffer(val) || typeof (val) === 'string'))
throw new TypeError('value must be a string'); throw new TypeError('value must be a buffer or a string');
this.requestValue = val; this.requestValue = val;
}); });
@ -69,7 +69,11 @@ ExtendedRequest.prototype._parse = function (ber) {
this.requestName = ber.readString(0x80); this.requestName = ber.readString(0x80);
if (ber.peek() === 0x81) if (ber.peek() === 0x81)
this.requestValue = ber.readString(0x81); try {
this.requestValue = ber.readString(0x81);
} catch (e) {
this.requestValue = ber.readBuffer(0x81);
}
return true; return true;
}; };
@ -79,7 +83,9 @@ ExtendedRequest.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeString(this.requestName, 0x80); ber.writeString(this.requestName, 0x80);
if (this.requestValue) if (Buffer.isBuffer(this.requestValue))
ber.writeBuffer(this.requestValue, 0x81);
else
ber.writeString(this.requestValue, 0x81); ber.writeString(this.requestValue, 0x81);
return ber; return ber;
@ -90,7 +96,7 @@ ExtendedRequest.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
j.requestName = this.requestName; j.requestName = this.requestName;
j.requestValue = this.requestValue; j.requestValue = (Buffer.isBuffer(this.requestValue)) ? this.requestValue.toString('hex') : this.requestValue;
return j; return j;
}; };