How to use the asn1tools.codecs.OutOfDataError function in asn1tools

To help you get started, we’ve selected a few asn1tools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eerimoq / asn1tools / tests / test_oer.py View on Github external
def test_c_source(self):
        files = [
            'tests/files/c_source/c_source.asn'
        ]
        foo = asn1tools.compile_files(files, 'oer')

        # Type L - decode error bad length.
        with self.assertRaises(asn1tools.codecs.OutOfDataError):
            foo.decode('L', b'\x82\x01\xff')

        with self.assertRaises(asn1tools.codecs.OutOfDataError):
            foo.decode('L', b'\x83\x01\xff\x00')

        with self.assertRaises(asn1tools.codecs.OutOfDataError):
            foo.decode('L', b'\x84\x01\x00\x01\x00')

        with self.assertRaises(asn1tools.codecs.OutOfDataError):
            foo.decode('L', b'\x83')

        with self.assertRaises(asn1tools.codecs.OutOfDataError):
            foo.decode('L', b'\xff\x00')
github eerimoq / asn1tools / asn1tools / codecs / oer.py View on Github external
def read_bit(self):
        """Read a bit.

        """

        if self.number_of_bits == 0:
            raise OutOfDataError(self.number_of_read_bits())

        self.number_of_bits -= 1

        return ((self.value >> self.number_of_bits) & 1)
github eerimoq / asn1tools / asn1tools / codecs / per.py View on Github external
def read_bit(self):
        """Read a bit.

        """

        if self.number_of_bits == 0:
            raise OutOfDataError(self.number_of_read_bits())

        bit = int(self.value[self.number_of_read_bits()])
        self.number_of_bits -= 1

        return bit
github eerimoq / asn1tools / asn1tools / codecs / oer.py View on Github external
def read_non_negative_binary_integer(self, number_of_bits):
        """Read an integer value of given number of bits.

        """

        if number_of_bits > self.number_of_bits:
            raise OutOfDataError(self.number_of_read_bits())

        self.number_of_bits -= number_of_bits
        mask = ((1 << number_of_bits) - 1)

        return ((self.value >> self.number_of_bits) & mask)
github eerimoq / asn1tools / asn1tools / codecs / oer.py View on Github external
def read_bits(self, number_of_bits):
        """Read given number of bits.

        """

        if number_of_bits > self.number_of_bits:
            raise OutOfDataError(self.number_of_read_bits())

        self.number_of_bits -= number_of_bits
        mask = ((1 << number_of_bits) - 1)
        value = ((self.value >> self.number_of_bits) & mask)
        value &= mask
        value |= (0x80 << number_of_bits)

        return binascii.unhexlify(hex(value)[4:].rstrip('L'))
github eerimoq / asn1tools / asn1tools / codecs / per.py View on Github external
def read_non_negative_binary_integer(self, number_of_bits):
        """Read an integer value of given number of bits.

        """

        if number_of_bits > self.number_of_bits:
            raise OutOfDataError(self.number_of_read_bits())

        if number_of_bits == 0:
            return 0

        offset = self.number_of_read_bits()
        value = self.value[offset:offset + number_of_bits]
        self.number_of_bits -= number_of_bits

        return int(value, 2)
github eerimoq / asn1tools / asn1tools / codecs / oer.py View on Github external
def skip_bits(self, number_of_bits):
        if number_of_bits > self.number_of_bits:
            raise OutOfDataError(self.number_of_read_bits())

        self.number_of_bits -= number_of_bits
github eerimoq / asn1tools / asn1tools / codecs / per.py View on Github external
def skip_bits(self, number_of_bits):
        if number_of_bits > self.number_of_bits:
            raise OutOfDataError(self.number_of_read_bits())

        self.number_of_bits -= number_of_bits