Allow ext request message to have a buffer value in order to accomodate rfc3062 exop

This commit is contained in:
Gonzalo Huerta-Canepa 2014-01-03 12:47:42 +00:00
parent 218150466f
commit fce043d6d0
1 changed files with 13 additions and 7 deletions

View File

@ -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;
};