273
|
1 /*
|
|
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
|
|
3 * Please refer to the LICENSE.txt for licensing details.
|
|
4 */
|
|
5 package ch.ethz.ssh2.packets;
|
|
6
|
|
7 import java.io.IOException;
|
|
8 import java.math.BigInteger;
|
|
9
|
|
10 import ch.ethz.ssh2.PacketFormatException;
|
|
11 import ch.ethz.ssh2.PacketTypeException;
|
|
12
|
|
13 /**
|
|
14 * @author Christian Plattner
|
|
15 * @version $Id: PacketKexDHInit.java 160 2014-05-01 14:30:26Z dkocher@sudo.ch $
|
|
16 */
|
|
17 public final class PacketKexDHInit {
|
|
18
|
|
19 private final byte[] payload;
|
|
20
|
|
21 private final BigInteger e;
|
|
22
|
|
23 public PacketKexDHInit(BigInteger e) {
|
|
24 this.e = e;
|
|
25 TypesWriter tw = new TypesWriter();
|
|
26 tw.writeByte(Packets.SSH_MSG_KEXDH_INIT);
|
|
27 tw.writeMPInt(e);
|
|
28 payload = tw.getBytes();
|
|
29 }
|
|
30
|
|
31 public PacketKexDHInit(byte payload[]) throws IOException {
|
|
32 this.payload = payload;
|
|
33 TypesReader tr = new TypesReader(payload);
|
|
34 int packet_type = tr.readByte();
|
|
35
|
307
|
36 if (packet_type != Packets.SSH_MSG_KEXDH_INIT) {
|
273
|
37 throw new PacketTypeException(packet_type);
|
|
38 }
|
|
39
|
|
40 e = tr.readMPINT();
|
|
41
|
307
|
42 if (tr.remain() != 0) {
|
273
|
43 throw new PacketFormatException(String.format("Padding in %s", Packets.getMessageName(packet_type)));
|
|
44 }
|
|
45 }
|
|
46
|
|
47 public BigInteger getE() {
|
|
48 return e;
|
|
49 }
|
|
50
|
|
51 public byte[] getPayload() {
|
|
52 return payload;
|
|
53 }
|
|
54 }
|