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

216 lines
7.8 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.asn1;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.Iterable;
/* loaded from: classes6.dex */
public abstract class ASN1Sequence extends ASN1Primitive implements Iterable<ASN1Encodable> {
protected Vector seq;
/* JADX INFO: Access modifiers changed from: package-private */
@Override // org.bouncycastle.asn1.ASN1Primitive
public abstract void encode(ASN1OutputStream aSN1OutputStream) throws IOException;
/* JADX INFO: Access modifiers changed from: package-private */
@Override // org.bouncycastle.asn1.ASN1Primitive
public boolean isConstructed() {
return true;
}
public String toString() {
return this.seq.toString();
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // org.bouncycastle.asn1.ASN1Primitive
public ASN1Primitive toDLObject() {
DLSequence dLSequence = new DLSequence();
dLSequence.seq = this.seq;
return dLSequence;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // org.bouncycastle.asn1.ASN1Primitive
public ASN1Primitive toDERObject() {
DERSequence dERSequence = new DERSequence();
dERSequence.seq = this.seq;
return dERSequence;
}
public ASN1Encodable[] toArray() {
ASN1Encodable[] aSN1EncodableArr = new ASN1Encodable[size()];
for (int i = 0; i != size(); i++) {
aSN1EncodableArr[i] = getObjectAt(i);
}
return aSN1EncodableArr;
}
public int size() {
return this.seq.size();
}
public ASN1SequenceParser parser() {
return new ASN1SequenceParser(this, this) { // from class: org.bouncycastle.asn1.ASN1Sequence.1
private int index;
private final int max;
final ASN1Sequence this$0;
final ASN1Sequence val$outer;
@Override // org.bouncycastle.asn1.ASN1Encodable
public ASN1Primitive toASN1Primitive() {
return this.val$outer;
}
@Override // org.bouncycastle.asn1.ASN1SequenceParser
public ASN1Encodable readObject() throws IOException {
int i = this.index;
if (i == this.max) {
return null;
}
ASN1Sequence aSN1Sequence = this.this$0;
this.index = i + 1;
ASN1Encodable objectAt = aSN1Sequence.getObjectAt(i);
return objectAt instanceof ASN1Sequence ? ((ASN1Sequence) objectAt).parser() : objectAt instanceof ASN1Set ? ((ASN1Set) objectAt).parser() : objectAt;
}
@Override // org.bouncycastle.asn1.InMemoryRepresentable
public ASN1Primitive getLoadedObject() {
return this.val$outer;
}
{
this.this$0 = this;
this.val$outer = this;
this.max = this.size();
}
};
}
@Override // org.bouncycastle.util.Iterable, java.lang.Iterable
public Iterator<ASN1Encodable> iterator() {
return new Arrays.Iterator(toArray());
}
@Override // org.bouncycastle.asn1.ASN1Primitive, org.bouncycastle.asn1.ASN1Object
public int hashCode() {
Enumeration objects = getObjects();
int size = size();
while (objects.hasMoreElements()) {
size = (size * 17) ^ getNext(objects).hashCode();
}
return size;
}
public Enumeration getObjects() {
return this.seq.elements();
}
public ASN1Encodable getObjectAt(int i) {
return (ASN1Encodable) this.seq.elementAt(i);
}
@Override // org.bouncycastle.asn1.ASN1Primitive
boolean asn1Equals(ASN1Primitive aSN1Primitive) {
if (!(aSN1Primitive instanceof ASN1Sequence)) {
return false;
}
ASN1Sequence aSN1Sequence = (ASN1Sequence) aSN1Primitive;
if (size() != aSN1Sequence.size()) {
return false;
}
Enumeration objects = getObjects();
Enumeration objects2 = aSN1Sequence.getObjects();
while (objects.hasMoreElements()) {
ASN1Encodable next = getNext(objects);
ASN1Encodable next2 = getNext(objects2);
ASN1Primitive aSN1Primitive2 = next.toASN1Primitive();
ASN1Primitive aSN1Primitive3 = next2.toASN1Primitive();
if (aSN1Primitive2 != aSN1Primitive3 && !aSN1Primitive2.equals(aSN1Primitive3)) {
return false;
}
}
return true;
}
private ASN1Encodable getNext(Enumeration enumeration) {
return (ASN1Encodable) enumeration.nextElement();
}
public static ASN1Sequence getInstance(ASN1TaggedObject aSN1TaggedObject, boolean z) {
if (z) {
if (aSN1TaggedObject.isExplicit()) {
return getInstance(aSN1TaggedObject.getObject().toASN1Primitive());
}
throw new IllegalArgumentException("object implicit - explicit expected.");
}
if (aSN1TaggedObject.isExplicit()) {
return aSN1TaggedObject instanceof BERTaggedObject ? new BERSequence(aSN1TaggedObject.getObject()) : new DLSequence(aSN1TaggedObject.getObject());
}
if (aSN1TaggedObject.getObject() instanceof ASN1Sequence) {
return (ASN1Sequence) aSN1TaggedObject.getObject();
}
StringBuilder sb = new StringBuilder("unknown object in getInstance: ");
sb.append(aSN1TaggedObject.getClass().getName());
throw new IllegalArgumentException(sb.toString());
}
public static ASN1Sequence getInstance(Object obj) {
while (obj != null && !(obj instanceof ASN1Sequence)) {
if (!(obj instanceof ASN1SequenceParser)) {
if (obj instanceof byte[]) {
try {
return getInstance(fromByteArray((byte[]) obj));
} catch (IOException e) {
StringBuilder sb = new StringBuilder("failed to construct sequence from byte[]: ");
sb.append(e.getMessage());
throw new IllegalArgumentException(sb.toString());
}
}
if (obj instanceof ASN1Encodable) {
ASN1Primitive aSN1Primitive = ((ASN1Encodable) obj).toASN1Primitive();
if (aSN1Primitive instanceof ASN1Sequence) {
return (ASN1Sequence) aSN1Primitive;
}
}
StringBuilder sb2 = new StringBuilder("unknown object in getInstance: ");
sb2.append(obj.getClass().getName());
throw new IllegalArgumentException(sb2.toString());
}
obj = ((ASN1SequenceParser) obj).toASN1Primitive();
}
return (ASN1Sequence) obj;
}
/* JADX INFO: Access modifiers changed from: protected */
public ASN1Sequence(ASN1Encodable[] aSN1EncodableArr) {
this.seq = new Vector();
for (int i = 0; i != aSN1EncodableArr.length; i++) {
this.seq.addElement(aSN1EncodableArr[i]);
}
}
/* JADX INFO: Access modifiers changed from: protected */
public ASN1Sequence(ASN1EncodableVector aSN1EncodableVector) {
this.seq = new Vector();
for (int i = 0; i != aSN1EncodableVector.size(); i++) {
this.seq.addElement(aSN1EncodableVector.get(i));
}
}
/* JADX INFO: Access modifiers changed from: protected */
public ASN1Sequence(ASN1Encodable aSN1Encodable) {
Vector vector = new Vector();
this.seq = vector;
vector.addElement(aSN1Encodable);
}
/* JADX INFO: Access modifiers changed from: protected */
public ASN1Sequence() {
this.seq = new Vector();
}
}