169 */ 170 public int parseEnumeration() throws DecodeException { 171 return parseIntWithTag(ASN_ENUMERATED); 172 } 173 174 /** 175 * Parses an ASN_INTEGER tagged integer from this BER buffer. 176 * @return The value of the integer. 177 */ 178 public int parseInt() throws DecodeException { 179 return parseIntWithTag(ASN_INTEGER); 180 } 181 182 /** 183 * Parses an integer that's preceded by a tag. 184 *<blockquote><pre> 185 * BER integer ::= tag length byte {byte}* 186 *</pre></blockquote> 187 */ 188 private int parseIntWithTag(int tag) throws DecodeException { 189 190 191 if (parseByte() != tag) { 192 throw new DecodeException("Encountered ASN.1 tag " + 193 Integer.toString(buf[offset - 1] & 0xff) + 194 " (expected tag " + Integer.toString(tag) + ")"); 195 } 196 197 int len = parseLength(); 198 199 if (len > 4) { 200 throw new DecodeException("INTEGER too long"); 201 } else if (len > bufsize - offset) { 202 throw new DecodeException("Insufficient data"); 203 } 204 205 byte fb = buf[offset++]; 206 int value = 0; 207 208 value = fb & 0x7F; 209 for( int i = 1 /* first byte already read */ ; i < len; i++) { 210 value <<= 8; 211 value |= (buf[offset++] & 0xff); 212 } 213 214 if ((fb & 0x80) == 0x80) { | 169 */ 170 public int parseEnumeration() throws DecodeException { 171 return parseIntWithTag(ASN_ENUMERATED); 172 } 173 174 /** 175 * Parses an ASN_INTEGER tagged integer from this BER buffer. 176 * @return The value of the integer. 177 */ 178 public int parseInt() throws DecodeException { 179 return parseIntWithTag(ASN_INTEGER); 180 } 181 182 /** 183 * Parses an integer that's preceded by a tag. 184 *<blockquote><pre> 185 * BER integer ::= tag length byte {byte}* 186 *</pre></blockquote> 187 */ 188 private int parseIntWithTag(int tag) throws DecodeException { 189 if (parseByte() != tag) { 190 // Ber could have been reset; 191 String s; 192 if (offset > 0) { 193 s = Integer.toString(buf[offset - 1] & 0xff); 194 } else { 195 s = "Empty tag"; 196 } 197 throw new DecodeException("Encountered ASN.1 tag " + 198 s + " (expected tag " + Integer.toString(tag) + ")"); 199 } 200 201 int len = parseLength(); 202 203 if (len > 4) { 204 throw new DecodeException("INTEGER too long"); 205 } else if (len > bufsize - offset) { 206 throw new DecodeException("Insufficient data"); 207 } 208 209 byte fb = buf[offset++]; 210 int value = 0; 211 212 value = fb & 0x7F; 213 for( int i = 1 /* first byte already read */ ; i < len; i++) { 214 value <<= 8; 215 value |= (buf[offset++] & 0xff); 216 } 217 218 if ((fb & 0x80) == 0x80) { |