comparison src/ch/ethz/ssh2/packets/TypesReader.java @ 307:071eccdff8ea ganymed

fix java formatting
author Carl Byington <carl@five-ten-sg.com>
date Wed, 30 Jul 2014 14:16:58 -0700
parents 91a31873c42a
children
comparison
equal deleted inserted replaced
305:d2b303406d63 307:071eccdff8ea
28 public TypesReader(byte[] arr, int off) { 28 public TypesReader(byte[] arr, int off) {
29 this.arr = arr; 29 this.arr = arr;
30 this.pos = off; 30 this.pos = off;
31 this.max = arr.length; 31 this.max = arr.length;
32 32
33 if((pos < 0) || (pos > arr.length)) { 33 if ((pos < 0) || (pos > arr.length)) {
34 throw new IllegalArgumentException("Illegal offset."); 34 throw new IllegalArgumentException("Illegal offset.");
35 } 35 }
36 } 36 }
37 37
38 public TypesReader(byte[] arr, int off, int len) { 38 public TypesReader(byte[] arr, int off, int len) {
39 this.arr = arr; 39 this.arr = arr;
40 this.pos = off; 40 this.pos = off;
41 this.max = off + len; 41 this.max = off + len;
42 42
43 if((pos < 0) || (pos > arr.length)) { 43 if ((pos < 0) || (pos > arr.length)) {
44 throw new IllegalArgumentException("Illegal offset."); 44 throw new IllegalArgumentException("Illegal offset.");
45 } 45 }
46 46
47 if((max < 0) || (max > arr.length)) { 47 if ((max < 0) || (max > arr.length)) {
48 throw new IllegalArgumentException("Illegal length."); 48 throw new IllegalArgumentException("Illegal length.");
49 } 49 }
50 } 50 }
51 51
52 public int readByte() throws IOException { 52 public int readByte() throws IOException {
53 if(pos >= max) { 53 if (pos >= max) {
54 throw new PacketFormatException("Packet too short."); 54 throw new PacketFormatException("Packet too short.");
55 } 55 }
56 56
57 return (arr[pos++] & 0xff); 57 return (arr[pos++] & 0xff);
58 } 58 }
59 59
60 public byte[] readBytes(int len) throws IOException { 60 public byte[] readBytes(int len) throws IOException {
61 if((pos + len) > max) { 61 if ((pos + len) > max) {
62 throw new PacketFormatException("Packet too short."); 62 throw new PacketFormatException("Packet too short.");
63 } 63 }
64 64
65 byte[] res = new byte[len]; 65 byte[] res = new byte[len];
66
67 System.arraycopy(arr, pos, res, 0, len); 66 System.arraycopy(arr, pos, res, 0, len);
68 pos += len; 67 pos += len;
69
70 return res; 68 return res;
71 } 69 }
72 70
73 public void readBytes(byte[] dst, int off, int len) throws IOException { 71 public void readBytes(byte[] dst, int off, int len) throws IOException {
74 if((pos + len) > max) { 72 if ((pos + len) > max) {
75 throw new PacketFormatException("Packet too short."); 73 throw new PacketFormatException("Packet too short.");
76 } 74 }
77 75
78 System.arraycopy(arr, pos, dst, off, len); 76 System.arraycopy(arr, pos, dst, off, len);
79 pos += len; 77 pos += len;
80 } 78 }
81 79
82 public boolean readBoolean() throws IOException { 80 public boolean readBoolean() throws IOException {
83 if(pos >= max) { 81 if (pos >= max) {
84 throw new PacketFormatException("Packet too short."); 82 throw new PacketFormatException("Packet too short.");
85 } 83 }
86 84
87 return (arr[pos++] != 0); 85 return (arr[pos++] != 0);
88 } 86 }
89 87
90 public int readUINT32() throws IOException { 88 public int readUINT32() throws IOException {
91 if((pos + 4) > max) { 89 if ((pos + 4) > max) {
92 throw new PacketFormatException("Packet too short."); 90 throw new PacketFormatException("Packet too short.");
93 } 91 }
94 92
95 return ((arr[pos++] & 0xff) << 24) | ((arr[pos++] & 0xff) << 16) | ((arr[pos++] & 0xff) << 8) 93 return ((arr[pos++] & 0xff) << 24) | ((arr[pos++] & 0xff) << 16) | ((arr[pos++] & 0xff) << 8)
96 | (arr[pos++] & 0xff); 94 | (arr[pos++] & 0xff);
97 } 95 }
98 96
99 public long readUINT64() throws IOException { 97 public long readUINT64() throws IOException {
100 if((pos + 8) > max) { 98 if ((pos + 8) > max) {
101 throw new PacketFormatException("Packet too short."); 99 throw new PacketFormatException("Packet too short.");
102 } 100 }
103 101
104 long high = ((arr[pos++] & 0xff) << 24) | ((arr[pos++] & 0xff) << 16) | ((arr[pos++] & 0xff) << 8) 102 long high = ((arr[pos++] & 0xff) << 24) | ((arr[pos++] & 0xff) << 16) | ((arr[pos++] & 0xff) << 8)
105 | (arr[pos++] & 0xff); /* sign extension may take place - will be shifted away =) */ 103 | (arr[pos++] & 0xff); /* sign extension may take place - will be shifted away =) */
106
107 long low = ((arr[pos++] & 0xff) << 24) | ((arr[pos++] & 0xff) << 16) | ((arr[pos++] & 0xff) << 8) 104 long low = ((arr[pos++] & 0xff) << 24) | ((arr[pos++] & 0xff) << 16) | ((arr[pos++] & 0xff) << 8)
108 | (arr[pos++] & 0xff); /* sign extension may take place - handle below */ 105 | (arr[pos++] & 0xff); /* sign extension may take place - handle below */
109
110 return (high << 32) | (low & 0xffffffffl); /* see Java language spec (15.22.1, 5.6.2) */ 106 return (high << 32) | (low & 0xffffffffl); /* see Java language spec (15.22.1, 5.6.2) */
111 } 107 }
112 108
113 public BigInteger readMPINT() throws IOException { 109 public BigInteger readMPINT() throws IOException {
114 BigInteger b; 110 BigInteger b;
115
116 byte raw[] = readByteString(); 111 byte raw[] = readByteString();
117 112
118 if(raw.length == 0) { 113 if (raw.length == 0) {
119 b = BigInteger.ZERO; 114 b = BigInteger.ZERO;
120 } 115 }
121 else { 116 else {
122 b = new BigInteger(raw); 117 b = new BigInteger(raw);
123 } 118 }
126 } 121 }
127 122
128 public byte[] readByteString() throws IOException { 123 public byte[] readByteString() throws IOException {
129 int len = readUINT32(); 124 int len = readUINT32();
130 125
131 if((len + pos) > max) { 126 if ((len + pos) > max) {
132 throw new PacketFormatException("Malformed SSH byte string."); 127 throw new PacketFormatException("Malformed SSH byte string.");
133 } 128 }
134 129
135 byte[] res = new byte[len]; 130 byte[] res = new byte[len];
136 System.arraycopy(arr, pos, res, 0, len); 131 System.arraycopy(arr, pos, res, 0, len);
139 } 134 }
140 135
141 public String readString(String charsetName) throws IOException { 136 public String readString(String charsetName) throws IOException {
142 int len = readUINT32(); 137 int len = readUINT32();
143 138
144 if((len + pos) > max) { 139 if ((len + pos) > max) {
145 throw new PacketFormatException("Malformed SSH string."); 140 throw new PacketFormatException("Malformed SSH string.");
146 } 141 }
147 142
148 String res = (charsetName == null) ? new String(arr, pos, len) : new String(arr, pos, len, charsetName); 143 String res = (charsetName == null) ? new String(arr, pos, len) : new String(arr, pos, len, charsetName);
149 pos += len; 144 pos += len;
150
151 return res; 145 return res;
152 } 146 }
153 147
154 public String readString() throws IOException { 148 public String readString() throws IOException {
155 int len = readUINT32(); 149 int len = readUINT32();
156 150
157 if((len + pos) > max) { 151 if ((len + pos) > max) {
158 throw new PacketFormatException("Malformed SSH string."); 152 throw new PacketFormatException("Malformed SSH string.");
159 } 153 }
160 154
161 String res = StringEncoder.GetString(arr, pos, len); 155 String res = StringEncoder.GetString(arr, pos, len);
162 pos += len; 156 pos += len;
163
164 return res; 157 return res;
165 } 158 }
166 159
167 public String[] readNameList() throws IOException { 160 public String[] readNameList() throws IOException {
168 return readString().split(","); 161 return readString().split(",");