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

125 lines
4.4 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.asn1;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;
/* loaded from: classes6.dex */
public class BEROctetString extends ASN1OctetString {
private static final int MAX_LENGTH = 1000;
private ASN1OctetString[] octs;
/* JADX INFO: Access modifiers changed from: package-private */
@Override // org.bouncycastle.asn1.ASN1Primitive
public boolean isConstructed() {
return true;
}
@Override // org.bouncycastle.asn1.ASN1OctetString
public byte[] getOctets() {
return this.string;
}
public Enumeration getObjects() {
return this.octs == null ? generateOcts().elements() : new Enumeration(this) { // from class: org.bouncycastle.asn1.BEROctetString.1
int counter = 0;
final BEROctetString this$0;
@Override // java.util.Enumeration
public Object nextElement() {
ASN1OctetString[] aSN1OctetStringArr = this.this$0.octs;
int i = this.counter;
this.counter = i + 1;
return aSN1OctetStringArr[i];
}
@Override // java.util.Enumeration
public boolean hasMoreElements() {
return this.counter < this.this$0.octs.length;
}
{
this.this$0 = this;
}
};
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // org.bouncycastle.asn1.ASN1Primitive
public int encodedLength() throws IOException {
Enumeration objects = getObjects();
int i = 0;
while (objects.hasMoreElements()) {
i += ((ASN1Encodable) objects.nextElement()).toASN1Primitive().encodedLength();
}
return i + 4;
}
@Override // org.bouncycastle.asn1.ASN1OctetString, org.bouncycastle.asn1.ASN1Primitive
public void encode(ASN1OutputStream aSN1OutputStream) throws IOException {
aSN1OutputStream.write(36);
aSN1OutputStream.write(128);
Enumeration objects = getObjects();
while (objects.hasMoreElements()) {
aSN1OutputStream.writeObject((ASN1Encodable) objects.nextElement());
}
aSN1OutputStream.write(0);
aSN1OutputStream.write(0);
}
private static byte[] toBytes(ASN1OctetString[] aSN1OctetStringArr) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
for (int i = 0; i != aSN1OctetStringArr.length; i++) {
try {
byteArrayOutputStream.write(((DEROctetString) aSN1OctetStringArr[i]).getOctets());
} catch (IOException e) {
StringBuilder sb = new StringBuilder("exception converting octets ");
sb.append(e.toString());
throw new IllegalArgumentException(sb.toString());
} catch (ClassCastException unused) {
StringBuilder sb2 = new StringBuilder();
sb2.append(aSN1OctetStringArr[i].getClass().getName());
sb2.append(" found in input should only contain DEROctetString");
throw new IllegalArgumentException(sb2.toString());
}
}
return byteArrayOutputStream.toByteArray();
}
private Vector generateOcts() {
Vector vector = new Vector();
int i = 0;
while (i < this.string.length) {
int i2 = i + 1000;
int length = (i2 > this.string.length ? this.string.length : i2) - i;
byte[] bArr = new byte[length];
System.arraycopy(this.string, i, bArr, 0, length);
vector.addElement(new DEROctetString(bArr));
i = i2;
}
return vector;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static BEROctetString fromSequence(ASN1Sequence aSN1Sequence) {
ASN1OctetString[] aSN1OctetStringArr = new ASN1OctetString[aSN1Sequence.size()];
Enumeration objects = aSN1Sequence.getObjects();
int i = 0;
while (objects.hasMoreElements()) {
aSN1OctetStringArr[i] = (ASN1OctetString) objects.nextElement();
i++;
}
return new BEROctetString(aSN1OctetStringArr);
}
public BEROctetString(ASN1OctetString[] aSN1OctetStringArr) {
super(toBytes(aSN1OctetStringArr));
this.octs = aSN1OctetStringArr;
}
public BEROctetString(byte[] bArr) {
super(bArr);
}
}