comparison src/ch/ethz/ssh2/packets/PacketChannelOpenFailure.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
11 /**
12 * @author Christian Plattner
13 * @version $Id: PacketChannelOpenFailure.java 160 2014-05-01 14:30:26Z dkocher@sudo.ch $
14 */
15 public final class PacketChannelOpenFailure {
16
17 private final byte[] payload;
18
19 public PacketChannelOpenFailure(int recipientChannelID, int reasonCode, String description,
20 String languageTag) {
21 TypesWriter tw = new TypesWriter();
22 tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN_FAILURE);
23 tw.writeUINT32(recipientChannelID);
24 tw.writeUINT32(reasonCode);
25 tw.writeString(description);
26 tw.writeString(languageTag);
27 payload = tw.getBytes();
28 }
29
30 public PacketChannelOpenFailure(byte payload[]) throws IOException {
31 this.payload = payload;
32
33 TypesReader tr = new TypesReader(payload);
34
35 int packet_type = tr.readByte();
36
37 if(packet_type != Packets.SSH_MSG_CHANNEL_OPEN_FAILURE) {
38 throw new IOException(
39 "This is not a SSH_MSG_CHANNEL_OPEN_FAILURE! ("
40 + packet_type + ")"
41 );
42 }
43
44 int recipientChannelID = tr.readUINT32();
45 int reasonCode = tr.readUINT32();
46 String description = tr.readString();
47 String languageTag = tr.readString();
48
49 if(tr.remain() != 0) {
50 throw new PacketFormatException(String.format("Padding in %s", Packets.getMessageName(packet_type)));
51 }
52 }
53
54 public byte[] getPayload() {
55 return payload;
56 }
57 }