UNPKG

2.17 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 dn = require('../dn')
9const lassert = require('../assert')
10
11/// --- API
12
13function ModifyDNRequest (options) {
14 options = options || {}
15 assert.object(options)
16 assert.optionalBool(options.deleteOldRdn)
17 lassert.optionalStringDN(options.entry)
18 lassert.optionalDN(options.newRdn)
19 lassert.optionalDN(options.newSuperior)
20
21 options.protocolOp = Protocol.LDAP_REQ_MODRDN
22 LDAPMessage.call(this, options)
23
24 this.entry = options.entry || null
25 this.newRdn = options.newRdn || null
26 this.deleteOldRdn = options.deleteOldRdn || true
27 this.newSuperior = options.newSuperior || null
28}
29util.inherits(ModifyDNRequest, LDAPMessage)
30Object.defineProperties(ModifyDNRequest.prototype, {
31 type: {
32 get: function getType () { return 'ModifyDNRequest' },
33 configurable: false
34 },
35 _dn: {
36 get: function getDN () { return this.entry },
37 configurable: false
38 }
39})
40
41ModifyDNRequest.prototype._parse = function (ber) {
42 assert.ok(ber)
43
44 this.entry = ber.readString()
45 this.newRdn = dn.parse(ber.readString())
46 this.deleteOldRdn = ber.readBoolean()
47 if (ber.peek() === 0x80) { this.newSuperior = dn.parse(ber.readString(0x80)) }
48
49 return true
50}
51
52ModifyDNRequest.prototype._toBer = function (ber) {
53 // assert.ok(ber);
54
55 ber.writeString(this.entry.toString())
56 ber.writeString(this.newRdn.toString())
57 ber.writeBoolean(this.deleteOldRdn)
58 if (this.newSuperior) {
59 const s = this.newSuperior.toString()
60 const len = Buffer.byteLength(s)
61
62 ber.writeByte(0x80) // MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG
63 ber.writeByte(len)
64 ber._ensure(len)
65 ber._buf.write(s, ber._offset)
66 ber._offset += len
67 }
68
69 return ber
70}
71
72ModifyDNRequest.prototype._json = function (j) {
73 assert.ok(j)
74
75 j.entry = this.entry.toString()
76 j.newRdn = this.newRdn.toString()
77 j.deleteOldRdn = this.deleteOldRdn
78 j.newSuperior = this.newSuperior ? this.newSuperior.toString() : ''
79
80 return j
81}
82
83/// --- Exports
84
85module.exports = ModifyDNRequest