comparison src/ch/ethz/ssh2/packets/PacketDisconnect.java @ 273:91a31873c42a ganymed

start conversion from trilead to ganymed
author Carl Byington <carl@five-ten-sg.com>
date Fri, 18 Jul 2014 11:21:46 -0700
parents
children 071eccdff8ea
comparison
equal deleted inserted replaced
272:ce2f4e397703 273:91a31873c42a
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
9 import ch.ethz.ssh2.PacketFormatException;
10 import ch.ethz.ssh2.PacketTypeException;
11
12 /**
13 * @author Christian Plattner
14 * @version $Id: PacketDisconnect.java 160 2014-05-01 14:30:26Z dkocher@sudo.ch $
15 */
16 public final class PacketDisconnect {
17
18 public enum Reason {
19 SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT,
20 SSH_DISCONNECT_PROTOCOL_ERROR,
21 SSH_DISCONNECT_KEY_EXCHANGE_FAILED,
22 SSH_DISCONNECT_RESERVED,
23 SSH_DISCONNECT_MAC_ERROR,
24 SSH_DISCONNECT_COMPRESSION_ERROR,
25 SSH_DISCONNECT_SERVICE_NOT_AVAILABLE,
26 SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED,
27 SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE,
28 SSH_DISCONNECT_CONNECTION_LOST,
29 SSH_DISCONNECT_BY_APPLICATION,
30 SSH_DISCONNECT_TOO_MANY_CONNECTIONS,
31 SSH_DISCONNECT_AUTH_CANCELLED_BY_USER,
32 SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE,
33 SSH_DISCONNECT_ILLEGAL_USER_NAME
34 }
35
36 private final byte[] payload;
37
38 private final Reason reason;
39
40 private final String message;
41
42 public PacketDisconnect(byte payload[]) throws IOException {
43 this.payload = payload;
44
45 TypesReader tr = new TypesReader(payload);
46
47 int packet_type = tr.readByte();
48
49 if(packet_type != Packets.SSH_MSG_DISCONNECT) {
50 throw new PacketTypeException(packet_type);
51 }
52 reason = PacketDisconnect.Reason.values()[tr.readUINT32()];
53 message = tr.readString();
54 String lang = tr.readString();
55
56 if(tr.remain() != 0) {
57 throw new PacketFormatException(String.format("Padding in %s", Packets.getMessageName(packet_type)));
58 }
59 }
60
61 public PacketDisconnect(Reason reason, String desc) {
62 this.reason = reason;
63 this.message = desc;
64 TypesWriter tw = new TypesWriter();
65 tw.writeByte(Packets.SSH_MSG_DISCONNECT);
66 tw.writeUINT32(reason.ordinal());
67 tw.writeString(desc);
68 tw.writeString("");
69 payload = tw.getBytes();
70 }
71
72 public Reason getReason() {
73 return reason;
74 }
75
76 public String getMessage() {
77 return message;
78 }
79
80 public byte[] getPayload() {
81 return payload;
82 }
83 }