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 DeleteRequest (options) {
|
13 | options = options || {}
|
14 | assert.object(options)
|
15 | lassert.optionalStringDN(options.entry)
|
16 |
|
17 | options.protocolOp = Protocol.LDAP_REQ_DELETE
|
18 | LDAPMessage.call(this, options)
|
19 |
|
20 | this.entry = options.entry || null
|
21 | }
|
22 | util.inherits(DeleteRequest, LDAPMessage)
|
23 | Object.defineProperties(DeleteRequest.prototype, {
|
24 | type: {
|
25 | get: function getType () { return 'DeleteRequest' },
|
26 | configurable: false
|
27 | },
|
28 | _dn: {
|
29 | get: function getDN () { return this.entry },
|
30 | configurable: false
|
31 | }
|
32 | })
|
33 |
|
34 | DeleteRequest.prototype._parse = function (ber, length) {
|
35 | assert.ok(ber)
|
36 |
|
37 | this.entry = ber.buffer.slice(0, length).toString('utf8')
|
38 | ber._offset += ber.length
|
39 |
|
40 | return true
|
41 | }
|
42 |
|
43 | DeleteRequest.prototype._toBer = function (ber) {
|
44 | assert.ok(ber)
|
45 |
|
46 | const buf = Buffer.from(this.entry.toString())
|
47 | for (let i = 0; i < buf.length; i++) { ber.writeByte(buf[i]) }
|
48 |
|
49 | return ber
|
50 | }
|
51 |
|
52 | DeleteRequest.prototype._json = function (j) {
|
53 | assert.ok(j)
|
54 |
|
55 | j.entry = this.entry
|
56 |
|
57 | return j
|
58 | }
|
59 |
|
60 |
|
61 |
|
62 | module.exports = DeleteRequest
|