1 11 package org.eclipse.team.internal.ccvs.ssh; 12 13 class ClientPacket extends Packet { 14 byte[] packet; 15 public ClientPacket(int type, byte[] data, Cipher cipher) { 16 packetLength = data == null ? 5 : data.length + 5; 17 paddingLength = 8 - (packetLength % 8); 18 packetType = type; 19 packet = new byte[4 + paddingLength + packetLength]; 20 21 int packetOff = 0; 22 Misc.writeInt(packetLength, packet, packetOff); 23 packetOff += 4; 24 25 if (cipher == null) { 26 for (int i = 0; i < paddingLength; i++) { 27 packet[packetOff++] = 0; 28 } 29 } else { 30 Misc.random(packet, packetOff, paddingLength, false); 31 packetOff += paddingLength; 32 } 33 34 packet[packetOff++] = (byte) packetType; 35 36 if (data != null) { 37 for (int i = 0; i < data.length; ++i) { 38 packet[packetOff++] = data[i]; 39 } 40 } 41 42 long crc = Misc.crc32(packet, 4, packet.length - 8, 0); 43 Misc.writeInt((int) crc, packet, packetOff); 44 packetOff += 4; 45 46 if (cipher != null) { 47 cipher.encipher(packet, 4, packet, 4, packet.length - 4); 48 } 49 } 50 public byte[] getBytes() { 51 return packet; 52 } 53 } 54 | Popular Tags |