package org.bouncycastle.crypto.tls; import java.io.IOException; import org.apache.http.conn.ssl.SSLSocketFactory; import org.bouncycastle.util.Strings; /* loaded from: classes6.dex */ public final class ProtocolVersion { private String name; private int version; public static final ProtocolVersion SSLv3 = new ProtocolVersion(768, "SSL 3.0"); public static final ProtocolVersion TLSv10 = new ProtocolVersion(769, "TLS 1.0"); public static final ProtocolVersion TLSv11 = new ProtocolVersion(770, "TLS 1.1"); public static final ProtocolVersion TLSv12 = new ProtocolVersion(771, "TLS 1.2"); public static final ProtocolVersion DTLSv10 = new ProtocolVersion(65279, "DTLS 1.0"); public static final ProtocolVersion DTLSv12 = new ProtocolVersion(65277, "DTLS 1.2"); public final String toString() { return this.name; } public final boolean isTLS() { return getMajorVersion() == 3; } public final boolean isSSL() { return this == SSLv3; } public final boolean isLaterVersionOf(ProtocolVersion protocolVersion) { if (getMajorVersion() != protocolVersion.getMajorVersion()) { return false; } int minorVersion = protocolVersion.getMinorVersion() - getMinorVersion(); if (isDTLS()) { if (minorVersion <= 0) { return false; } } else if (minorVersion >= 0) { return false; } return true; } public final boolean isEqualOrEarlierVersionOf(ProtocolVersion protocolVersion) { if (getMajorVersion() != protocolVersion.getMajorVersion()) { return false; } int minorVersion = protocolVersion.getMinorVersion() - getMinorVersion(); if (isDTLS()) { if (minorVersion > 0) { return false; } } else if (minorVersion < 0) { return false; } return true; } public final boolean isDTLS() { return getMajorVersion() == 254; } public final int hashCode() { return this.version; } public final int getMinorVersion() { return this.version & 255; } public final int getMajorVersion() { return this.version >> 8; } public final int getFullVersion() { return this.version; } public final ProtocolVersion getEquivalentTLSVersion() { return !isDTLS() ? this : this == DTLSv10 ? TLSv11 : TLSv12; } public final boolean equals(ProtocolVersion protocolVersion) { return protocolVersion != null && this.version == protocolVersion.version; } public final boolean equals(Object obj) { return this == obj || ((obj instanceof ProtocolVersion) && equals((ProtocolVersion) obj)); } private static ProtocolVersion getUnknownVersion(int i, int i2, String str) throws IOException { TlsUtils.checkUint8(i); TlsUtils.checkUint8(i2); int i3 = (i << 8) | i2; String upperCase = Strings.toUpperCase(Integer.toHexString(65536 | i3).substring(1)); StringBuilder sb = new StringBuilder(); sb.append(str); sb.append(" 0x"); sb.append(upperCase); return new ProtocolVersion(i3, sb.toString()); } public static ProtocolVersion get(int i, int i2) throws IOException { String str; if (i != 3) { if (i != 254) { throw new TlsFatalAlert((short) 47); } switch (i2) { case 253: return DTLSv12; case 254: throw new TlsFatalAlert((short) 47); case 255: return DTLSv10; default: str = "DTLS"; break; } } else { if (i2 == 0) { return SSLv3; } if (i2 == 1) { return TLSv10; } if (i2 == 2) { return TLSv11; } if (i2 == 3) { return TLSv12; } str = SSLSocketFactory.TLS; } return getUnknownVersion(i, i2, str); } private ProtocolVersion(int i, String str) { this.version = i & 65535; this.name = str; } }