1 | var assert = require('assert-plus');
|
2 | var util = require('util');
|
3 |
|
4 | var asn1 = require('asn1');
|
5 |
|
6 | var Control = require('./control');
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | var BerReader = asn1.BerReader;
|
12 | var BerWriter = asn1.BerWriter;
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function 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 | }
|
33 | util.inherits(EntryChangeNotificationControl, Control);
|
34 | Object.defineProperties(EntryChangeNotificationControl.prototype, {
|
35 | value: {
|
36 | get: function () { return this._value || {}; },
|
37 | configurable: false
|
38 | }
|
39 | });
|
40 |
|
41 | EntryChangeNotificationControl.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 |
|
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 |
|
62 | EntryChangeNotificationControl.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 |
|
80 | EntryChangeNotificationControl.prototype._json = function (obj) {
|
81 | obj.controlValue = this.value;
|
82 | return obj;
|
83 | };
|
84 |
|
85 | EntryChangeNotificationControl.OID = '2.16.840.1.113730.3.4.7';
|
86 |
|
87 |
|
88 |
|
89 | module.exports = EntryChangeNotificationControl;
|