Preserve raw Buffer value in Control objects

Fix mcavage/node-ldapjs#143
This commit is contained in:
Patrick Mooney 2014-07-14 14:47:36 -05:00
parent e30a5dab33
commit dd63fea6f7
4 changed files with 8 additions and 6 deletions

View File

@ -2,6 +2,7 @@
## CURRENT
- #143 Preserve raw Buffer value in Control objects
- Test code coverage with node-istanbul
- Convert tests to node-tape
- Add controls for server-side sorting

View File

@ -26,8 +26,8 @@ function Control(options) {
if (options.criticality !== undefined &&
typeof (options.criticality) !== 'boolean')
throw new TypeError('options.criticality must be a boolean');
if (options.value && typeof (options.value) !== 'string')
throw new TypeError('options.value must be a string');
if (options.value && !Buffer.isBuffer(options.value))
throw new TypeError('options.value must be a Buffer');
} else {
options = {};
}

View File

@ -1,6 +1,7 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert');
var Ber = require('asn1').Ber;
var Control = require('./control');
var EntryChangeNotificationControl =
@ -33,12 +34,12 @@ module.exports = {
type = ber.readString();
if (ber.offset < end) {
if (ber.peek() === 0x01)
if (ber.peek() === Ber.Boolean)
critical = ber.readBoolean();
}
if (ber.offset < end)
value = ber.readString(0x04, true);
value = ber.readString(Ber.OctetString, true);
}
var control;
@ -77,7 +78,7 @@ module.exports = {
control = new Control({
type: type,
critical: critical,
value: value ? value.toString('utf8') : null
value: value
});
break;
}

View File

@ -55,7 +55,7 @@ test('parse', function (t) {
t.ok(c);
t.equal(c.type, '2.16.840.1.113730.3.4.2');
t.ok(c.criticality);
t.equal(c.value, 'foo');
t.equal(c.value.toString('utf8'), 'foo');
t.end();
});