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

📄 berinputstream.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:   BERInputStream.java

package jit.asn1;

import java.io.*;
import java.util.Vector;

// Referenced classes of package jit.asn1:
//            DERInputStream, DERObject, BERConstructedOctetString, BERConstructedSequence, 
//            ASN1EncodableVector, BERSet, BERTaggedObject, DEROctetString, 
//            DERTaggedObject, DEROutputStream

public class BERInputStream extends DERInputStream
{

    private DERObject END_OF_STREAM;

    public BERInputStream(InputStream is)
    {
        super(is);
        END_OF_STREAM = ((BERInputStream)this). new DERObject() {

            void encode(DEROutputStream out)
                throws IOException
            {
                throw new IOException("Eeek!");
            }

        };
    }

    private byte[] readIndefiniteLengthFully()
        throws IOException
    {
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        int b;
        for(int b1 = read(); (b = read()) >= 0 && (b1 != 0 || b != 0); b1 = b)
            bOut.write(b1);

        return bOut.toByteArray();
    }

    private BERConstructedOctetString buildConstructedOctetString()
        throws IOException
    {
        Vector octs = new Vector();
        do
        {
            DERObject o = readObject();
            if(o != END_OF_STREAM)
                octs.addElement(o);
            else
                return new BERConstructedOctetString(octs);
        } while(true);
    }

    public DERObject readObject()
        throws IOException
    {
        int tag = read();
        if(tag == -1)
            throw new EOFException();
        int length = readLength();
        if(length < 0)
        {
            switch(tag)
            {
            case 5: // '\005'
                return null;

            case 48: // '0'
                BERConstructedSequence seq = new BERConstructedSequence();
                do
                {
                    DERObject obj = readObject();
                    if(obj != END_OF_STREAM)
                        seq.addObject(obj);
                    else
                        return seq;
                } while(true);

            case 36: // '$'
                return buildConstructedOctetString();

            case 49: // '1'
                ASN1EncodableVector v = new ASN1EncodableVector();
                do
                {
                    DERObject obj = readObject();
                    if(obj != END_OF_STREAM)
                        v.add(obj);
                    else
                        return new BERSet(v);
                } while(true);
            }
            if((tag & 0x80) != 0)
            {
                if((tag & 0x1f) == 31)
                    throw new IOException("unsupported high tag encountered");
                if((tag & 0x20) == 0)
                {
                    byte bytes[] = readIndefiniteLengthFully();
                    return new BERTaggedObject(false, tag & 0x1f, new DEROctetString(bytes));
                }
                DERObject dObj = readObject();
                if(dObj == END_OF_STREAM)
                    return new DERTaggedObject(tag & 0x1f);
                DERObject next = readObject();
                if(next == END_OF_STREAM)
                    return new BERTaggedObject(tag & 0x1f, dObj);
                BERConstructedSequence seq = new BERConstructedSequence();
                seq.addObject(dObj);
                do
                {
                    seq.addObject(next);
                    next = readObject();
                } while(next != END_OF_STREAM);
                return new BERTaggedObject(false, tag & 0x1f, seq);
            } else
            {
                throw new IOException("unknown BER object encountered");
            }
        }
        if(tag == 0 && length == 0)
        {
            return END_OF_STREAM;
        } else
        {
            byte bytes[] = new byte[length];
            readFully(bytes);
            return buildObject(tag, bytes);
        }
    }
}

⌨️ 快捷键说明

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