Skip to content

Commit 9d7ca92

Browse files
committed
Update BooleanControl encoding/decoding to use pyasn1
1 parent 47975ee commit 9d7ca92

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Lib/ldap/controls/simple.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import struct,ldap
88
from ldap.controls import RequestControl,ResponseControl,LDAPControl,KNOWN_RESPONSE_CONTROLS
99

10+
from pyasn1.type import univ
11+
from pyasn1.codec.ber import encoder,decoder
12+
1013

1114
class ValueLessRequestControl(RequestControl):
1215
"""
@@ -57,19 +60,18 @@ class BooleanControl(LDAPControl):
5760
booleanValue
5861
Boolean (True/False or 1/0) which is the boolean controlValue.
5962
"""
60-
boolean2ber = { 1:'\x01\x01\xFF', 0:'\x01\x01\x00' }
61-
ber2boolean = { '\x01\x01\xFF':1, '\x01\x01\x00':0 }
6263

6364
def __init__(self,controlType=None,criticality=False,booleanValue=False):
6465
self.controlType = controlType
6566
self.criticality = criticality
6667
self.booleanValue = booleanValue
6768

6869
def encodeControlValue(self):
69-
return self.boolean2ber[int(self.booleanValue)]
70+
return encoder.encode(self.booleanValue,asn1Spec=univ.Boolean())
7071

7172
def decodeControlValue(self,encodedControlValue):
72-
self.booleanValue = self.ber2boolean[encodedControlValue]
73+
decodedValue,_ = decoder.decode(encodedControlValue,asn1Spec=univ.Boolean())
74+
self.booleanValue = bool(int(decodedValue))
7375

7476

7577
class ManageDSAITControl(ValueLessRequestControl):

0 commit comments

Comments
 (0)