278 }
279
280 if (rlen != null) {
281 rlen[0] = offset - origOffset;
282 }
283
284 return retstr;
285 }
286
287 /**
288 * Parses an octet string of a given type(tag) from this BER buffer.
289 * <blockquote><pre>
290 * BER Binary Data of type "tag" ::= tag length {byte}*
291 *</pre></blockquote>
292 *
293 * @param tag The tag to look for.
294 * @param rlen An array for returning the relative parsed position. If null,
295 * the relative parsed position is not returned.
296 * @return A non-null array containing the octet string.
297 * @throws DecodeException If the next byte in the BER buffer is not
298 * <tt>tag</tt>, or if length specified in the BER buffer exceeds the
299 * number of bytes left in the buffer.
300 */
301 public byte[] parseOctetString(int tag, int rlen[]) throws DecodeException {
302
303 int origOffset = offset;
304 int st;
305 if ((st = parseByte()) != tag) {
306
307 throw new DecodeException("Encountered ASN.1 tag " +
308 Integer.toString(st) +
309 " (expected tag " + Integer.toString(tag) + ")");
310 }
311
312 int len = parseLength();
313
314 if (len > bufsize - offset) {
315 throw new DecodeException("Insufficient data");
316 }
317
318 byte retarr[] = new byte[len];
|
278 }
279
280 if (rlen != null) {
281 rlen[0] = offset - origOffset;
282 }
283
284 return retstr;
285 }
286
287 /**
288 * Parses an octet string of a given type(tag) from this BER buffer.
289 * <blockquote><pre>
290 * BER Binary Data of type "tag" ::= tag length {byte}*
291 *</pre></blockquote>
292 *
293 * @param tag The tag to look for.
294 * @param rlen An array for returning the relative parsed position. If null,
295 * the relative parsed position is not returned.
296 * @return A non-null array containing the octet string.
297 * @throws DecodeException If the next byte in the BER buffer is not
298 * {@code tag}, or if length specified in the BER buffer exceeds the
299 * number of bytes left in the buffer.
300 */
301 public byte[] parseOctetString(int tag, int rlen[]) throws DecodeException {
302
303 int origOffset = offset;
304 int st;
305 if ((st = parseByte()) != tag) {
306
307 throw new DecodeException("Encountered ASN.1 tag " +
308 Integer.toString(st) +
309 " (expected tag " + Integer.toString(tag) + ")");
310 }
311
312 int len = parseLength();
313
314 if (len > bufsize - offset) {
315 throw new DecodeException("Insufficient data");
316 }
317
318 byte retarr[] = new byte[len];
|