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

91 lines
3.1 KiB
Java
Raw 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 BERConstructedOctetString extends BEROctetString {
private static final int MAX_LENGTH = 1000;
private Vector octs;
@Override // org.bouncycastle.asn1.BEROctetString, org.bouncycastle.asn1.ASN1OctetString
public byte[] getOctets() {
return this.string;
}
@Override // org.bouncycastle.asn1.BEROctetString
public Enumeration getObjects() {
Vector vector = this.octs;
return vector == null ? generateOcts().elements() : vector.elements();
}
private static byte[] toBytes(Vector vector) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
for (int i = 0; i != vector.size(); i++) {
try {
byteArrayOutputStream.write(((DEROctetString) vector.elementAt(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(vector.elementAt(i).getClass().getName());
sb2.append(" found in input should only contain DEROctetString");
throw new IllegalArgumentException(sb2.toString());
}
}
return byteArrayOutputStream.toByteArray();
}
private static byte[] toByteArray(ASN1Primitive aSN1Primitive) {
try {
return aSN1Primitive.getEncoded();
} catch (IOException unused) {
throw new IllegalArgumentException("Unable to encode object");
}
}
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;
}
public static BEROctetString fromSequence(ASN1Sequence aSN1Sequence) {
Vector vector = new Vector();
Enumeration objects = aSN1Sequence.getObjects();
while (objects.hasMoreElements()) {
vector.addElement(objects.nextElement());
}
return new BERConstructedOctetString(vector);
}
public BERConstructedOctetString(byte[] bArr) {
super(bArr);
}
public BERConstructedOctetString(ASN1Primitive aSN1Primitive) {
super(toByteArray(aSN1Primitive));
}
public BERConstructedOctetString(ASN1Encodable aSN1Encodable) {
this(aSN1Encodable.toASN1Primitive());
}
public BERConstructedOctetString(Vector vector) {
super(toBytes(vector));
this.octs = vector;
}
}