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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
'use strict'
 
const { Ber } = require('@ldapjs/asn1')
 
const Control = require('./lib/control')
const EntryChangeNotificationControl = require('./lib/controls/entry-change-notification-control')
const PagedResultsControl = require('./lib/controls/paged-results-control')
const PasswordPolicyControl = require('./lib/controls/password-policy-control')
const PersistentSearchControl = require('./lib/controls/persistent-search-control')
const ServerSideSortingRequestControl = require('./lib/controls/server-side-sorting-request-control')
const ServerSideSortingResponseControl = require('./lib/controls/server-side-sorting-response-control')
const VirtualListViewRequestControl = require('./lib/controls/virtual-list-view-request-control')
const VirtualListViewResponseControl = require('./lib/controls/virtual-list-view-response-control')
 
module.exports = {
 
  getControl: function getControl (ber) {
    if (!ber) throw TypeError('ber must be provided')
 
    if (ber.readSequence() === null) { return null }
 
    let type
    const opts = {
      criticality: false,
      value: null
    }
 
    /* istanbul ignore else */
    if (ber.length) {
      const end = ber.offset + ber.length
 
      type = ber.readString()
      /* istanbul ignore else */
      if (ber.offset < end) {
        /* istanbul ignore else */
        if (ber.peek() === Ber.Boolean) { opts.criticality = ber.readBoolean() }
      }
 
      if (ber.offset < end) { opts.value = ber.readString(Ber.OctetString, true) }
    }
 
    let control
    switch (type) {
      case EntryChangeNotificationControl.OID: {
        control = new EntryChangeNotificationControl(opts)
        break
      }
 
      case PagedResultsControl.OID: {
        control = new PagedResultsControl(opts)
        break
      }
 
      case PasswordPolicyControl.OID: {
        control = new PasswordPolicyControl(opts)
        break
      }
 
      case PersistentSearchControl.OID: {
        control = new PersistentSearchControl(opts)
        break
      }
 
      case ServerSideSortingRequestControl.OID: {
        control = new ServerSideSortingRequestControl(opts)
        break
      }
 
      case ServerSideSortingResponseControl.OID: {
        control = new ServerSideSortingResponseControl(opts)
        break
      }
 
      case VirtualListViewRequestControl.OID: {
        control = new VirtualListViewRequestControl(opts)
        break
      }
 
      case VirtualListViewResponseControl.OID: {
        control = new VirtualListViewResponseControl(opts)
        break
      }
 
      default: {
        opts.type = type
        control = new Control(opts)
        break
      }
    }
 
    return control
  },
 
  Control,
  EntryChangeNotificationControl,
  PagedResultsControl,
  PasswordPolicyControl,
  PersistentSearchControl,
  ServerSideSortingRequestControl,
  ServerSideSortingResponseControl,
  VirtualListViewRequestControl,
  VirtualListViewResponseControl
}