UNPKG

1.63 kBJavaScriptView Raw
1// Copyright 2011 Mark Cavage, Inc. All rights reserved.
2
3const assert = require('assert-plus')
4const util = require('util')
5
6const LDAPMessage = require('./message')
7const Protocol = require('../protocol')
8const lassert = require('../assert')
9
10/// --- API
11
12function 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}
26util.inherits(CompareRequest, LDAPMessage)
27Object.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
38CompareRequest.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
50CompareRequest.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
62CompareRequest.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/// --- Exports
73
74module.exports = CompareRequest