|
7 | 7 | import struct,ldap
|
8 | 8 | from ldap.controls import RequestControl,ResponseControl,LDAPControl,KNOWN_RESPONSE_CONTROLS
|
9 | 9 |
|
| 10 | +from pyasn1.type import univ |
| 11 | +from pyasn1.codec.ber import encoder,decoder |
| 12 | + |
10 | 13 |
|
11 | 14 | class ValueLessRequestControl(RequestControl):
|
12 | 15 | """
|
@@ -57,19 +60,18 @@ class BooleanControl(LDAPControl):
|
57 | 60 | booleanValue
|
58 | 61 | Boolean (True/False or 1/0) which is the boolean controlValue.
|
59 | 62 | """
|
60 |
| - boolean2ber = { 1:'\x01\x01\xFF', 0:'\x01\x01\x00' } |
61 |
| - ber2boolean = { '\x01\x01\xFF':1, '\x01\x01\x00':0 } |
62 | 63 |
|
63 | 64 | def __init__(self,controlType=None,criticality=False,booleanValue=False):
|
64 | 65 | self.controlType = controlType
|
65 | 66 | self.criticality = criticality
|
66 | 67 | self.booleanValue = booleanValue
|
67 | 68 |
|
68 | 69 | def encodeControlValue(self):
|
69 |
| - return self.boolean2ber[int(self.booleanValue)] |
| 70 | + return encoder.encode(self.booleanValue,asn1Spec=univ.Boolean()) |
70 | 71 |
|
71 | 72 | def decodeControlValue(self,encodedControlValue):
|
72 |
| - self.booleanValue = self.ber2boolean[encodedControlValue] |
| 73 | + decodedValue,_ = decoder.decode(encodedControlValue,asn1Spec=univ.Boolean()) |
| 74 | + self.booleanValue = bool(int(decodedValue)) |
73 | 75 |
|
74 | 76 |
|
75 | 77 | class ManageDSAITControl(ValueLessRequestControl):
|
|
0 commit comments