I tried to use the method prettyIn
from the python library pyasn1.type.univ.BitString
.
This method takes a string, but whatever I pass in, in the python interactive shell raises the exception pyasn1.error.PyAsn1Error: Unknown bit identifier
. I looked up on Google the source code for that method, and here is what I found:
def prettyIn(self, value):
r = []
if not value:
return ()
elif isinstance(value, str):
if value[0] == '\'':
if value[-2:] == '\'B':
for v in value[1:-2]:
if v == '0':
r.append(0)
elif v == '1':
r.append(1)
else:
raise error.PyAsn1Error(
'Non-binary BIT STRING initializer %s' % (v,)
)
return tuple(r)
elif value[-2:] == '\'H':
for v in value[1:-2]:
i = 4
v = int(v, 16)
while i:
i = i - 1
r.append((v>>i)&0x01)
return tuple(r)
else:
raise error.PyAsn1Error(
'Bad BIT STRING value notation %s' % value
)
else:
for i in value.split(','):
j = self.__namedValues.getValue(i)
if j is None:
# THIS IS THE PROBLEMATIC LINE
raise error.PyAsn1Error(
'Unknown bit identifier \'%s\'' % i
)
if j >= len(r):
r.extend([0]*(j-len(r)+1))
r[j] = 1
return tuple(r)
elif isinstance(value, (tuple, list)):
r = tuple(value)
for b in r:
if b and b != 1:
raise error.PyAsn1Error(
'Non-binary BitString initializer \'%s\'' % (r,)
)
return r
elif isinstance(value, BitString):
return tuple(value)
else:
raise error.PyAsn1Error(
'Bad BitString initializer type \'%s\'' % (value,)
)
Does anyone have any idea what kind of string this method takes in? This method is use in a program I have to debug and cannot be changed.
Thanks your help,
Drummmer Kubuntu