serializeMpInt function

void serializeMpInt(
  1. SerializableOutput output,
  2. BigInt x
)

mpint: https://www.ietf.org/rfc/rfc4251.txt

Implementation

void serializeMpInt(SerializableOutput output, BigInt x) {
  if (x.sign < 0) throw FormatException('Negative BigInt not supported');
  Uint8List xBytes = encodeBigInt(x);
  bool padX = x.bitLength > 0 && x.bitLength % 8 == 0;
  output.addUint32(xBytes.length + (padX ? 1 : 0));
  if (padX) output.addUint8(0);
  output.addBytes(xBytes);
}