what-the-bank/sources/org/bouncycastle/asn1/DLBitString.java

93 lines
3.1 KiB
Java

package org.bouncycastle.asn1;
import java.io.IOException;
/* loaded from: classes6.dex */
public class DLBitString 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[] bArr = this.data;
int length = bArr.length;
byte[] bArr2 = new byte[length + 1];
bArr2[0] = (byte) getPadBits();
System.arraycopy(bArr, 0, bArr2, 1, length);
aSN1OutputStream.writeEncoded(3, bArr2);
}
private static byte[] toByteArray(byte b) {
return new byte[]{b};
}
public static ASN1BitString getInstance(ASN1TaggedObject aSN1TaggedObject, boolean z) {
ASN1Primitive object = aSN1TaggedObject.getObject();
return (z || (object instanceof DLBitString)) ? getInstance(object) : fromOctetString(((ASN1OctetString) object).getOctets());
}
public static ASN1BitString getInstance(Object obj) {
if (obj == null || (obj instanceof DLBitString)) {
return (DLBitString) obj;
}
if (obj instanceof DERBitString) {
return (DERBitString) obj;
}
if (!(obj instanceof byte[])) {
StringBuilder sb = new StringBuilder("illegal object in getInstance: ");
sb.append(obj.getClass().getName());
throw new IllegalArgumentException(sb.toString());
}
try {
return (ASN1BitString) fromByteArray((byte[]) obj);
} catch (Exception e) {
StringBuilder sb2 = new StringBuilder("encoding error in getInstance: ");
sb2.append(e.toString());
throw new IllegalArgumentException(sb2.toString());
}
}
static DLBitString 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 DLBitString(bArr2, b);
}
public DLBitString(byte[] bArr, int i) {
super(bArr, i);
}
public DLBitString(byte[] bArr) {
this(bArr, 0);
}
public DLBitString(ASN1Encodable aSN1Encodable) throws IOException {
super(aSN1Encodable.toASN1Primitive().getEncoded(ASN1Encoding.DER), 0);
}
public DLBitString(int i) {
super(getBytes(i), getPadBits(i));
}
protected DLBitString(byte b, int i) {
this(toByteArray(b), i);
}
}