1 |
|
2 |
|
3 | var assert = require('assert');
|
4 | var util = require('util');
|
5 |
|
6 | var parents = require('ldap-filter');
|
7 |
|
8 | var Filter = require('./filter');
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function SubstringFilter(options) {
|
14 | parents.SubstringFilter.call(this, options);
|
15 | }
|
16 | util.inherits(SubstringFilter, parents.SubstringFilter);
|
17 | Filter.mixin(SubstringFilter);
|
18 | module.exports = SubstringFilter;
|
19 |
|
20 |
|
21 | SubstringFilter.prototype.parse = function (ber) {
|
22 | assert.ok(ber);
|
23 |
|
24 | this.attribute = ber.readString().toLowerCase();
|
25 | ber.readSequence();
|
26 | var end = ber.offset + ber.length;
|
27 |
|
28 | while (ber.offset < end) {
|
29 | var tag = ber.peek();
|
30 | switch (tag) {
|
31 | case 0x80:
|
32 | this.initial = ber.readString(tag);
|
33 | if (this.attribute === 'objectclass')
|
34 | this.initial = this.initial.toLowerCase();
|
35 | break;
|
36 | case 0x81:
|
37 | var anyVal = ber.readString(tag);
|
38 | if (this.attribute === 'objectclass')
|
39 | anyVal = anyVal.toLowerCase();
|
40 | this.any.push(anyVal);
|
41 | break;
|
42 | case 0x82:
|
43 | this.final = ber.readString(tag);
|
44 | if (this.attribute === 'objectclass')
|
45 | this.final = this.final.toLowerCase();
|
46 | break;
|
47 | default:
|
48 | throw new Error('Invalid substrings filter type: 0x' + tag.toString(16));
|
49 | }
|
50 | }
|
51 |
|
52 | return true;
|
53 | };
|
54 |
|
55 |
|
56 | SubstringFilter.prototype._toBer = function (ber) {
|
57 | assert.ok(ber);
|
58 |
|
59 | ber.writeString(this.attribute);
|
60 | ber.startSequence();
|
61 |
|
62 | if (this.initial)
|
63 | ber.writeString(this.initial, 0x80);
|
64 |
|
65 | if (this.any && this.any.length)
|
66 | this.any.forEach(function (s) {
|
67 | ber.writeString(s, 0x81);
|
68 | });
|
69 |
|
70 | if (this.final)
|
71 | ber.writeString(this.final, 0x82);
|
72 |
|
73 | ber.endSequence();
|
74 |
|
75 | return ber;
|
76 | };
|