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

📄 derinputstream.java

📁 java 文件下载器。可自定义
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   DERInputStream.java

package org.bouncycastle.asn1;

import java.io.*;

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

/**
 * @deprecated Class DERInputStream is deprecated
 */

public class DERInputStream extends FilterInputStream
	implements DERTags
{

	/**
	 * @deprecated Method DERInputStream is deprecated
	 */

	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;
			if (size > 4)
				throw new IOException("DER length more than 4 bytes");
			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;
			}

			if (length < 0)
				throw new IOException("corrupted stream - negative length found");
		}
		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();
			do
				try
				{
					DERObject obj = dIn.readObject();
					seq.addObject(obj);
				}
				catch (EOFException ex)
				{
					return seq;
				}
			while (true);
		}

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

		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 27: // '\033'
		{
			return new DERGeneralString(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 ex)
				{
					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 + -