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
'use strict'
 
const { test } = require('tap')
const { BerReader, BerWriter } = require('@ldapjs/asn1')
const { Control, getControl } = require('../../lib')
 
test('new no args', function (t) {
  t.ok(new Control())
  t.end()
})
 
test('new with args', function (t) {
  const c = new Control({
    type: '2.16.840.1.113730.3.4.2',
    criticality: true
  })
  t.ok(c)
  t.equal(c.type, '2.16.840.1.113730.3.4.2')
  t.ok(c.criticality)
  t.end()
})
 
test('parse', function (t) {
  const ber = new BerWriter()
  ber.startSequence()
  ber.writeString('2.16.840.1.113730.3.4.2')
  ber.writeBoolean(true)
  ber.writeString('foo')
  ber.endSequence()
 
  const c = getControl(new BerReader(ber.buffer))
 
  t.ok(c)
  t.equal(c.type, '2.16.840.1.113730.3.4.2')
  t.ok(c.criticality)
  t.equal(c.value.toString('utf8'), 'foo')
  t.end()
})
 
test('parse no value', function (t) {
  const ber = new BerWriter()
  ber.startSequence()
  ber.writeString('2.16.840.1.113730.3.4.2')
  ber.endSequence()
 
  const c = getControl(new BerReader(ber.buffer))
 
  t.ok(c)
  t.equal(c.type, '2.16.840.1.113730.3.4.2')
  t.equal(c.criticality, false)
  t.notOk(c.value, null)
  t.end()
})