Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def read_bits(self, bits):
result = 0
resultbits = 0
while resultbits != bits:
if self._nextbits == 0:
if self.done():
raise TruncatedError(self)
self._next = ord(self._data[self._used])
self._used += 1
self._nextbits = 8
copybits = min(bits - resultbits, self._nextbits)
copy = (self._next & ((1 << copybits) - 1))
if self._bigendian:
result |= copy << (bits - resultbits - copybits)
else:
result |= copy << resultbits
self._next >>= copybits
self._nextbits -= copybits
resultbits += copybits
return result
def read_bits(self, bits):
result = 0
resultbits = 0
while resultbits != bits:
if self._nextbits == 0:
if self.done():
raise TruncatedError(self)
self._next = byte_to_int(self._data[self._used])
self._used += 1
self._nextbits = 8
copybits = min(bits - resultbits, self._nextbits)
copy = (self._next & ((1 << copybits) - 1))
if self._bigendian:
result |= copy << (bits - resultbits - copybits)
else:
result |= copy << resultbits
self._next >>= copybits
self._nextbits -= copybits
resultbits += copybits
return result
def read_aligned_bytes(self, bytes):
self.byte_align()
data = self._data[self._used:self._used + bytes]
self._used += bytes
if len(data) != bytes:
raise TruncatedError(self)
return data
def read_aligned_bytes(self, bytes):
self.byte_align()
data = self._data[self._used:self._used + bytes]
self._used += bytes
if len(data) != bytes:
raise TruncatedError(self)
return data