94 lines
3.2 KiB
Java
94 lines
3.2 KiB
Java
package org.bouncycastle.asn1;
|
|
|
|
import java.io.IOException;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class DERBitString extends ASN1BitString {
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
|
public boolean isConstructed() {
|
|
return false;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
|
public int encodedLength() {
|
|
return StreamUtil.calculateBodyLength(this.data.length + 1) + 1 + this.data.length + 1;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // org.bouncycastle.asn1.ASN1BitString, org.bouncycastle.asn1.ASN1Primitive
|
|
public void encode(ASN1OutputStream aSN1OutputStream) throws IOException {
|
|
byte[] derForm = derForm(this.data, this.padBits);
|
|
int length = derForm.length;
|
|
byte[] bArr = new byte[length + 1];
|
|
bArr[0] = (byte) getPadBits();
|
|
System.arraycopy(derForm, 0, bArr, 1, length);
|
|
aSN1OutputStream.writeEncoded(3, bArr);
|
|
}
|
|
|
|
private static byte[] toByteArray(byte b) {
|
|
return new byte[]{b};
|
|
}
|
|
|
|
public static DERBitString getInstance(ASN1TaggedObject aSN1TaggedObject, boolean z) {
|
|
ASN1Primitive object = aSN1TaggedObject.getObject();
|
|
return (z || (object instanceof DERBitString)) ? getInstance(object) : fromOctetString(((ASN1OctetString) object).getOctets());
|
|
}
|
|
|
|
public static DERBitString getInstance(Object obj) {
|
|
if (obj == null || (obj instanceof DERBitString)) {
|
|
return (DERBitString) obj;
|
|
}
|
|
if (obj instanceof DLBitString) {
|
|
DLBitString dLBitString = (DLBitString) obj;
|
|
return new DERBitString(dLBitString.data, dLBitString.padBits);
|
|
}
|
|
if (!(obj instanceof byte[])) {
|
|
StringBuilder sb = new StringBuilder("illegal object in getInstance: ");
|
|
sb.append(obj.getClass().getName());
|
|
throw new IllegalArgumentException(sb.toString());
|
|
}
|
|
try {
|
|
return (DERBitString) fromByteArray((byte[]) obj);
|
|
} catch (Exception e) {
|
|
StringBuilder sb2 = new StringBuilder("encoding error in getInstance: ");
|
|
sb2.append(e.toString());
|
|
throw new IllegalArgumentException(sb2.toString());
|
|
}
|
|
}
|
|
|
|
static DERBitString fromOctetString(byte[] bArr) {
|
|
if (bArr.length <= 0) {
|
|
throw new IllegalArgumentException("truncated BIT STRING detected");
|
|
}
|
|
byte b = bArr[0];
|
|
int length = bArr.length - 1;
|
|
byte[] bArr2 = new byte[length];
|
|
if (length != 0) {
|
|
System.arraycopy(bArr, 1, bArr2, 0, bArr.length - 1);
|
|
}
|
|
return new DERBitString(bArr2, b);
|
|
}
|
|
|
|
public DERBitString(byte[] bArr, int i) {
|
|
super(bArr, i);
|
|
}
|
|
|
|
public DERBitString(byte[] bArr) {
|
|
this(bArr, 0);
|
|
}
|
|
|
|
public DERBitString(ASN1Encodable aSN1Encodable) throws IOException {
|
|
super(aSN1Encodable.toASN1Primitive().getEncoded(ASN1Encoding.DER), 0);
|
|
}
|
|
|
|
public DERBitString(int i) {
|
|
super(getBytes(i), getPadBits(i));
|
|
}
|
|
|
|
protected DERBitString(byte b, int i) {
|
|
this(toByteArray(b), i);
|
|
}
|
|
}
|