594 lines · 20.1 KB · Java
RawDownload
    /**     * Get a Generalized encoded time value from the input stream.     */    public Date getGeneralizedTime() throws IOException {        if (buffer.read() != DerValue.tag_GeneralizedTime)            throw new IOException("DER input, GeneralizedTime tag invalid ");        return buffer.getGeneralizedTime(getLength(buffer));    }     /*     * Get a byte from the input stream.     */    // package private    int getByte() throws IOException {        return (0x00ff & buffer.read());    }     public int peekByte() throws IOException {        return buffer.peek();    }     // package private    int getLength() throws IOException {        return getLength(buffer);    }     /*     * Get a length from the input stream, allowing for at most 32 bits of     * encoding to be used.  (Not the same as getting a tagged integer!)     *     * @return the length or -1 if indefinite length found.     * @exception IOException on parsing error or unsupported lengths.     */    static int getLength(InputStream in) throws IOException {        return getLength(in.read(), in);    }     /*     * Get a length from the input stream, allowing for at most 32 bits of     * encoding to be used.  (Not the same as getting a tagged integer!)     *     * @return the length or -1 if indefinite length found.     * @exception IOException on parsing error or unsupported lengths.     */    static int getLength(int lenByte, InputStream in) throws IOException {        int value, tmp;         tmp = lenByte;        if ((tmp & 0x080) == 0x00) { // short form, 1 byte datum            value = tmp;        } else {                     // long form or indefinite            tmp &= 0x07f;             /*             * NOTE:  tmp == 0 indicates indefinite length encoded data.             * tmp > 4 indicates more than 4Gb of data.             */            if (tmp == 0)                return -1;            if (tmp < 0 || tmp > 4)                throw new IOException("DerInputStream.getLength(): lengthTag="                    + tmp + ", "                    + ((tmp < 0) ? "incorrect DER encoding." : "too big."));             for (value = 0; tmp > 0; tmp --) {                value <<= 8;                value += 0x0ff & in.read();            }        }        return value;    }     /**     * Mark the current position in the buffer, so that     * a later call to <code>reset</code> will return here.     */    public void mark(int value) { buffer.mark(value); }      /**     * Return to the position of the last <code>mark</code>     * call.  A mark is implicitly set at the beginning of     * the stream when it is created.     */    public void reset() { buffer.reset(); }      /**     * Returns the number of bytes available for reading.     * This is most useful for testing whether the stream is     * empty.     */    public int available() { return buffer.available(); }}

Lines 501–594 of 594. Previous lines