what-the-bank/sources/org/bouncycastle/asn1/x9/DHDomainParameters.java

136 lines
4.9 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.asn1.x9;
import java.math.BigInteger;
import java.util.Enumeration;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.DERSequence;
/* loaded from: classes6.dex */
public class DHDomainParameters extends ASN1Object {
private ASN1Integer g;
private ASN1Integer j;
private ASN1Integer p;
private ASN1Integer q;
private DHValidationParms validationParms;
@Override // org.bouncycastle.asn1.ASN1Object, org.bouncycastle.asn1.ASN1Encodable
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector aSN1EncodableVector = new ASN1EncodableVector();
aSN1EncodableVector.add(this.p);
aSN1EncodableVector.add(this.g);
aSN1EncodableVector.add(this.q);
ASN1Integer aSN1Integer = this.j;
if (aSN1Integer != null) {
aSN1EncodableVector.add(aSN1Integer);
}
DHValidationParms dHValidationParms = this.validationParms;
if (dHValidationParms != null) {
aSN1EncodableVector.add(dHValidationParms);
}
return new DERSequence(aSN1EncodableVector);
}
public DHValidationParms getValidationParms() {
return this.validationParms;
}
public ASN1Integer getQ() {
return this.q;
}
public ASN1Integer getP() {
return this.p;
}
public ASN1Integer getJ() {
return this.j;
}
public ASN1Integer getG() {
return this.g;
}
private static ASN1Encodable getNext(Enumeration enumeration) {
if (enumeration.hasMoreElements()) {
return (ASN1Encodable) enumeration.nextElement();
}
return null;
}
public static DHDomainParameters getInstance(ASN1TaggedObject aSN1TaggedObject, boolean z) {
return getInstance(ASN1Sequence.getInstance(aSN1TaggedObject, z));
}
public static DHDomainParameters getInstance(Object obj) {
if (obj == null || (obj instanceof DHDomainParameters)) {
return (DHDomainParameters) obj;
}
if (obj instanceof ASN1Sequence) {
return new DHDomainParameters((ASN1Sequence) obj);
}
StringBuilder sb = new StringBuilder("Invalid DHDomainParameters: ");
sb.append(obj.getClass().getName());
throw new IllegalArgumentException(sb.toString());
}
private DHDomainParameters(ASN1Sequence aSN1Sequence) {
if (aSN1Sequence.size() < 3 || aSN1Sequence.size() > 5) {
StringBuilder sb = new StringBuilder("Bad sequence size: ");
sb.append(aSN1Sequence.size());
throw new IllegalArgumentException(sb.toString());
}
Enumeration objects = aSN1Sequence.getObjects();
this.p = ASN1Integer.getInstance(objects.nextElement());
this.g = ASN1Integer.getInstance(objects.nextElement());
this.q = ASN1Integer.getInstance(objects.nextElement());
ASN1Encodable next = getNext(objects);
if (next != null && (next instanceof ASN1Integer)) {
this.j = ASN1Integer.getInstance(next);
next = getNext(objects);
}
if (next != null) {
this.validationParms = DHValidationParms.getInstance(next.toASN1Primitive());
}
}
public DHDomainParameters(ASN1Integer aSN1Integer, ASN1Integer aSN1Integer2, ASN1Integer aSN1Integer3, ASN1Integer aSN1Integer4, DHValidationParms dHValidationParms) {
if (aSN1Integer == null) {
throw new IllegalArgumentException("'p' cannot be null");
}
if (aSN1Integer2 == null) {
throw new IllegalArgumentException("'g' cannot be null");
}
if (aSN1Integer3 == null) {
throw new IllegalArgumentException("'q' cannot be null");
}
this.p = aSN1Integer;
this.g = aSN1Integer2;
this.q = aSN1Integer3;
this.j = aSN1Integer4;
this.validationParms = dHValidationParms;
}
public DHDomainParameters(BigInteger bigInteger, BigInteger bigInteger2, BigInteger bigInteger3, BigInteger bigInteger4, DHValidationParms dHValidationParms) {
if (bigInteger == null) {
throw new IllegalArgumentException("'p' cannot be null");
}
if (bigInteger2 == null) {
throw new IllegalArgumentException("'g' cannot be null");
}
if (bigInteger3 == null) {
throw new IllegalArgumentException("'q' cannot be null");
}
this.p = new ASN1Integer(bigInteger);
this.g = new ASN1Integer(bigInteger2);
this.q = new ASN1Integer(bigInteger3);
this.j = new ASN1Integer(bigInteger4);
this.validationParms = dHValidationParms;
}
}