⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 derinputstream.java

📁 进行与数字证书相关开发必须的java源码
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   DERInputStream.java

package jit.asn1;

import java.io.*;

// Referenced classes of package jit.asn1:
//            BERInputStream, DERConstructedSequence, DERObject, ASN1EncodableVector, 
//            DERConstructedSet, DERBoolean, DERInteger, DEREnumerated, 
//            DERObjectIdentifier, DERBitString, DERUTF8String, DERPrintableString, 
//            DERIA5String, DERT61String, DERVisibleString, DERUniversalString, 
//            DERBMPString, DEROctetString, DERUTCTime, DERGeneralizedTime, 
//            DERTaggedObject, DERNull, DEREncodable, DERUnknownTag, 
//            DERTags

public class DERInputStream extends FilterInputStream
    implements DERTags
{

    public DERInputStream(InputStream is)
    {
        super(is);
    }

    protected int readLength()
        throws IOException
    {
        int length = read();
        if(length < 0)
            throw new IOException("EOF found when length expected");
        if(length == 128)
            return -1;
        if(length > 127)
        {
            int size = length & 0x7f;
            length = 0;
            for(int i = 0; i < size; i++)
            {
                int next = read();
                if(next < 0)
                    throw new IOException("EOF found reading length");
                length = (length << 8) + next;
            }

        }
        return length;
    }

    protected void readFully(byte bytes[])
        throws IOException
    {
        int left = bytes.length;
        if(left == 0)
            return;
        int l;
        for(; left > 0; left -= l)
        {
            l = read(bytes, bytes.length - left, left);
            if(l < 0)
                throw new EOFException("unexpected end of stream");
        }

    }

    protected DERObject buildObject(int tag, byte bytes[])
        throws IOException
    {
        switch(tag)
        {
        case 5: // '\005'
            return null;

        case 48: // '0'
            ByteArrayInputStream bIn = new ByteArrayInputStream(bytes);
            BERInputStream dIn = new BERInputStream(bIn);
            DERConstructedSequence seq = new DERConstructedSequence();
            try
            {
                do
                {
                    DERObject obj = dIn.readObject();
                    seq.addObject(obj);
                } while(true);
            }
            catch(EOFException ex)
            {
                DERConstructedSequence derconstructedsequence = seq;
                return derconstructedsequence;
            }

        case 49: // '1'
            ByteArrayInputStream bIn = new ByteArrayInputStream(bytes);
            BERInputStream dIn = new BERInputStream(bIn);
            ASN1EncodableVector v = new ASN1EncodableVector();
            try
            {
                do
                {
                    DERObject obj = dIn.readObject();
                    v.add(obj);
                } while(true);
            }
            catch(EOFException ex)
            {
                DERConstructedSet derconstructedset = new DERConstructedSet(v);
                return derconstructedset;
            }

        case 1: // '\001'
            return new DERBoolean(bytes);

        case 2: // '\002'
            return new DERInteger(bytes);

        case 10: // '\n'
            return new DEREnumerated(bytes);

        case 6: // '\006'
            return new DERObjectIdentifier(bytes);

        case 3: // '\003'
            int padBits = bytes[0];
            byte data[] = new byte[bytes.length - 1];
            System.arraycopy(bytes, 1, data, 0, bytes.length - 1);
            return new DERBitString(data, padBits);

        case 12: // '\f'
            return new DERUTF8String(bytes);

        case 19: // '\023'
            return new DERPrintableString(bytes);

        case 22: // '\026'
            return new DERIA5String(bytes);

        case 20: // '\024'
            return new DERT61String(bytes);

        case 26: // '\032'
            return new DERVisibleString(bytes);

        case 28: // '\034'
            return new DERUniversalString(bytes);

        case 30: // '\036'
            return new DERBMPString(bytes);

        case 4: // '\004'
            return new DEROctetString(bytes);

        case 23: // '\027'
            return new DERUTCTime(bytes);

        case 24: // '\030'
            return new DERGeneralizedTime(bytes);
        }
        if((tag & 0x80) != 0)
        {
            if((tag & 0x1f) == 31)
                throw new IOException("unsupported high tag encountered");
            if(bytes.length == 0)
                if((tag & 0x20) == 0)
                    return new DERTaggedObject(false, tag & 0x1f, new DERNull());
                else
                    return new DERTaggedObject(false, tag & 0x1f, new DERConstructedSequence());
            if((tag & 0x20) == 0)
                return new DERTaggedObject(false, tag & 0x1f, new DEROctetString(bytes));
            ByteArrayInputStream bIn = new ByteArrayInputStream(bytes);
            BERInputStream dIn = new BERInputStream(bIn);
            DEREncodable dObj = dIn.readObject();
            if(dIn.available() == 0)
                return new DERTaggedObject(tag & 0x1f, dObj);
            DERConstructedSequence seq = new DERConstructedSequence();
            seq.addObject(dObj);
            do
                try
                {
                    dObj = dIn.readObject();
                    seq.addObject(dObj);
                }
                catch(EOFException eofexception)
                {
                    return new DERTaggedObject(false, tag & 0x1f, seq);
                }
            while(true);
        } else
        {
            return new DERUnknownTag(tag, bytes);
        }
    }

    public DERObject readObject()
        throws IOException
    {
        int tag = read();
        if(tag == -1)
        {
            throw new EOFException();
        } else
        {
            int length = readLength();
            byte bytes[] = new byte[length];
            readFully(bytes);
            return buildObject(tag, bytes);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -