2011-12-08 22:54:40 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const assert = require('assert-plus')
|
|
|
|
const util = require('util')
|
2011-12-08 22:54:40 +00:00
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const asn1 = require('asn1')
|
2011-12-08 22:54:40 +00:00
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const Control = require('./control')
|
2011-12-08 22:54:40 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
/// --- Globals
|
2011-12-08 22:54:40 +00:00
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const BerReader = asn1.BerReader
|
|
|
|
const BerWriter = asn1.BerWriter
|
2011-12-08 22:54:40 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
/// --- API
|
2011-12-08 22:54:40 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
function PersistentSearchControl (options) {
|
|
|
|
assert.optionalObject(options)
|
|
|
|
options = options || {}
|
|
|
|
options.type = PersistentSearchControl.OID
|
2015-11-12 04:36:21 +00:00
|
|
|
|
2011-12-08 19:22:35 +00:00
|
|
|
if (options.value) {
|
2011-12-08 22:54:40 +00:00
|
|
|
if (Buffer.isBuffer(options.value)) {
|
2019-08-27 21:11:49 +00:00
|
|
|
this.parse(options.value)
|
2012-02-18 08:15:52 +00:00
|
|
|
} else if (typeof (options.value) === 'object') {
|
2019-08-27 21:11:49 +00:00
|
|
|
this._value = options.value
|
2011-12-08 22:54:40 +00:00
|
|
|
} else {
|
2019-08-27 21:11:49 +00:00
|
|
|
throw new TypeError('options.value must be a Buffer or Object')
|
2011-12-08 19:22:35 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
options.value = null
|
2011-12-08 01:02:17 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
Control.call(this, options)
|
2011-12-08 01:02:17 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
util.inherits(PersistentSearchControl, Control)
|
2015-11-12 04:36:21 +00:00
|
|
|
Object.defineProperties(PersistentSearchControl.prototype, {
|
|
|
|
value: {
|
2019-08-27 21:11:49 +00:00
|
|
|
get: function () { return this._value || {} },
|
2015-11-12 04:36:21 +00:00
|
|
|
configurable: false
|
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
PersistentSearchControl.prototype.parse = function parse (buffer) {
|
|
|
|
assert.ok(buffer)
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const ber = new BerReader(buffer)
|
2011-12-08 22:54:40 +00:00
|
|
|
if (ber.readSequence()) {
|
|
|
|
this._value = {
|
|
|
|
changeTypes: ber.readInt(),
|
|
|
|
changesOnly: ber.readBoolean(),
|
|
|
|
returnECs: ber.readBoolean()
|
2019-08-27 21:11:49 +00:00
|
|
|
}
|
2011-12-08 22:54:40 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
return true
|
2011-12-08 22:54:40 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
return false
|
|
|
|
}
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
PersistentSearchControl.prototype._toBer = function (ber) {
|
2019-08-27 21:11:49 +00:00
|
|
|
assert.ok(ber)
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
if (!this._value) { return }
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const writer = new BerWriter()
|
2019-08-27 21:11:49 +00:00
|
|
|
writer.startSequence()
|
|
|
|
writer.writeInt(this.value.changeTypes)
|
|
|
|
writer.writeBoolean(this.value.changesOnly)
|
|
|
|
writer.writeBoolean(this.value.returnECs)
|
|
|
|
writer.endSequence()
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
ber.writeBuffer(writer.buffer, 0x04)
|
|
|
|
}
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
PersistentSearchControl.prototype._json = function (obj) {
|
2019-08-27 21:11:49 +00:00
|
|
|
obj.controlValue = this.value
|
|
|
|
return obj
|
|
|
|
}
|
2011-12-09 21:59:17 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
PersistentSearchControl.OID = '2.16.840.1.113730.3.4.3'
|
2015-11-12 04:36:21 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
/// --- Exports
|
|
|
|
module.exports = PersistentSearchControl
|