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