2019-08-27 21:11:49 +00:00
|
|
|
var assert = require('assert-plus')
|
|
|
|
var util = require('util')
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
var asn1 = require('asn1')
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
var Control = require('./control')
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
/// --- Globals
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
var BerReader = asn1.BerReader
|
|
|
|
var BerWriter = asn1.BerWriter
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
/// --- API
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
function EntryChangeNotificationControl (options) {
|
|
|
|
assert.optionalObject(options)
|
|
|
|
options = options || {}
|
|
|
|
options.type = EntryChangeNotificationControl.OID
|
2011-12-20 00:52:48 +00:00
|
|
|
if (options.value) {
|
|
|
|
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-20 00:52:48 +00:00
|
|
|
} else {
|
2019-08-27 21:11:49 +00:00
|
|
|
throw new TypeError('options.value must be a Buffer or Object')
|
2011-12-20 00:52:48 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
options.value = null
|
2011-12-20 00:52:48 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
Control.call(this, options)
|
2011-12-20 00:52:48 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
util.inherits(EntryChangeNotificationControl, Control)
|
2015-11-12 04:36:21 +00:00
|
|
|
Object.defineProperties(EntryChangeNotificationControl.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-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
EntryChangeNotificationControl.prototype.parse = function parse (buffer) {
|
|
|
|
assert.ok(buffer)
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
var ber = new BerReader(buffer)
|
2011-12-20 00:52:48 +00:00
|
|
|
if (ber.readSequence()) {
|
|
|
|
this._value = {
|
|
|
|
changeType: ber.readInt()
|
2019-08-27 21:11:49 +00:00
|
|
|
}
|
2011-12-20 00:52:48 +00:00
|
|
|
|
|
|
|
// if the operation was moddn, then parse the optional previousDN attr
|
2019-08-27 21:11:49 +00:00
|
|
|
if (this._value.changeType === 8) { this._value.previousDN = ber.readString() }
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
this._value.changeNumber = ber.readInt()
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
return true
|
2011-12-20 00:52:48 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
return false
|
|
|
|
}
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
EntryChangeNotificationControl.prototype._toBer = function (ber) {
|
2019-08-27 21:11:49 +00:00
|
|
|
assert.ok(ber)
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
if (!this._value) { return }
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
var writer = new BerWriter()
|
|
|
|
writer.startSequence()
|
|
|
|
writer.writeInt(this.value.changeType)
|
|
|
|
if (this.value.previousDN) { writer.writeString(this.value.previousDN) }
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
writer.writeInt(parseInt(this.value.changeNumber, 10))
|
|
|
|
writer.endSequence()
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
ber.writeBuffer(writer.buffer, 0x04)
|
|
|
|
}
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
EntryChangeNotificationControl.prototype._json = function (obj) {
|
2019-08-27 21:11:49 +00:00
|
|
|
obj.controlValue = this.value
|
|
|
|
return obj
|
|
|
|
}
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
EntryChangeNotificationControl.OID = '2.16.840.1.113730.3.4.7'
|
2011-12-20 00:52:48 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
/// --- Exports
|
|
|
|
module.exports = EntryChangeNotificationControl
|