enqueue_packet (Net::SSH::Transport::PacketStream)

         # File lib/net/ssh/transport/packet_stream.rb, line 115
    115:     def enqueue_packet(payload)
    116:       # try to compress the packet
    117:       payload = client.compress(payload)
    118:
    119:       # the length of the packet, minus the padding
    120:       actual_length = 4 + payload.length + 1
    121:
    122:       # compute the padding length
    123:       padding_length = client.block_size - (actual_length % client.block_size)
    124:       padding_length += client.block_size if padding_length < 4
    125:
    126:       # compute the packet length (sans the length field itself)
    127:       packet_length = payload.length + padding_length + 1
    128:
    129:       if packet_length < 16
    130:         padding_length += client.block_size
    131:         packet_length = payload.length + padding_length + 1
    132:       end
    133:
    134:       padding = Array.new(padding_length) { rand(256) }.pack("C*")
    135:
    136:       unencrypted_data = [packet_length, padding_length, payload, padding].pack("NCA*A*")
    137:       mac = client.hmac.digest([client.sequence_number, unencrypted_data].pack("NA*"))
    138:
    139:       encrypted_data = client.update_cipher(unencrypted_data) << client.final_cipher
    140:       message = encrypted_data + mac
    141:
    142:       debug { "queueing packet nr #{client.sequence_number} type #{payload.getbyte(0)} len #{packet_length}" }
    143:       enqueue(message)
    144:
    145:       client.increment(packet_length)
    146:
    147:       self
    148:     end