2011-12-08 01:02:17 +00:00
|
|
|
var assert = require('assert');
|
|
|
|
var asn1 = require('asn1');
|
|
|
|
var buffer = require('buffer');
|
|
|
|
var Control = require('./control');
|
|
|
|
var util = require('util');
|
|
|
|
|
|
|
|
function PersistentSearchControl(options) {
|
|
|
|
if (options) {
|
|
|
|
if (typeof(options) !== 'object')
|
|
|
|
throw new TypeError('options must be an object');
|
|
|
|
if (options.type && typeof(options.type) !== 'string')
|
|
|
|
throw new TypeError('options.type must be a string');
|
|
|
|
if (options.criticality !== undefined &&
|
|
|
|
typeof(options.criticality) !== 'boolean')
|
|
|
|
throw new TypeError('options.criticality must be a boolean');
|
2011-12-08 19:22:35 +00:00
|
|
|
if (options.value && !Buffer.isBuffer(options.value))
|
2011-12-08 01:02:17 +00:00
|
|
|
throw new TypeError('options.value must be a buffer');
|
|
|
|
} else {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
|
2011-12-08 19:22:35 +00:00
|
|
|
this.type = options.type || '2.16.840.1.113730.3.4.3';
|
2011-12-08 01:02:17 +00:00
|
|
|
this.criticality = options.criticality || false;
|
|
|
|
|
2011-12-08 19:22:35 +00:00
|
|
|
if (options.value) {
|
2011-12-08 01:02:17 +00:00
|
|
|
// parse out this.value into the PSC object
|
2011-12-08 19:22:35 +00:00
|
|
|
var ber = new asn1.BerReader(options.value);
|
|
|
|
if (ber.readSequence()) {
|
|
|
|
this.value = {
|
|
|
|
changeTypes: ber.readInt(),
|
|
|
|
changesOnly: ber.readBoolean(),
|
|
|
|
returnECs: ber.readBoolean()
|
|
|
|
};
|
|
|
|
}
|
2011-12-08 01:02:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
this.__defineGetter__('json', function() {
|
|
|
|
return {
|
|
|
|
controlType: self.type,
|
|
|
|
criticality: self.criticality,
|
|
|
|
controlValue: self.value
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
module.exports = PersistentSearchControl;
|
|
|
|
|
|
|
|
// returns a psc given a fully populated psc object
|
|
|
|
PersistentSearchControl.prototype.get = function(options) {
|
|
|
|
if (options) {
|
|
|
|
if (typeof(options) !== 'object')
|
|
|
|
throw new TypeError('options must be an object');
|
|
|
|
if (options.type && typeof(options.type) !== 'string')
|
|
|
|
throw new TypeError('options.type must be a string');
|
|
|
|
if (options.criticality !== undefined &&
|
|
|
|
typeof(options.criticality) !== 'boolean')
|
|
|
|
throw new TypeError('options.criticality must be a boolean');
|
|
|
|
if (options.value && typeof(options.value) !== 'object') {
|
|
|
|
throw new TypeError('options.value must be an object');
|
|
|
|
} else {
|
|
|
|
if (options.value.changeTypes &&
|
|
|
|
typeof(options.value.changeTypes) !== 'number')
|
|
|
|
throw new TypeError('options.value.changeTypes must be a number');
|
|
|
|
if (options.value.changesOnly !== undefined &&
|
|
|
|
typeof(options.value.changesOnly) !== 'boolean')
|
|
|
|
throw new TypeError('options.value.changesOnly must be a boolean');
|
|
|
|
if (options.value.returnECs !== undefined &&
|
|
|
|
typeof(options.value.returnECs) !== 'boolean')
|
|
|
|
throw new TypeError('options.value.returnECs must be a boolean');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.type = options.type || '';
|
|
|
|
this.criticality = options.criticality || false;
|
|
|
|
this.value = options.value || undefined;
|
|
|
|
|
|
|
|
var self = this;
|
2011-12-08 19:22:35 +00:00
|
|
|
this.__defineGetter__('json', function() {
|
|
|
|
return {
|
|
|
|
controlType: self.type,
|
|
|
|
criticality: self.criticality,
|
|
|
|
controlValue: self.value
|
|
|
|
};
|
|
|
|
});
|
2011-12-08 01:02:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PersistentSearchControl.prototype.toBer = function(ber) {
|
|
|
|
assert.ok(ber);
|
|
|
|
|
|
|
|
ber.startSequence();
|
2011-12-08 19:22:35 +00:00
|
|
|
ber.writeString(this.type);
|
2011-12-08 01:02:17 +00:00
|
|
|
ber.writeBoolean(this.criticality);
|
|
|
|
|
2011-12-08 19:22:35 +00:00
|
|
|
var pscWriter = new asn1.BerWriter();
|
2011-12-08 01:02:17 +00:00
|
|
|
|
|
|
|
// write the value subsequence
|
|
|
|
pscWriter.startSequence();
|
|
|
|
pscWriter.writeInt(this.value.changeTypes);
|
|
|
|
pscWriter.writeBoolean(this.value.changesOnly);
|
|
|
|
pscWriter.writeBoolean(this.value.returnECs);
|
|
|
|
pscWriter.endSequence();
|
|
|
|
|
|
|
|
// write the pscValue as a octetstring to the ber
|
|
|
|
ber.writeBuffer(pscWriter.buffer, 0x04);
|
|
|
|
|
|
|
|
ber.endSequence();
|
|
|
|
};
|