107 lines
3.6 KiB
Java
107 lines
3.6 KiB
Java
package org.bouncycastle.asn1;
|
|
|
|
import java.io.IOException;
|
|
import org.bouncycastle.util.Arrays;
|
|
import org.bouncycastle.util.Strings;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class DERNumericString extends ASN1Primitive implements ASN1String {
|
|
private final byte[] string;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
|
public boolean isConstructed() {
|
|
return false;
|
|
}
|
|
|
|
public String toString() {
|
|
return getString();
|
|
}
|
|
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive, org.bouncycastle.asn1.ASN1Object
|
|
public int hashCode() {
|
|
return Arrays.hashCode(this.string);
|
|
}
|
|
|
|
@Override // org.bouncycastle.asn1.ASN1String
|
|
public String getString() {
|
|
return Strings.fromByteArray(this.string);
|
|
}
|
|
|
|
public byte[] getOctets() {
|
|
return Arrays.clone(this.string);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
|
public int encodedLength() {
|
|
return StreamUtil.calculateBodyLength(this.string.length) + 1 + this.string.length;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
|
public void encode(ASN1OutputStream aSN1OutputStream) throws IOException {
|
|
aSN1OutputStream.writeEncoded(18, this.string);
|
|
}
|
|
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
|
boolean asn1Equals(ASN1Primitive aSN1Primitive) {
|
|
if (aSN1Primitive instanceof DERNumericString) {
|
|
return Arrays.areEqual(this.string, ((DERNumericString) aSN1Primitive).string);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static boolean isNumericString(String str) {
|
|
for (int length = str.length() - 1; length >= 0; length--) {
|
|
char charAt = str.charAt(length);
|
|
if (charAt > 127) {
|
|
return false;
|
|
}
|
|
if (('0' > charAt || charAt > '9') && charAt != ' ') {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static DERNumericString getInstance(ASN1TaggedObject aSN1TaggedObject, boolean z) {
|
|
ASN1Primitive object = aSN1TaggedObject.getObject();
|
|
return (z || (object instanceof DERNumericString)) ? getInstance(object) : new DERNumericString(ASN1OctetString.getInstance(object).getOctets());
|
|
}
|
|
|
|
public static DERNumericString getInstance(Object obj) {
|
|
if (obj == null || (obj instanceof DERNumericString)) {
|
|
return (DERNumericString) obj;
|
|
}
|
|
if (!(obj instanceof byte[])) {
|
|
StringBuilder sb = new StringBuilder("illegal object in getInstance: ");
|
|
sb.append(obj.getClass().getName());
|
|
throw new IllegalArgumentException(sb.toString());
|
|
}
|
|
try {
|
|
return (DERNumericString) fromByteArray((byte[]) obj);
|
|
} catch (Exception e) {
|
|
StringBuilder sb2 = new StringBuilder("encoding error in getInstance: ");
|
|
sb2.append(e.toString());
|
|
throw new IllegalArgumentException(sb2.toString());
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public DERNumericString(byte[] bArr) {
|
|
this.string = bArr;
|
|
}
|
|
|
|
public DERNumericString(String str, boolean z) {
|
|
if (z && !isNumericString(str)) {
|
|
throw new IllegalArgumentException("string contains illegal characters");
|
|
}
|
|
this.string = Strings.toByteArray(str);
|
|
}
|
|
|
|
public DERNumericString(String str) {
|
|
this(str, false);
|
|
}
|
|
}
|