package o; import com.google.common.primitives.UnsignedBytes; 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 final class grP implements grQ { private byte[] d = {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}; private byte e = 61; private byte[] a = new byte[128]; private static boolean d(char c) { return c == '\n' || c == '\r' || c == '\t' || c == ' '; } public grP() { int i = 0; int i2 = 0; while (true) { byte[] bArr = this.a; if (i2 >= bArr.length) { break; } bArr[i2] = -1; i2++; } while (true) { byte[] bArr2 = this.d; if (i >= bArr2.length) { return; } this.a[bArr2[i]] = (byte) i; i++; } } @Override // o.grQ public final int e(byte[] bArr, int i, int i2, OutputStream outputStream) throws IOException { int i3; int i4 = i2 % 3; int i5 = i2 - i4; int i6 = i; while (true) { i3 = i + i5; if (i6 >= i3) { break; } int i7 = bArr[i6] & UnsignedBytes.MAX_VALUE; int i8 = bArr[i6 + 1] & UnsignedBytes.MAX_VALUE; byte b = bArr[i6 + 2]; outputStream.write(this.d[(i7 >>> 2) & 63]); outputStream.write(this.d[((i7 << 4) | (i8 >>> 4)) & 63]); outputStream.write(this.d[((i8 << 2) | ((b & UnsignedBytes.MAX_VALUE) >>> 6)) & 63]); outputStream.write(this.d[b & 63]); i6 += 3; } if (i4 == 1) { int i9 = bArr[i3] & UnsignedBytes.MAX_VALUE; outputStream.write(this.d[(i9 >>> 2) & 63]); outputStream.write(this.d[(i9 << 4) & 63]); outputStream.write(this.e); outputStream.write(this.e); } else if (i4 == 2) { int i10 = bArr[i3] & UnsignedBytes.MAX_VALUE; int i11 = bArr[i3 + 1] & UnsignedBytes.MAX_VALUE; outputStream.write(this.d[(i10 >>> 2) & 63]); outputStream.write(this.d[((i10 << 4) | (i11 >>> 4)) & 63]); outputStream.write(this.d[(i11 << 2) & 63]); outputStream.write(this.e); } return ((i5 / 3) << 2) + (i4 == 0 ? 0 : 4); } @Override // o.grQ public final int e(String str, OutputStream outputStream) throws IOException { int length = str.length(); while (length > 0 && d(str.charAt(length - 1))) { length--; } int i = length - 4; int i2 = 0; int i3 = 0; while (i3 < i && d(str.charAt(i3))) { i3++; } while (i3 < i) { byte b = this.a[str.charAt(i3)]; do { i3++; if (i3 >= i) { break; } } while (d(str.charAt(i3))); byte b2 = this.a[str.charAt(i3)]; do { i3++; if (i3 >= i) { break; } } while (d(str.charAt(i3))); byte b3 = this.a[str.charAt(i3)]; do { i3++; if (i3 >= i) { break; } } while (d(str.charAt(i3))); byte b4 = this.a[str.charAt(i3)]; 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; do { i3++; if (i3 < i) { } } while (d(str.charAt(i3))); } char charAt = str.charAt(i); char charAt2 = str.charAt(length - 3); char charAt3 = str.charAt(length - 2); int i4 = 1; char charAt4 = str.charAt(length - 1); byte b5 = this.e; if (charAt3 == b5) { byte[] bArr = this.a; byte b6 = bArr[charAt]; byte b7 = bArr[charAt2]; if ((b6 | b7) < 0) { throw new IOException("invalid characters encountered at end of base64 data"); } outputStream.write((b7 >> 4) | (b6 << 2)); } else if (charAt4 == b5) { byte[] bArr2 = this.a; byte b8 = bArr2[charAt]; byte b9 = bArr2[charAt2]; byte b10 = bArr2[charAt3]; if ((b8 | b9 | b10) < 0) { throw new IOException("invalid characters encountered at end of base64 data"); } outputStream.write((b8 << 2) | (b9 >> 4)); outputStream.write((b10 >> 2) | (b9 << 4)); i4 = 2; } else { byte[] bArr3 = this.a; byte b11 = bArr3[charAt]; byte b12 = bArr3[charAt2]; byte b13 = bArr3[charAt3]; byte b14 = bArr3[charAt4]; if ((b11 | b12 | b13 | b14) < 0) { throw new IOException("invalid characters encountered at end of base64 data"); } outputStream.write((b11 << 2) | (b12 >> 4)); outputStream.write((b12 << 4) | (b13 >> 2)); outputStream.write(b14 | (b13 << 6)); i4 = 3; } return i2 + i4; } }