UNPKG

2.09 kBJavaScriptView Raw
1var assert = require('assert-plus');
2var util = require('util');
3
4var asn1 = require('asn1');
5
6var Control = require('./control');
7
8
9///--- Globals
10
11var BerReader = asn1.BerReader;
12var BerWriter = asn1.BerWriter;
13
14
15///--- API
16
17function EntryChangeNotificationControl(options) {
18 assert.optionalObject(options);
19 options = options || {};
20 options.type = EntryChangeNotificationControl.OID;
21 if (options.value) {
22 if (Buffer.isBuffer(options.value)) {
23 this.parse(options.value);
24 } else if (typeof (options.value) === 'object') {
25 this._value = options.value;
26 } else {
27 throw new TypeError('options.value must be a Buffer or Object');
28 }
29 options.value = null;
30 }
31 Control.call(this, options);
32}
33util.inherits(EntryChangeNotificationControl, Control);
34Object.defineProperties(EntryChangeNotificationControl.prototype, {
35 value: {
36 get: function () { return this._value || {}; },
37 configurable: false
38 }
39});
40
41EntryChangeNotificationControl.prototype.parse = function parse(buffer) {
42 assert.ok(buffer);
43
44 var ber = new BerReader(buffer);
45 if (ber.readSequence()) {
46 this._value = {
47 changeType: ber.readInt()
48 };
49
50 // if the operation was moddn, then parse the optional previousDN attr
51 if (this._value.changeType === 8)
52 this._value.previousDN = ber.readString();
53
54 this._value.changeNumber = ber.readInt();
55
56 return true;
57 }
58
59 return false;
60};
61
62EntryChangeNotificationControl.prototype._toBer = function (ber) {
63 assert.ok(ber);
64
65 if (!this._value)
66 return;
67
68 var writer = new BerWriter();
69 writer.startSequence();
70 writer.writeInt(this.value.changeType);
71 if (this.value.previousDN)
72 writer.writeString(this.value.previousDN);
73
74 writer.writeInt(parseInt(this.value.changeNumber, 10));
75 writer.endSequence();
76
77 ber.writeBuffer(writer.buffer, 0x04);
78};
79
80EntryChangeNotificationControl.prototype._json = function (obj) {
81 obj.controlValue = this.value;
82 return obj;
83};
84
85EntryChangeNotificationControl.OID = '2.16.840.1.113730.3.4.7';
86
87
88///--- Exports
89module.exports = EntryChangeNotificationControl;