1 |
|
2 |
|
3 | const assert = require('assert-plus')
|
4 | const util = require('util')
|
5 |
|
6 | const LDAPMessage = require('./message')
|
7 | const Protocol = require('../protocol')
|
8 | const lassert = require('../assert')
|
9 |
|
10 |
|
11 |
|
12 | function CompareRequest (options) {
|
13 | options = options || {}
|
14 | assert.object(options)
|
15 | assert.optionalString(options.attribute)
|
16 | assert.optionalString(options.value)
|
17 | lassert.optionalStringDN(options.entry)
|
18 |
|
19 | options.protocolOp = Protocol.LDAP_REQ_COMPARE
|
20 | LDAPMessage.call(this, options)
|
21 |
|
22 | this.entry = options.entry || null
|
23 | this.attribute = options.attribute || ''
|
24 | this.value = options.value || ''
|
25 | }
|
26 | util.inherits(CompareRequest, LDAPMessage)
|
27 | Object.defineProperties(CompareRequest.prototype, {
|
28 | type: {
|
29 | get: function getType () { return 'CompareRequest' },
|
30 | configurable: false
|
31 | },
|
32 | _dn: {
|
33 | get: function getDN () { return this.entry },
|
34 | configurable: false
|
35 | }
|
36 | })
|
37 |
|
38 | CompareRequest.prototype._parse = function (ber) {
|
39 | assert.ok(ber)
|
40 |
|
41 | this.entry = ber.readString()
|
42 |
|
43 | ber.readSequence()
|
44 | this.attribute = ber.readString().toLowerCase()
|
45 | this.value = ber.readString()
|
46 |
|
47 | return true
|
48 | }
|
49 |
|
50 | CompareRequest.prototype._toBer = function (ber) {
|
51 | assert.ok(ber)
|
52 |
|
53 | ber.writeString(this.entry.toString())
|
54 | ber.startSequence()
|
55 | ber.writeString(this.attribute)
|
56 | ber.writeString(this.value)
|
57 | ber.endSequence()
|
58 |
|
59 | return ber
|
60 | }
|
61 |
|
62 | CompareRequest.prototype._json = function (j) {
|
63 | assert.ok(j)
|
64 |
|
65 | j.entry = this.entry.toString()
|
66 | j.attribute = this.attribute
|
67 | j.value = this.value
|
68 |
|
69 | return j
|
70 | }
|
71 |
|
72 |
|
73 |
|
74 | module.exports = CompareRequest
|