📄 asn1streamparser.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: ASN1StreamParser.java
package org.bouncycastle.asn1;
import java.io.*;
// Referenced classes of package org.bouncycastle.asn1:
// ASN1EncodableVector, ASN1InputStream, ASN1ObjectParser, BERNull,
// BEROctetStringParser, BERSequenceParser, BERSetParser, BERTaggedObjectParser,
// DERInteger, DERNull, DERObjectIdentifier, DEROctetString,
// DERSequence, DERSet, DefiniteLengthInputStream, IndefiniteLengthInputStream,
// DEREncodable
public class ASN1StreamParser
{
InputStream _in;
private int _limit;
private boolean _eofFound;
public ASN1StreamParser(InputStream in)
{
this(in, 0x7fffffff);
}
public ASN1StreamParser(InputStream in, int limit)
{
_in = in;
_limit = limit;
}
public ASN1StreamParser(byte encoding[])
{
this(((InputStream) (new ByteArrayInputStream(encoding))), encoding.length);
}
InputStream getParentStream()
{
return _in;
}
private int readLength()
throws IOException
{
int length = _in.read();
if (length < 0)
throw new EOFException("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 = _in.read();
if (next < 0)
throw new EOFException("EOF found reading length");
length = (length << 8) + next;
}
if (length < 0)
throw new IOException("corrupted stream - negative length found");
if (length >= _limit)
throw new IOException("corrupted stream - out of bounds length found");
}
return length;
}
public DEREncodable readObject()
throws IOException
{
int tag = _in.read();
if (tag == -1)
if (_eofFound)
{
throw new EOFException("attempt to read past end of file.");
} else
{
_eofFound = true;
return null;
}
set00Check(false);
int baseTagNo = tag & 0xffffffdf;
int tagNo = baseTagNo;
if ((tag & 0x80) != 0)
{
tagNo = tag & 0x1f;
if (tagNo == 31)
{
tagNo = 0;
int b;
for (b = _in.read(); b >= 0 && (b & 0x80) != 0; b = _in.read())
{
tagNo |= b & 0x7f;
tagNo <<= 7;
}
if (b < 0)
{
_eofFound = true;
throw new EOFException("EOF encountered inside tag value.");
}
tagNo |= b & 0x7f;
}
}
int length = readLength();
if (length < 0)
{
IndefiniteLengthInputStream indIn = new IndefiniteLengthInputStream(_in);
switch (baseTagNo)
{
case 5: // '\005'
while (indIn.read() >= 0) ;
return BERNull.INSTANCE;
case 4: // '\004'
return new BEROctetStringParser(new ASN1ObjectParser(tag, tagNo, indIn));
case 16: // '\020'
return new BERSequenceParser(new ASN1ObjectParser(tag, tagNo, indIn));
case 17: // '\021'
return new BERSetParser(new ASN1ObjectParser(tag, tagNo, indIn));
}
return new BERTaggedObjectParser(tag, tagNo, indIn);
}
DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(_in, length);
switch (baseTagNo)
{
case 2: // '\002'
return new DERInteger(defIn.toByteArray());
case 5: // '\005'
defIn.toByteArray();
return DERNull.INSTANCE;
case 6: // '\006'
return new DERObjectIdentifier(defIn.toByteArray());
case 4: // '\004'
return new DEROctetString(defIn.toByteArray());
case 16: // '\020'
return (new DERSequence(loadVector(defIn, length))).parser();
case 17: // '\021'
return (new DERSet(loadVector(defIn, length))).parser();
case 3: // '\003'
case 7: // '\007'
case 8: // '\b'
case 9: // '\t'
case 10: // '\n'
case 11: // '\013'
case 12: // '\f'
case 13: // '\r'
case 14: // '\016'
case 15: // '\017'
default:
return new BERTaggedObjectParser(tag, tagNo, defIn);
}
}
private void set00Check(boolean enabled)
{
if (_in instanceof IndefiniteLengthInputStream)
((IndefiniteLengthInputStream)_in).setEofOn00(enabled);
}
private ASN1EncodableVector loadVector(InputStream in, int length)
throws IOException
{
ASN1InputStream aIn = new ASN1InputStream(in, length);
ASN1EncodableVector v = new ASN1EncodableVector();
DERObject obj;
while ((obj = aIn.readObject()) != null)
v.add(obj);
return v;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -