📄 derbitstring.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: DERBitString.java
package jit.asn1;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
// Referenced classes of package jit.asn1:
// DERObject, ASN1OctetString, ASN1TaggedObject, DEROutputStream,
// DEREncodable
public class DERBitString extends DERObject
{
protected byte data[];
protected int padBits;
protected static int getPadBits(int bitString)
{
if(bitString == 0)
return 7;
int tmp = 0;
int val;
if(bitString > 255)
{
if(bitString >> 8 > 255)
{
if(bitString >> 16 > 255)
tmp = 24;
else
tmp = 16;
} else
{
tmp = 8;
}
val = bitString >> tmp & 0xff;
} else
{
val = bitString & 0xff;
}
int bits;
for(bits = 1; ((val <<= 1) & 0xff) != 0; bits++);
return 8 - bits;
}
protected static byte[] getBytes(int bitString)
{
int bitLen = 0;
if(bitString >> 24 > 0)
bitLen = 4;
else
if(bitString >> 16 > 0)
bitLen = 3;
else
if(bitString >> 8 > 0)
bitLen = 2;
else
bitLen = 1;
byte bytes[] = new byte[bitLen];
for(int i = 0; i < bitLen; i++)
bytes[i] = (byte)(bitString >> i * 8 & 0xff);
return bytes;
}
public static DERBitString getInstance(Object obj)
{
if(obj == null || (obj instanceof DERBitString))
return (DERBitString)obj;
if(obj instanceof ASN1OctetString)
{
byte bytes[] = ((ASN1OctetString)obj).getOctets();
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);
}
if(obj instanceof ASN1TaggedObject)
return getInstance(((ASN1TaggedObject)obj).getObject());
else
throw new IllegalArgumentException("illegal object in getInstance: ".concat(String.valueOf(String.valueOf(obj.getClass().getName()))));
}
public static DERBitString getInstance(ASN1TaggedObject obj, boolean explicit)
{
return getInstance(obj.getObject());
}
protected DERBitString(byte data, int padBits)
{
this.data = new byte[4];
this.data[0] = data;
this.padBits = padBits;
}
public DERBitString(byte data[], int padBits)
{
this.data = data;
this.padBits = padBits;
}
public DERBitString(byte data[])
{
this(data, 0);
}
public DERBitString(DEREncodable obj)
{
try
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
dOut.writeObject(obj);
dOut.close();
data = bOut.toByteArray();
padBits = 0;
}
catch(IOException e)
{
throw new IllegalArgumentException("Error processing object : ".concat(String.valueOf(String.valueOf(e.toString()))));
}
}
public byte[] getBytes()
{
return data;
}
public int getPadBits()
{
return padBits;
}
void encode(DEROutputStream out)
throws IOException
{
byte bytes[] = new byte[getBytes().length + 1];
bytes[0] = (byte)getPadBits();
System.arraycopy(getBytes(), 0, bytes, 1, bytes.length - 1);
out.writeEncoded(3, bytes);
}
public boolean equals(Object o)
{
if(o == null || !(o instanceof DERBitString))
return false;
DERBitString other = (DERBitString)o;
if(data.length != other.data.length)
return false;
for(int i = 0; i != data.length; i++)
if(data[i] != other.data[i])
return false;
return padBits == other.padBits;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -