Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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')
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)
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
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)
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'))
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)
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
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