wangzhibo
2026-05-09 53418655c061ac26f66058253f39200aced1ab1d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict'
 
const LdapMessage = require('../ldap-message')
const { operations } = require('@ldapjs/protocol')
 
/**
 * Implements the unbind request message as described in
 * https://www.rfc-editor.org/rfc/rfc4511.html#section-4.3.
 */
class UnbindRequest extends LdapMessage {
  /**
   * @param {LdapMessageOptions} options
   */
  constructor (options = {}) {
    options.protocolOp = operations.LDAP_REQ_UNBIND
    super(options)
  }
 
  /**
   * The name of the request type.
   *
   * @type {string}
   */
  get type () {
    return 'UnbindRequest'
  }
 
  /**
   * Internal use only.
   *
   * @param {import('@ldapjs/asn1').BerWriter} ber
   *
   * @returns {import('@ldapjs/asn1').BerWriter}
   */
  _toBer (ber) {
    ber.writeString('', operations.LDAP_REQ_UNBIND)
    return ber
  }
 
  /**
   * Internal use only.
   *
   * @param {object}
   *
   * @returns {object}
   */
  _pojo (obj = {}) {
    return obj
  }
 
  /**
   * Implements the standardized `parseToPojo` method.
   *
   * @see LdapMessage.parseToPojo
   *
   * @param {import('@ldapjs/asn1').BerReader} ber
   */
  static parseToPojo (ber) {
    const protocolOp = ber.readSequence()
    if (protocolOp !== operations.LDAP_REQ_UNBIND) {
      const op = protocolOp.toString(16).padStart(2, '0')
      throw Error(`found wrong protocol operation: 0x${op}`)
    }
 
    return { protocolOp }
  }
}
 
module.exports = UnbindRequest