/** * Resets this stream to initial state. * * @param encoded a new bytes array to be decoded * @throws IOException if an error occurs */ public final void reset(byte[] encoded) throws IOException { buffer = encoded; next(); }
public int next() throws IOException { int tag = super.next(); if (length == INDEFINIT_LENGTH) { throw new ASN1Exception("DER: only definite length encoding MUST be used"); } // FIXME add check: length encoding uses minimum number of octets return tag; }
/** * Creates stream for decoding. * * @param encoded bytes array to be decoded * @param offset the encoding offset * @param expectedLength expected length of full encoding, this includes * identifier, length an content octets */ public BerInputStream(byte[] encoded, int offset, int expectedLength) throws IOException { this.in = null; this.buffer = encoded; this.offset = offset; next(); // compare expected and decoded length if (length != INDEFINIT_LENGTH && (offset + expectedLength) != (this.offset + this.length)) { throw new ASN1Exception("Wrong content length"); } }
/** * Creates stream for decoding. * * @param initialSize the internal buffer initial size */ public BerInputStream(InputStream in, int initialSize) throws IOException { this.in = in; buffer = new byte[initialSize]; next(); if (length != INDEFINIT_LENGTH) { // input stream has definite length encoding // check allocated length to avoid further reallocations if (buffer.length < (length + offset)) { byte[] newBuffer = new byte[length + offset]; System.arraycopy(buffer, 0, newBuffer, 0, offset); buffer = newBuffer; } } else { isIndefinedLength = true; throw new ASN1Exception("Decoding indefinite length encoding is not supported"); } }
public Object decode(BerInputStream in) throws IOException { if (constrId != in.tag) { throw new ASN1Exception("ASN.1 explicitly tagged type is expected at [" + in.tagOffset + "]. Expected tag: " + Integer.toHexString(constrId) + ", " + "but encountered tag " + Integer.toHexString(in.tag)); } in.next(); in.content = type.decode(in); if (in.isVerify) { return null; } return getDecodedObject(in); }
private void decodeValueCollection(ASN1ValueCollection collection) throws IOException { int begOffset = offset; int endOffset = begOffset + length; ASN1Type type = collection.type; if (isVerify) { while (endOffset > offset) { next(); type.decode(this); } } else { int seqTagOffset = tagOffset; //store tag offset ArrayList<Object> values = new ArrayList<Object>(); while (endOffset > offset) { next(); values.add(type.decode(this)); } values.trimToSize(); content = values; tagOffset = seqTagOffset; //retrieve tag offset } if (offset != endOffset) { throw new ASN1Exception("Wrong encoding at [" + begOffset + "]. Content's length and encoded length are not the same"); } }
: new BerInputStream(encoding); second_asn1_tag = in.next(); // inStream position changed if (encoding == null) {
: new BerInputStream(encoding); second_asn1_tag = in.next(); if (encoding == null) {
/** * Resets this stream to initial state. * * @param encoded a new bytes array to be decoded * @throws IOException if an error occurs */ public final void reset(byte[] encoded) throws IOException { buffer = encoded; next(); }
/** * Resets this stream to initial state. * * @param encoded a new bytes array to be decoded * @throws IOException if an error occurs */ public final void reset(byte[] encoded) throws IOException { buffer = encoded; next(); }
/** * Resets this stream to initial state. * * @param encoded a new bytes array to be decoded * @throws IOException if an error occurs */ public final void reset(byte[] encoded) throws IOException { buffer = encoded; next(); }
/** * Resets this stream to initial state. * * @param encoded a new bytes array to be decoded * @throws IOException if an error occurs */ public final void reset(byte[] encoded) throws IOException { buffer = encoded; next(); }
/** * Resets this stream to initial state. * * @param encoded a new bytes array to be decoded * @throws IOException if an error occurs */ public final void reset(byte[] encoded) throws IOException { buffer = encoded; next(); }
public int next() throws IOException { int tag = super.next(); if (length == INDEFINIT_LENGTH) { throw new ASN1Exception("DER: only definite length encoding MUST be used"); } // FIXME add check: length encoding uses minimum number of octets return tag; }
public int next() throws IOException { int tag = super.next(); if (length == INDEFINIT_LENGTH) { throw new ASN1Exception("DER: only definite length encoding MUST be used"); } // FIXME add check: length encoding uses minimum number of octets return tag; }
public int next() throws IOException { int tag = super.next(); if (length == INDEFINIT_LENGTH) { throw new ASN1Exception("DER: only definite length encoding MUST be used"); } // FIXME add check: length encoding uses minimum number of octets return tag; }
public int next() throws IOException { int tag = super.next(); if (length == INDEFINIT_LENGTH) { throw new ASN1Exception("DER: only definite length encoding MUST be used"); } // FIXME add check: length encoding uses minimum number of octets return tag; }
public int next() throws IOException { int tag = super.next(); if (length == INDEFINIT_LENGTH) { throw new ASN1Exception("DER: only definite length encoding MUST be used"); } // FIXME add check: length encoding uses minimum number of octets return tag; }
public Object decode(BerInputStream in) throws IOException { if (constrId != in.tag) { throw new ASN1Exception("ASN.1 explicitly tagged type is expected at [" + in.tagOffset + "]. Expected tag: " + Integer.toHexString(constrId) + ", " + "but encountered tag " + Integer.toHexString(in.tag)); } in.next(); in.content = type.decode(in); if (in.isVerify) { return null; } return getDecodedObject(in); }