public byte[] decodeBytes(boolean implicit) throws Asn1Exception {
        byte[] retValue = null;

        //
        // There must be at least 2 bytes available
        //
        if (residualLength < 2)
            throw new Asn1Exception("Attempt to read past end of stream");

        //
        // Validate the tag for an explicit value
        //
        if (!implicit && stream[next] != ASN1_OCTETSTRING)
            throw new Asn1Exception("Field at offset "+next+" is not an OCTETSTRING");

        if ((stream[next]&ASN1_CONSTRUCTED) != 0)
            throw new Asn1Exception("OCTETSTRING must not be a constructed field");

        next++;
        residualLength--;

        //
        // Decode the field length
        //
        int length = decodeLength();

        if (length > residualLength)
            throw new Asn1Exception("Attempt to read past end of stream");

        //
        // Extract the octet string
        //
        retValue = new byte[length];
        if (length != 0) {
            System.arraycopy(stream, next, retValue, 0, length);
            next += length;
            residualLength -= length;
        }

        return retValue;
    }