sendPacket method

void sendPacket(
  1. Uint8List data
)

Implementation

void sendPacket(Uint8List data) {
  if (isClosed) {
    throw SSHStateError('Transport is closed');
  }
  final packetAlign = _encryptCipher == null
      ? SSHPacket.minAlign
      : max(SSHPacket.minAlign, _encryptCipher!.blockSize);

  final packet = SSHPacket.pack(data, align: packetAlign);

  if (_encryptCipher == null) {
    socket.sink.add(packet);
  } else {
    final mac = _localMac!;
    mac.updateAll(_localPacketSN.value.toUint32());
    mac.updateAll(packet);

    final buffer = BytesBuilder(copy: false);
    buffer.add(_encryptCipher!.processAll(packet));
    buffer.add(mac.finish());

    socket.sink.add(buffer.takeBytes());
  }

  _localPacketSN.increase();
}