261 lines
9.1 KiB
Java
261 lines
9.1 KiB
Java
|
package org.bouncycastle.util.encoders;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.io.OutputStream;
|
||
|
import net.sf.scuba.smartcards.ISO7816;
|
||
|
import net.sf.scuba.smartcards.ISOFileInfo;
|
||
|
import org.jmrtd.lds.CVCAFile;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class Base64Encoder implements Encoder {
|
||
|
protected final byte[] encodingTable = {65, CVCAFile.CAR_TAG, 67, ISO7816.INS_REHABILITATE_CHV, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, ISOFileInfo.FCP_BYTE, 99, ISOFileInfo.FMD_BYTE, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, ISOFileInfo.FCI_BYTE, ISO7816.INS_MANAGE_CHANNEL, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, ISO7816.INS_DECREASE, 49, ISO7816.INS_INCREASE, 51, ISO7816.INS_DECREASE_STAMPED, 53, 54, 55, 56, 57, 43, 47};
|
||
|
protected byte padding = 61;
|
||
|
protected final byte[] decodingTable = new byte[128];
|
||
|
|
||
|
private boolean ignore(char c) {
|
||
|
return c == '\n' || c == '\r' || c == '\t' || c == ' ';
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: protected */
|
||
|
public void initialiseDecodingTable() {
|
||
|
int i = 0;
|
||
|
int i2 = 0;
|
||
|
while (true) {
|
||
|
byte[] bArr = this.decodingTable;
|
||
|
if (i2 >= bArr.length) {
|
||
|
break;
|
||
|
}
|
||
|
bArr[i2] = -1;
|
||
|
i2++;
|
||
|
}
|
||
|
while (true) {
|
||
|
byte[] bArr2 = this.encodingTable;
|
||
|
if (i >= bArr2.length) {
|
||
|
return;
|
||
|
}
|
||
|
this.decodingTable[bArr2[i]] = (byte) i;
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX WARN: Removed duplicated region for block: B:13:0x00a1 */
|
||
|
@Override // org.bouncycastle.util.encoders.Encoder
|
||
|
/*
|
||
|
Code decompiled incorrectly, please refer to instructions dump.
|
||
|
To view partially-correct add '--show-bad-code' argument
|
||
|
*/
|
||
|
public int encode(byte[] r10, int r11, int r12, java.io.OutputStream r13) throws java.io.IOException {
|
||
|
/*
|
||
|
r9 = this;
|
||
|
int r0 = r12 % 3
|
||
|
int r12 = r12 - r0
|
||
|
r1 = r11
|
||
|
L4:
|
||
|
int r2 = r11 + r12
|
||
|
r3 = 4
|
||
|
r4 = 2
|
||
|
if (r1 >= r2) goto L4c
|
||
|
r2 = r10[r1]
|
||
|
r2 = r2 & 255(0xff, float:3.57E-43)
|
||
|
int r5 = r1 + 1
|
||
|
r5 = r10[r5]
|
||
|
r5 = r5 & 255(0xff, float:3.57E-43)
|
||
|
int r6 = r1 + 2
|
||
|
r6 = r10[r6]
|
||
|
byte[] r7 = r9.encodingTable
|
||
|
int r8 = r2 >>> 2
|
||
|
r8 = r8 & 63
|
||
|
r7 = r7[r8]
|
||
|
r13.write(r7)
|
||
|
byte[] r7 = r9.encodingTable
|
||
|
int r2 = r2 << r3
|
||
|
int r3 = r5 >>> 4
|
||
|
r2 = r2 | r3
|
||
|
r2 = r2 & 63
|
||
|
r2 = r7[r2]
|
||
|
r13.write(r2)
|
||
|
byte[] r2 = r9.encodingTable
|
||
|
int r3 = r5 << 2
|
||
|
r4 = r6 & 255(0xff, float:3.57E-43)
|
||
|
int r4 = r4 >>> 6
|
||
|
r3 = r3 | r4
|
||
|
r3 = r3 & 63
|
||
|
r2 = r2[r3]
|
||
|
r13.write(r2)
|
||
|
byte[] r2 = r9.encodingTable
|
||
|
r3 = r6 & 63
|
||
|
r2 = r2[r3]
|
||
|
r13.write(r2)
|
||
|
int r1 = r1 + 3
|
||
|
goto L4
|
||
|
L4c:
|
||
|
r11 = 1
|
||
|
if (r0 == r11) goto L7a
|
||
|
if (r0 != r4) goto L9d
|
||
|
r1 = r10[r2]
|
||
|
r1 = r1 & 255(0xff, float:3.57E-43)
|
||
|
int r2 = r2 + r11
|
||
|
r10 = r10[r2]
|
||
|
r10 = r10 & 255(0xff, float:3.57E-43)
|
||
|
byte[] r11 = r9.encodingTable
|
||
|
int r2 = r1 >>> 2
|
||
|
r2 = r2 & 63
|
||
|
r11 = r11[r2]
|
||
|
r13.write(r11)
|
||
|
byte[] r11 = r9.encodingTable
|
||
|
int r1 = r1 << r3
|
||
|
int r2 = r10 >>> 4
|
||
|
r1 = r1 | r2
|
||
|
r1 = r1 & 63
|
||
|
r11 = r11[r1]
|
||
|
r13.write(r11)
|
||
|
byte[] r11 = r9.encodingTable
|
||
|
int r10 = r10 << r4
|
||
|
r10 = r10 & 63
|
||
|
r10 = r11[r10]
|
||
|
goto L95
|
||
|
L7a:
|
||
|
r10 = r10[r2]
|
||
|
r10 = r10 & 255(0xff, float:3.57E-43)
|
||
|
byte[] r11 = r9.encodingTable
|
||
|
int r1 = r10 >>> 2
|
||
|
r1 = r1 & 63
|
||
|
r11 = r11[r1]
|
||
|
r13.write(r11)
|
||
|
byte[] r11 = r9.encodingTable
|
||
|
int r10 = r10 << r3
|
||
|
r10 = r10 & 63
|
||
|
r10 = r11[r10]
|
||
|
r13.write(r10)
|
||
|
byte r10 = r9.padding
|
||
|
L95:
|
||
|
r13.write(r10)
|
||
|
byte r10 = r9.padding
|
||
|
r13.write(r10)
|
||
|
L9d:
|
||
|
int r12 = r12 / 3
|
||
|
if (r0 != 0) goto La2
|
||
|
r3 = 0
|
||
|
La2:
|
||
|
int r10 = r12 << 2
|
||
|
int r10 = r10 + r3
|
||
|
return r10
|
||
|
*/
|
||
|
throw new UnsupportedOperationException("Method not decompiled: org.bouncycastle.util.encoders.Base64Encoder.encode(byte[], int, int, java.io.OutputStream):int");
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.util.encoders.Encoder
|
||
|
public int decode(byte[] bArr, int i, int i2, OutputStream outputStream) throws IOException {
|
||
|
int i3 = i2 + i;
|
||
|
while (i3 > i && ignore((char) bArr[i3 - 1])) {
|
||
|
i3--;
|
||
|
}
|
||
|
int i4 = i3 - 4;
|
||
|
int nextI = nextI(bArr, i, i4);
|
||
|
int i5 = 0;
|
||
|
while (nextI < i4) {
|
||
|
byte b = this.decodingTable[bArr[nextI]];
|
||
|
int nextI2 = nextI(bArr, nextI + 1, i4);
|
||
|
byte b2 = this.decodingTable[bArr[nextI2]];
|
||
|
int nextI3 = nextI(bArr, nextI2 + 1, i4);
|
||
|
byte b3 = this.decodingTable[bArr[nextI3]];
|
||
|
int nextI4 = nextI(bArr, nextI3 + 1, i4);
|
||
|
byte b4 = this.decodingTable[bArr[nextI4]];
|
||
|
if ((b | b2 | b3 | b4) < 0) {
|
||
|
throw new IOException("invalid characters encountered in base64 data");
|
||
|
}
|
||
|
outputStream.write((b << 2) | (b2 >> 4));
|
||
|
outputStream.write((b2 << 4) | (b3 >> 2));
|
||
|
outputStream.write((b3 << 6) | b4);
|
||
|
i5 += 3;
|
||
|
nextI = nextI(bArr, nextI4 + 1, i4);
|
||
|
}
|
||
|
return i5 + decodeLastBlock(outputStream, (char) bArr[i4], (char) bArr[i3 - 3], (char) bArr[i3 - 2], (char) bArr[i3 - 1]);
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.util.encoders.Encoder
|
||
|
public int decode(String str, OutputStream outputStream) throws IOException {
|
||
|
int length = str.length();
|
||
|
while (length > 0 && ignore(str.charAt(length - 1))) {
|
||
|
length--;
|
||
|
}
|
||
|
int i = length - 4;
|
||
|
int i2 = 0;
|
||
|
int nextI = nextI(str, 0, i);
|
||
|
while (nextI < i) {
|
||
|
byte b = this.decodingTable[str.charAt(nextI)];
|
||
|
int nextI2 = nextI(str, nextI + 1, i);
|
||
|
byte b2 = this.decodingTable[str.charAt(nextI2)];
|
||
|
int nextI3 = nextI(str, nextI2 + 1, i);
|
||
|
byte b3 = this.decodingTable[str.charAt(nextI3)];
|
||
|
int nextI4 = nextI(str, nextI3 + 1, i);
|
||
|
byte b4 = this.decodingTable[str.charAt(nextI4)];
|
||
|
if ((b | b2 | b3 | b4) < 0) {
|
||
|
throw new IOException("invalid characters encountered in base64 data");
|
||
|
}
|
||
|
outputStream.write((b << 2) | (b2 >> 4));
|
||
|
outputStream.write((b2 << 4) | (b3 >> 2));
|
||
|
outputStream.write((b3 << 6) | b4);
|
||
|
i2 += 3;
|
||
|
nextI = nextI(str, nextI4 + 1, i);
|
||
|
}
|
||
|
return i2 + decodeLastBlock(outputStream, str.charAt(i), str.charAt(length - 3), str.charAt(length - 2), str.charAt(length - 1));
|
||
|
}
|
||
|
|
||
|
private int nextI(byte[] bArr, int i, int i2) {
|
||
|
while (i < i2 && ignore((char) bArr[i])) {
|
||
|
i++;
|
||
|
}
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
private int nextI(String str, int i, int i2) {
|
||
|
while (i < i2 && ignore(str.charAt(i))) {
|
||
|
i++;
|
||
|
}
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
private int decodeLastBlock(OutputStream outputStream, char c, char c2, char c3, char c4) throws IOException {
|
||
|
byte b = this.padding;
|
||
|
if (c3 == b) {
|
||
|
byte[] bArr = this.decodingTable;
|
||
|
byte b2 = bArr[c];
|
||
|
byte b3 = bArr[c2];
|
||
|
if ((b2 | b3) < 0) {
|
||
|
throw new IOException("invalid characters encountered at end of base64 data");
|
||
|
}
|
||
|
outputStream.write((b2 << 2) | (b3 >> 4));
|
||
|
return 1;
|
||
|
}
|
||
|
if (c4 == b) {
|
||
|
byte[] bArr2 = this.decodingTable;
|
||
|
byte b4 = bArr2[c];
|
||
|
byte b5 = bArr2[c2];
|
||
|
byte b6 = bArr2[c3];
|
||
|
if ((b4 | b5 | b6) < 0) {
|
||
|
throw new IOException("invalid characters encountered at end of base64 data");
|
||
|
}
|
||
|
outputStream.write((b4 << 2) | (b5 >> 4));
|
||
|
outputStream.write((b5 << 4) | (b6 >> 2));
|
||
|
return 2;
|
||
|
}
|
||
|
byte[] bArr3 = this.decodingTable;
|
||
|
byte b7 = bArr3[c];
|
||
|
byte b8 = bArr3[c2];
|
||
|
byte b9 = bArr3[c3];
|
||
|
byte b10 = bArr3[c4];
|
||
|
if ((b7 | b8 | b9 | b10) < 0) {
|
||
|
throw new IOException("invalid characters encountered at end of base64 data");
|
||
|
}
|
||
|
outputStream.write((b7 << 2) | (b8 >> 4));
|
||
|
outputStream.write((b8 << 4) | (b9 >> 2));
|
||
|
outputStream.write((b9 << 6) | b10);
|
||
|
return 3;
|
||
|
}
|
||
|
|
||
|
public Base64Encoder() {
|
||
|
initialiseDecodingTable();
|
||
|
}
|
||
|
}
|