def _build(self, obj, stream, context, path): if not isinstance(obj, integertypes): raise IntegerError("value is not an integer") if obj < 0: raise IntegerError( "asn1length cannot build from negative number: %r" % (obj, )) num = obj if num < 0x80: stream_write(stream, int2byte(num), 1) else: acc = b"" while num != 0: acc += int2byte(num & 0xFF) num >>= 8 stream_write(stream, int2byte(0x80 | len(acc)), 1) stream_write(stream, swapbytes(acc)) return obj
def _build(self, obj, stream, context, path): modulus = self.modulus(context) if callable(self.modulus) else self.modulus bits_to_add = (modulus - len(stream.wbuffer)) % modulus stream_write(stream, self.pattern * bits_to_add, bits_to_add)