what-the-bank/sources/org/bouncycastle/asn1/x509/RoleSyntax.java

123 lines
4.5 KiB
Java

package org.bouncycastle.asn1.x509;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1String;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERTaggedObject;
/* loaded from: classes6.dex */
public class RoleSyntax extends ASN1Object {
private GeneralNames roleAuthority;
private GeneralName roleName;
public String toString() {
StringBuilder sb = new StringBuilder("Name: ");
sb.append(getRoleNameAsString());
sb.append(" - Auth: ");
StringBuffer stringBuffer = new StringBuffer(sb.toString());
GeneralNames generalNames = this.roleAuthority;
if (generalNames == null || generalNames.getNames().length == 0) {
stringBuffer.append("N/A");
} else {
String[] roleAuthorityAsString = getRoleAuthorityAsString();
stringBuffer.append('[').append(roleAuthorityAsString[0]);
for (int i = 1; i < roleAuthorityAsString.length; i++) {
stringBuffer.append(", ").append(roleAuthorityAsString[i]);
}
stringBuffer.append(']');
}
return stringBuffer.toString();
}
@Override // org.bouncycastle.asn1.ASN1Object, org.bouncycastle.asn1.ASN1Encodable
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector aSN1EncodableVector = new ASN1EncodableVector();
if (this.roleAuthority != null) {
aSN1EncodableVector.add(new DERTaggedObject(false, 0, this.roleAuthority));
}
aSN1EncodableVector.add(new DERTaggedObject(true, 1, this.roleName));
return new DERSequence(aSN1EncodableVector);
}
public String getRoleNameAsString() {
return ((ASN1String) this.roleName.getName()).getString();
}
public GeneralName getRoleName() {
return this.roleName;
}
public String[] getRoleAuthorityAsString() {
GeneralNames generalNames = this.roleAuthority;
if (generalNames == null) {
return new String[0];
}
GeneralName[] names = generalNames.getNames();
String[] strArr = new String[names.length];
for (int i = 0; i < names.length; i++) {
ASN1Encodable name = names[i].getName();
if (name instanceof ASN1String) {
strArr[i] = ((ASN1String) name).getString();
} else {
strArr[i] = name.toString();
}
}
return strArr;
}
public GeneralNames getRoleAuthority() {
return this.roleAuthority;
}
public static RoleSyntax getInstance(Object obj) {
if (obj instanceof RoleSyntax) {
return (RoleSyntax) obj;
}
if (obj != null) {
return new RoleSyntax(ASN1Sequence.getInstance(obj));
}
return null;
}
public RoleSyntax(GeneralNames generalNames, GeneralName generalName) {
if (generalName == null || generalName.getTagNo() != 6 || ((ASN1String) generalName.getName()).getString().equals("")) {
throw new IllegalArgumentException("the role name MUST be non empty and MUST use the URI option of GeneralName");
}
this.roleAuthority = generalNames;
this.roleName = generalName;
}
public RoleSyntax(GeneralName generalName) {
this(null, generalName);
}
private RoleSyntax(ASN1Sequence aSN1Sequence) {
if (aSN1Sequence.size() <= 0 || aSN1Sequence.size() > 2) {
StringBuilder sb = new StringBuilder("Bad sequence size: ");
sb.append(aSN1Sequence.size());
throw new IllegalArgumentException(sb.toString());
}
for (int i = 0; i != aSN1Sequence.size(); i++) {
ASN1TaggedObject aSN1TaggedObject = ASN1TaggedObject.getInstance(aSN1Sequence.getObjectAt(i));
int tagNo = aSN1TaggedObject.getTagNo();
if (tagNo == 0) {
this.roleAuthority = GeneralNames.getInstance(aSN1TaggedObject, false);
} else {
if (tagNo != 1) {
throw new IllegalArgumentException("Unknown tag in RoleSyntax");
}
this.roleName = GeneralName.getInstance(aSN1TaggedObject, true);
}
}
}
public RoleSyntax(String str) {
this(new GeneralName(6, str == null ? "" : str));
}
}