diff options
Diffstat (limited to 'src/main/java/org/bouncycastle/crypto/tls/ProtocolVersion.java')
-rw-r--r-- | src/main/java/org/bouncycastle/crypto/tls/ProtocolVersion.java | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/src/main/java/org/bouncycastle/crypto/tls/ProtocolVersion.java b/src/main/java/org/bouncycastle/crypto/tls/ProtocolVersion.java index 87bb891c..aade297a 100644 --- a/src/main/java/org/bouncycastle/crypto/tls/ProtocolVersion.java +++ b/src/main/java/org/bouncycastle/crypto/tls/ProtocolVersion.java @@ -2,7 +2,8 @@ package org.bouncycastle.crypto.tls; import java.io.IOException;
-public final class ProtocolVersion {
+public final class ProtocolVersion
+{
public static final ProtocolVersion SSLv3 = new ProtocolVersion(0x0300, "SSL 3.0");
public static final ProtocolVersion TLSv10 = new ProtocolVersion(0x0301, "TLS 1.0");
@@ -14,69 +15,88 @@ public final class ProtocolVersion { private int version;
private String name;
- private ProtocolVersion(int v, String name) {
+ private ProtocolVersion(int v, String name)
+ {
this.version = v & 0xffff;
this.name = name;
}
- public int getFullVersion() {
+ public int getFullVersion()
+ {
return version;
}
- public int getMajorVersion() {
+ public int getMajorVersion()
+ {
return version >> 8;
}
- public int getMinorVersion() {
+ public int getMinorVersion()
+ {
return version & 0xff;
}
- public boolean isDTLS() {
+ public boolean isDTLS()
+ {
return getMajorVersion() == 0xFE;
}
- public boolean isSSL() {
+ public boolean isSSL()
+ {
return this == SSLv3;
}
- public ProtocolVersion getEquivalentTLSVersion() {
- if (!isDTLS()) {
+ public ProtocolVersion getEquivalentTLSVersion()
+ {
+ if (!isDTLS())
+ {
return this;
}
- if (this == DTLSv10) {
+ if (this == DTLSv10)
+ {
return TLSv11;
}
return TLSv12;
}
- public boolean isEqualOrEarlierVersionOf(ProtocolVersion version) {
- if (getMajorVersion() != version.getMajorVersion()) {
+ public boolean isEqualOrEarlierVersionOf(ProtocolVersion version)
+ {
+ if (getMajorVersion() != version.getMajorVersion())
+ {
return false;
}
int diffMinorVersion = version.getMinorVersion() - getMinorVersion();
return isDTLS() ? diffMinorVersion <= 0 : diffMinorVersion >= 0;
}
- public boolean isLaterVersionOf(ProtocolVersion version) {
- if (getMajorVersion() != version.getMajorVersion()) {
+ public boolean isLaterVersionOf(ProtocolVersion version)
+ {
+ if (getMajorVersion() != version.getMajorVersion())
+ {
return false;
}
int diffMinorVersion = version.getMinorVersion() - getMinorVersion();
return isDTLS() ? diffMinorVersion > 0 : diffMinorVersion < 0;
}
- public boolean equals(Object obj) {
+ public boolean equals(Object obj)
+ {
return this == obj;
}
- public int hashCode() {
+ public int hashCode()
+ {
return version;
}
- public static ProtocolVersion get(int major, int minor) throws IOException {
- switch (major) {
+ public static ProtocolVersion get(int major, int minor)
+ throws IOException
+ {
+ switch (major)
+ {
case 0x03:
- switch (minor) {
+ switch (minor)
+ {
case 0x00:
return SSLv3;
case 0x01:
@@ -87,7 +107,8 @@ public final class ProtocolVersion { return TLSv12;
}
case 0xFE:
- switch (minor) {
+ switch (minor)
+ {
case 0xFF:
return DTLSv10;
case 0xFD:
@@ -98,7 +119,8 @@ public final class ProtocolVersion { throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
- public String toString() {
+ public String toString()
+ {
return name;
}
}
|