287 lines
9.3 KiB
Java
287 lines
9.3 KiB
Java
package org.bouncycastle.util;
|
|
|
|
import com.google.common.base.Ascii;
|
|
import com.google.common.primitives.UnsignedBytes;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.OutputStream;
|
|
import java.security.AccessController;
|
|
import java.security.PrivilegedAction;
|
|
import java.util.ArrayList;
|
|
import java.util.Vector;
|
|
import net.sf.scuba.smartcards.ISO7816;
|
|
import org.jmrtd.PassportService;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public final class Strings {
|
|
private static String LINE_SEPARATOR;
|
|
|
|
public static String toUpperCase(String str) {
|
|
char[] charArray = str.toCharArray();
|
|
boolean z = false;
|
|
for (int i = 0; i != charArray.length; i++) {
|
|
char c = charArray[i];
|
|
if ('a' <= c && 'z' >= c) {
|
|
charArray[i] = (char) (c - ' ');
|
|
z = true;
|
|
}
|
|
}
|
|
return z ? new String(charArray) : str;
|
|
}
|
|
|
|
public static byte[] toUTF8ByteArray(char[] cArr) {
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
try {
|
|
toUTF8ByteArray(cArr, byteArrayOutputStream);
|
|
return byteArrayOutputStream.toByteArray();
|
|
} catch (IOException unused) {
|
|
throw new IllegalStateException("cannot encode string to byte array!");
|
|
}
|
|
}
|
|
|
|
public static byte[] toUTF8ByteArray(String str) {
|
|
return toUTF8ByteArray(str.toCharArray());
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static void toUTF8ByteArray(char[] cArr, OutputStream outputStream) throws IOException {
|
|
int i;
|
|
int i2;
|
|
int i3;
|
|
int i4;
|
|
int i5 = 0;
|
|
while (i5 < cArr.length) {
|
|
char c = cArr[i5];
|
|
if (c >= 128) {
|
|
if (c < 2048) {
|
|
i3 = (c >> 6) | 192;
|
|
i4 = c;
|
|
} else {
|
|
if (c < 55296 || c > 57343) {
|
|
i = (c >> 12) | PassportService.DEFAULT_MAX_BLOCKSIZE;
|
|
i2 = c;
|
|
} else {
|
|
i5++;
|
|
if (i5 >= cArr.length) {
|
|
throw new IllegalStateException("invalid UTF-16 codepoint");
|
|
}
|
|
char c2 = cArr[i5];
|
|
if (c > 56319) {
|
|
throw new IllegalStateException("invalid UTF-16 codepoint");
|
|
}
|
|
int i6 = (((c & 1023) << 10) | (c2 & 1023)) + 65536;
|
|
outputStream.write((i6 >> 18) | 240);
|
|
i = ((i6 >> 12) & 63) | 128;
|
|
i2 = i6;
|
|
}
|
|
outputStream.write(i);
|
|
i3 = ((i2 >> 6) & 63) | 128;
|
|
i4 = i2;
|
|
}
|
|
outputStream.write(i3);
|
|
c = (i4 & 63) | 128;
|
|
}
|
|
outputStream.write(c);
|
|
i5++;
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes6.dex */
|
|
static class StringListImpl extends ArrayList<String> implements StringList {
|
|
@Override // org.bouncycastle.util.StringList
|
|
public String[] toStringArray(int i, int i2) {
|
|
String[] strArr = new String[i2 - i];
|
|
for (int i3 = i; i3 != size() && i3 != i2; i3++) {
|
|
strArr[i3 - i] = get(i3);
|
|
}
|
|
return strArr;
|
|
}
|
|
|
|
@Override // org.bouncycastle.util.StringList
|
|
public String[] toStringArray() {
|
|
int size = size();
|
|
String[] strArr = new String[size];
|
|
for (int i = 0; i != size; i++) {
|
|
strArr[i] = get(i);
|
|
}
|
|
return strArr;
|
|
}
|
|
|
|
@Override // java.util.ArrayList, java.util.AbstractList, java.util.List
|
|
public String set(int i, String str) {
|
|
return (String) super.set(i, (int) str);
|
|
}
|
|
|
|
@Override // java.util.ArrayList, java.util.AbstractList, java.util.List, org.bouncycastle.util.StringList
|
|
public /* bridge */ /* synthetic */ String get(int i) {
|
|
return (String) super.get(i);
|
|
}
|
|
|
|
@Override // java.util.ArrayList, java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.util.List
|
|
public boolean add(String str) {
|
|
return super.add((StringListImpl) str);
|
|
}
|
|
|
|
@Override // java.util.ArrayList, java.util.AbstractList, java.util.List
|
|
public void add(int i, String str) {
|
|
super.add(i, (int) str);
|
|
}
|
|
|
|
private StringListImpl() {
|
|
}
|
|
}
|
|
|
|
public static String toLowerCase(String str) {
|
|
char[] charArray = str.toCharArray();
|
|
boolean z = false;
|
|
for (int i = 0; i != charArray.length; i++) {
|
|
char c = charArray[i];
|
|
if ('A' <= c && 'Z' >= c) {
|
|
charArray[i] = (char) (c + ' ');
|
|
z = true;
|
|
}
|
|
}
|
|
return z ? new String(charArray) : str;
|
|
}
|
|
|
|
public static byte[] toByteArray(char[] cArr) {
|
|
int length = cArr.length;
|
|
byte[] bArr = new byte[length];
|
|
for (int i = 0; i != length; i++) {
|
|
bArr[i] = (byte) cArr[i];
|
|
}
|
|
return bArr;
|
|
}
|
|
|
|
public static byte[] toByteArray(String str) {
|
|
int length = str.length();
|
|
byte[] bArr = new byte[length];
|
|
for (int i = 0; i != length; i++) {
|
|
bArr[i] = (byte) str.charAt(i);
|
|
}
|
|
return bArr;
|
|
}
|
|
|
|
public static int toByteArray(String str, byte[] bArr, int i) {
|
|
int length = str.length();
|
|
for (int i2 = 0; i2 < length; i2++) {
|
|
bArr[i + i2] = (byte) str.charAt(i2);
|
|
}
|
|
return length;
|
|
}
|
|
|
|
public static String[] split(String str, char c) {
|
|
int i;
|
|
Vector vector = new Vector();
|
|
boolean z = true;
|
|
while (true) {
|
|
if (!z) {
|
|
break;
|
|
}
|
|
int indexOf = str.indexOf(c);
|
|
if (indexOf > 0) {
|
|
vector.addElement(str.substring(0, indexOf));
|
|
str = str.substring(indexOf + 1);
|
|
} else {
|
|
vector.addElement(str);
|
|
z = false;
|
|
}
|
|
}
|
|
int size = vector.size();
|
|
String[] strArr = new String[size];
|
|
for (i = 0; i != size; i++) {
|
|
strArr[i] = (String) vector.elementAt(i);
|
|
}
|
|
return strArr;
|
|
}
|
|
|
|
public static StringList newList() {
|
|
return new StringListImpl();
|
|
}
|
|
|
|
public static String lineSeparator() {
|
|
return LINE_SEPARATOR;
|
|
}
|
|
|
|
public static String fromUTF8ByteArray(byte[] bArr) {
|
|
char c;
|
|
int i;
|
|
byte b;
|
|
int i2 = 0;
|
|
int i3 = 0;
|
|
int i4 = 0;
|
|
while (i3 < bArr.length) {
|
|
byte b2 = bArr[i3];
|
|
if ((b2 & 240) == 240) {
|
|
i4 += 2;
|
|
i3 += 4;
|
|
} else {
|
|
i3 = (b2 & ISO7816.INS_CREATE_FILE) == 224 ? i3 + 3 : (b2 & ISO7816.INS_GET_RESPONSE) == 192 ? i3 + 2 : i3 + 1;
|
|
i4++;
|
|
}
|
|
}
|
|
char[] cArr = new char[i4];
|
|
int i5 = 0;
|
|
while (i2 < bArr.length) {
|
|
byte b3 = bArr[i2];
|
|
if ((b3 & 240) == 240) {
|
|
int i6 = (((((b3 & 3) << 18) | ((bArr[i2 + 1] & 63) << 12)) | ((bArr[i2 + 2] & 63) << 6)) | (bArr[i2 + 3] & 63)) - 65536;
|
|
char c2 = (char) ((i6 >> 10) | 55296);
|
|
c = (char) ((i6 & 1023) | 56320);
|
|
cArr[i5] = c2;
|
|
i2 += 4;
|
|
i5++;
|
|
} else if ((b3 & ISO7816.INS_CREATE_FILE) == 224) {
|
|
c = (char) (((b3 & 15) << 12) | ((bArr[i2 + 1] & 63) << 6) | (bArr[i2 + 2] & 63));
|
|
i2 += 3;
|
|
} else {
|
|
if ((b3 & ISO7816.INS_WRITE_BINARY) == 208) {
|
|
i = (b3 & Ascii.US) << 6;
|
|
b = bArr[i2 + 1];
|
|
} else if ((b3 & ISO7816.INS_GET_RESPONSE) == 192) {
|
|
i = (b3 & Ascii.US) << 6;
|
|
b = bArr[i2 + 1];
|
|
} else {
|
|
c = (char) (b3 & UnsignedBytes.MAX_VALUE);
|
|
i2++;
|
|
}
|
|
c = (char) (i | (b & 63));
|
|
i2 += 2;
|
|
}
|
|
cArr[i5] = c;
|
|
i5++;
|
|
}
|
|
return new String(cArr);
|
|
}
|
|
|
|
public static String fromByteArray(byte[] bArr) {
|
|
return new String(asCharArray(bArr));
|
|
}
|
|
|
|
public static char[] asCharArray(byte[] bArr) {
|
|
int length = bArr.length;
|
|
char[] cArr = new char[length];
|
|
for (int i = 0; i != length; i++) {
|
|
cArr[i] = (char) (bArr[i] & UnsignedBytes.MAX_VALUE);
|
|
}
|
|
return cArr;
|
|
}
|
|
|
|
static {
|
|
try {
|
|
try {
|
|
LINE_SEPARATOR = (String) AccessController.doPrivileged(new PrivilegedAction<String>() { // from class: org.bouncycastle.util.Strings.1
|
|
@Override // java.security.PrivilegedAction
|
|
public final String run() {
|
|
return System.getProperty("line.separator");
|
|
}
|
|
});
|
|
} catch (Exception unused) {
|
|
LINE_SEPARATOR = String.format("%n", new Object[0]);
|
|
}
|
|
} catch (Exception unused2) {
|
|
LINE_SEPARATOR = "\n";
|
|
}
|
|
}
|
|
}
|