84 lines
3.2 KiB
Java
84 lines
3.2 KiB
Java
package org.bouncycastle.crypto.tls;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.util.Vector;
|
|
import org.bouncycastle.asn1.ASN1Encoding;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class Certificate {
|
|
public static final Certificate EMPTY_CHAIN = new Certificate(new org.bouncycastle.asn1.x509.Certificate[0]);
|
|
protected org.bouncycastle.asn1.x509.Certificate[] certificateList;
|
|
|
|
public boolean isEmpty() {
|
|
return this.certificateList.length == 0;
|
|
}
|
|
|
|
public int getLength() {
|
|
return this.certificateList.length;
|
|
}
|
|
|
|
public org.bouncycastle.asn1.x509.Certificate[] getCertificateList() {
|
|
return cloneCertificateList();
|
|
}
|
|
|
|
public org.bouncycastle.asn1.x509.Certificate getCertificateAt(int i) {
|
|
return this.certificateList[i];
|
|
}
|
|
|
|
public void encode(OutputStream outputStream) throws IOException {
|
|
Vector vector = new Vector(this.certificateList.length);
|
|
int i = 0;
|
|
int i2 = 0;
|
|
while (true) {
|
|
org.bouncycastle.asn1.x509.Certificate[] certificateArr = this.certificateList;
|
|
if (i >= certificateArr.length) {
|
|
break;
|
|
}
|
|
byte[] encoded = certificateArr[i].getEncoded(ASN1Encoding.DER);
|
|
vector.addElement(encoded);
|
|
i2 += encoded.length + 3;
|
|
i++;
|
|
}
|
|
TlsUtils.checkUint24(i2);
|
|
TlsUtils.writeUint24(i2, outputStream);
|
|
for (int i3 = 0; i3 < vector.size(); i3++) {
|
|
TlsUtils.writeOpaque24((byte[]) vector.elementAt(i3), outputStream);
|
|
}
|
|
}
|
|
|
|
protected org.bouncycastle.asn1.x509.Certificate[] cloneCertificateList() {
|
|
org.bouncycastle.asn1.x509.Certificate[] certificateArr = this.certificateList;
|
|
int length = certificateArr.length;
|
|
org.bouncycastle.asn1.x509.Certificate[] certificateArr2 = new org.bouncycastle.asn1.x509.Certificate[length];
|
|
System.arraycopy(certificateArr, 0, certificateArr2, 0, length);
|
|
return certificateArr2;
|
|
}
|
|
|
|
public static Certificate parse(InputStream inputStream) throws IOException {
|
|
int readUint24 = TlsUtils.readUint24(inputStream);
|
|
if (readUint24 == 0) {
|
|
return EMPTY_CHAIN;
|
|
}
|
|
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(TlsUtils.readFully(readUint24, inputStream));
|
|
Vector vector = new Vector();
|
|
while (byteArrayInputStream.available() > 0) {
|
|
vector.addElement(org.bouncycastle.asn1.x509.Certificate.getInstance(TlsUtils.readDERObject(TlsUtils.readOpaque24(byteArrayInputStream))));
|
|
}
|
|
org.bouncycastle.asn1.x509.Certificate[] certificateArr = new org.bouncycastle.asn1.x509.Certificate[vector.size()];
|
|
for (int i = 0; i < vector.size(); i++) {
|
|
certificateArr[i] = (org.bouncycastle.asn1.x509.Certificate) vector.elementAt(i);
|
|
}
|
|
return new Certificate(certificateArr);
|
|
}
|
|
|
|
public Certificate(org.bouncycastle.asn1.x509.Certificate[] certificateArr) {
|
|
if (certificateArr == null) {
|
|
throw new IllegalArgumentException("'certificateList' cannot be null");
|
|
}
|
|
this.certificateList = certificateArr;
|
|
}
|
|
}
|