106 lines
4.4 KiB
Java
106 lines
4.4 KiB
Java
package com.huawei.hms.support.log.common;
|
|
|
|
import com.google.common.base.Ascii;
|
|
import com.google.common.primitives.UnsignedBytes;
|
|
import net.sf.scuba.smartcards.ISO7816;
|
|
import org.bouncycastle.pqc.math.linearalgebra.Matrix;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class Base64 {
|
|
private static final char[] a = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', Matrix.MATRIX_TYPE_RANDOM_LT, 'M', 'N', 'O', 'P', 'Q', Matrix.MATRIX_TYPE_RANDOM_REGULAR, 'S', 'T', Matrix.MATRIX_TYPE_RANDOM_UT, 'V', 'W', 'X', 'Y', Matrix.MATRIX_TYPE_ZERO, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '='};
|
|
private static final byte[] b = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, ISO7816.INS_DECREASE_STAMPED, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, Ascii.DC2, 19, Ascii.DC4, Ascii.NAK, Ascii.SYN, Ascii.ETB, Ascii.CAN, Ascii.EM, -1, -1, -1, -1, -1, -1, Ascii.SUB, Ascii.ESC, 28, 29, 30, Ascii.US, 32, 33, ISO7816.INS_MSE, 35, ISO7816.INS_CHANGE_CHV, 37, 38, 39, 40, 41, ISO7816.INS_PSO, 43, ISO7816.INS_UNBLOCK_CHV, 45, 46, 47, ISO7816.INS_DECREASE, 49, ISO7816.INS_INCREASE, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
|
|
|
|
private Base64() {
|
|
}
|
|
|
|
private static int a(String str) {
|
|
int length = str.length();
|
|
for (int i = 0; i < str.length(); i++) {
|
|
char charAt = str.charAt(i);
|
|
if (charAt > 255 || b[charAt] < 0) {
|
|
length--;
|
|
}
|
|
}
|
|
return length;
|
|
}
|
|
|
|
public static String encode(byte[] bArr) {
|
|
return bArr == null ? "" : encode(bArr, bArr.length);
|
|
}
|
|
|
|
public static byte[] decode(String str) {
|
|
if (str == null) {
|
|
return new byte[0];
|
|
}
|
|
int a2 = a(str);
|
|
int i = (a2 / 4) * 3;
|
|
int i2 = a2 % 4;
|
|
if (i2 == 3) {
|
|
i += 2;
|
|
}
|
|
if (i2 == 2) {
|
|
i++;
|
|
}
|
|
byte[] bArr = new byte[i];
|
|
int i3 = 0;
|
|
int i4 = 0;
|
|
int i5 = 0;
|
|
for (int i6 = 0; i6 < str.length(); i6++) {
|
|
char charAt = str.charAt(i6);
|
|
byte b2 = charAt > 255 ? (byte) -1 : b[charAt];
|
|
if (b2 >= 0) {
|
|
int i7 = i5 + 6;
|
|
i4 = (i4 << 6) | b2;
|
|
if (i7 >= 8) {
|
|
i5 -= 2;
|
|
bArr[i3] = (byte) ((i4 >> i5) & 255);
|
|
i3++;
|
|
} else {
|
|
i5 = i7;
|
|
}
|
|
}
|
|
}
|
|
return i3 != i ? new byte[0] : bArr;
|
|
}
|
|
|
|
public static String encode(byte[] bArr, int i) {
|
|
boolean z;
|
|
if (bArr == null) {
|
|
return "";
|
|
}
|
|
char[] cArr = new char[((i + 2) / 3) << 2];
|
|
int i2 = 0;
|
|
int i3 = 0;
|
|
while (i2 < i) {
|
|
int i4 = (bArr[i2] & UnsignedBytes.MAX_VALUE) << 8;
|
|
int i5 = i2 + 1;
|
|
boolean z2 = true;
|
|
if (i5 < i) {
|
|
i4 |= bArr[i5] & UnsignedBytes.MAX_VALUE;
|
|
z = true;
|
|
} else {
|
|
z = false;
|
|
}
|
|
int i6 = i4 << 8;
|
|
int i7 = i2 + 2;
|
|
if (i7 < i) {
|
|
i6 |= bArr[i7] & UnsignedBytes.MAX_VALUE;
|
|
} else {
|
|
z2 = false;
|
|
}
|
|
char[] cArr2 = a;
|
|
int i8 = 64;
|
|
cArr[i3 + 3] = cArr2[z2 ? i6 & 63 : 64];
|
|
if (z) {
|
|
i8 = (i6 >> 6) & 63;
|
|
}
|
|
cArr[i3 + 2] = cArr2[i8];
|
|
cArr[i3 + 1] = cArr2[(i6 >> 12) & 63];
|
|
cArr[i3] = cArr2[(i6 >> 18) & 63];
|
|
i2 += 3;
|
|
i3 += 4;
|
|
}
|
|
return new String(cArr);
|
|
}
|
|
}
|