package org.bouncycastle.crypto.parsers; import java.io.IOException; import java.io.InputStream; import org.bouncycastle.crypto.KeyParser; import org.bouncycastle.crypto.params.AsymmetricKeyParameter; import org.bouncycastle.crypto.params.ECDomainParameters; import org.bouncycastle.crypto.params.ECPublicKeyParameters; import org.bouncycastle.util.io.Streams; /* loaded from: classes6.dex */ public class ECIESPublicKeyParser implements KeyParser { private ECDomainParameters ecParams; @Override // org.bouncycastle.crypto.KeyParser public AsymmetricKeyParameter readKey(InputStream inputStream) throws IOException { int fieldSize; int read = inputStream.read(); if (read == 0) { throw new IOException("Sender's public key invalid."); } if (read == 2 || read == 3) { fieldSize = (this.ecParams.getCurve().getFieldSize() + 7) / 8; } else { if (read != 4 && read != 6 && read != 7) { StringBuilder sb = new StringBuilder("Sender's public key has invalid point encoding 0x"); sb.append(Integer.toString(read, 16)); throw new IOException(sb.toString()); } fieldSize = ((this.ecParams.getCurve().getFieldSize() + 7) / 8) << 1; } byte[] bArr = new byte[fieldSize + 1]; bArr[0] = (byte) read; Streams.readFully(inputStream, bArr, 1, bArr.length - 1); return new ECPublicKeyParameters(this.ecParams.getCurve().decodePoint(bArr), this.ecParams); } public ECIESPublicKeyParser(ECDomainParameters eCDomainParameters) { this.ecParams = eCDomainParameters; } }