what-the-bank/sources/org/bouncycastle/asn1/eac/CVCertificateRequest.java

115 lines
4.7 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.asn1.eac;
import java.io.IOException;
import java.util.Enumeration;
import org.bouncycastle.asn1.ASN1ApplicationSpecific;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1ParsingException;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DERApplicationSpecific;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.util.Arrays;
/* loaded from: classes6.dex */
public class CVCertificateRequest extends ASN1Object {
private static final int bodyValid = 1;
private static final int signValid = 2;
private CertificateBody certificateBody;
private byte[] innerSignature = null;
private byte[] outerSignature;
@Override // org.bouncycastle.asn1.ASN1Object, org.bouncycastle.asn1.ASN1Encodable
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector aSN1EncodableVector = new ASN1EncodableVector();
aSN1EncodableVector.add(this.certificateBody);
try {
aSN1EncodableVector.add(new DERApplicationSpecific(false, 55, (ASN1Encodable) new DEROctetString(this.innerSignature)));
return new DERApplicationSpecific(33, aSN1EncodableVector);
} catch (IOException unused) {
throw new IllegalStateException("unable to convert signature!");
}
}
public boolean hasOuterSignature() {
return this.outerSignature != null;
}
public PublicKeyDataObject getPublicKey() {
return this.certificateBody.getPublicKey();
}
public byte[] getOuterSignature() {
return Arrays.clone(this.outerSignature);
}
public byte[] getInnerSignature() {
return Arrays.clone(this.innerSignature);
}
public CertificateBody getCertificateBody() {
return this.certificateBody;
}
private void initCertBody(ASN1ApplicationSpecific aSN1ApplicationSpecific) throws IOException {
if (aSN1ApplicationSpecific.getApplicationTag() != 33) {
StringBuilder sb = new StringBuilder("not a CARDHOLDER_CERTIFICATE in request:");
sb.append(aSN1ApplicationSpecific.getApplicationTag());
throw new IOException(sb.toString());
}
Enumeration objects = ASN1Sequence.getInstance(aSN1ApplicationSpecific.getObject(16)).getObjects();
int i = 0;
while (objects.hasMoreElements()) {
ASN1ApplicationSpecific aSN1ApplicationSpecific2 = ASN1ApplicationSpecific.getInstance(objects.nextElement());
int applicationTag = aSN1ApplicationSpecific2.getApplicationTag();
if (applicationTag == 55) {
this.innerSignature = aSN1ApplicationSpecific2.getContents();
i |= 2;
} else {
if (applicationTag != 78) {
StringBuilder sb2 = new StringBuilder("Invalid tag, not an CV Certificate Request element:");
sb2.append(aSN1ApplicationSpecific2.getApplicationTag());
throw new IOException(sb2.toString());
}
this.certificateBody = CertificateBody.getInstance(aSN1ApplicationSpecific2);
i |= 1;
}
}
if ((i & 3) != 0) {
return;
}
StringBuilder sb3 = new StringBuilder("Invalid CARDHOLDER_CERTIFICATE in request:");
sb3.append(aSN1ApplicationSpecific.getApplicationTag());
throw new IOException(sb3.toString());
}
public static CVCertificateRequest getInstance(Object obj) {
if (obj instanceof CVCertificateRequest) {
return (CVCertificateRequest) obj;
}
if (obj == null) {
return null;
}
try {
return new CVCertificateRequest(ASN1ApplicationSpecific.getInstance(obj));
} catch (IOException e) {
StringBuilder sb = new StringBuilder("unable to parse data: ");
sb.append(e.getMessage());
throw new ASN1ParsingException(sb.toString(), e);
}
}
private CVCertificateRequest(ASN1ApplicationSpecific aSN1ApplicationSpecific) throws IOException {
this.outerSignature = null;
if (aSN1ApplicationSpecific.getApplicationTag() != 103) {
initCertBody(aSN1ApplicationSpecific);
return;
}
ASN1Sequence aSN1Sequence = ASN1Sequence.getInstance(aSN1ApplicationSpecific.getObject(16));
initCertBody(ASN1ApplicationSpecific.getInstance(aSN1Sequence.getObjectAt(0)));
this.outerSignature = ASN1ApplicationSpecific.getInstance(aSN1Sequence.getObjectAt(aSN1Sequence.size() - 1)).getContents();
}
}