comparison app/src/main/java/ch/ethz/ssh2/packets/PacketKexDHReply.java @ 438:d29cce60f393

migrate from Eclipse to Android Studio
author Carl Byington <carl@five-ten-sg.com>
date Thu, 03 Dec 2015 11:23:55 -0800
parents src/ch/ethz/ssh2/packets/PacketKexDHReply.java@071eccdff8ea
children
comparison
equal deleted inserted replaced
437:208b31032318 438:d29cce60f393
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: PacketKexDHReply.java 160 2014-05-01 14:30:26Z dkocher@sudo.ch $
16 */
17 public final class PacketKexDHReply {
18
19 private final byte[] payload;
20
21 private final byte[] hostKey;
22 private final BigInteger f;
23 private final byte[] signature;
24
25 public PacketKexDHReply(byte[] hostKey, BigInteger f, byte[] signature) {
26 this.hostKey = hostKey;
27 this.f = f;
28 this.signature = signature;
29 TypesWriter tw = new TypesWriter();
30 tw.writeByte(Packets.SSH_MSG_KEXDH_REPLY);
31 tw.writeString(hostKey, 0, hostKey.length);
32 tw.writeMPInt(f);
33 tw.writeString(signature, 0, signature.length);
34 payload = tw.getBytes();
35 }
36
37 public PacketKexDHReply(byte payload[]) throws IOException {
38 this.payload = payload;
39 TypesReader tr = new TypesReader(payload);
40 int packet_type = tr.readByte();
41
42 if (packet_type != Packets.SSH_MSG_KEXDH_REPLY) {
43 throw new PacketTypeException(packet_type);
44 }
45
46 hostKey = tr.readByteString();
47 f = tr.readMPINT();
48 signature = tr.readByteString();
49
50 if (tr.remain() != 0) {
51 throw new PacketFormatException(String.format("Padding in %s", Packets.getMessageName(packet_type)));
52 }
53 }
54
55 public byte[] getPayload() {
56 return payload;
57 }
58
59 public BigInteger getF() {
60 return f;
61 }
62
63 public byte[] getHostKey() {
64 return hostKey;
65 }
66
67 public byte[] getSignature() {
68 return signature;
69 }
70 }