0

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

1 Answers1

-3

just saw this question as i'm currently working on it, I can tell you.

http://transit.iut2.upmf-grenoble.fr/doc/python-pyasn1/pyasn1-tutorial.html#1.1.6

BIT STRING ::= '1010111011110001010110101101101 1011000101010000010110101100010 0110101010000111101010111111110'B signature BIT STRING ::= 'AF01330CD932093392100B39FF00DE0'H

which means, univ.BitString("'AF01330CD932093392100B39FF00DE0'H")

NoOne
  • 27
  • 5
  • What does this answer mean? Does it solve the problem OP has? – luk2302 Feb 15 '17 at 15:17
  • I guess, he was asking which kind of string univ.BitString takes, I gave him an example and a link where I found this information. – NoOne Mar 17 '17 at 14:02