diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-12-10 20:25:39 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-12-10 20:25:39 +0000 |
commit | da66af5951b18b6f5e8752cbbe11f5f842332a33 (patch) | |
tree | a28e126d1415e3689be6c7b2c2d061ae51194195 /gnu/javax/net/ssl/provider/ProtocolVersion.java | |
parent | ab90923ee693a17e2e0e37b6ba5a84794c9236de (diff) | |
download | classpath-da66af5951b18b6f5e8752cbbe11f5f842332a33.tar.gz |
2006-12-10 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of generics-branch to HEAD (woohoo!)
Diffstat (limited to 'gnu/javax/net/ssl/provider/ProtocolVersion.java')
-rw-r--r-- | gnu/javax/net/ssl/provider/ProtocolVersion.java | 73 |
1 files changed, 47 insertions, 26 deletions
diff --git a/gnu/javax/net/ssl/provider/ProtocolVersion.java b/gnu/javax/net/ssl/provider/ProtocolVersion.java index 5f5d1d979..ca62054a8 100644 --- a/gnu/javax/net/ssl/provider/ProtocolVersion.java +++ b/gnu/javax/net/ssl/provider/ProtocolVersion.java @@ -42,15 +42,16 @@ import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; -final class ProtocolVersion implements Comparable, Constructed +public final class ProtocolVersion + implements Comparable<ProtocolVersion>, Constructed { // Constants and fields. // ------------------------------------------------------------------------- - static final ProtocolVersion SSL_3 = new ProtocolVersion(3, 0); - static final ProtocolVersion TLS_1 = new ProtocolVersion(3, 1); - static final ProtocolVersion TLS_1_1 = new ProtocolVersion(3, 2); + public static final ProtocolVersion SSL_3 = new ProtocolVersion(3, 0); + public static final ProtocolVersion TLS_1 = new ProtocolVersion(3, 1); + public static final ProtocolVersion TLS_1_1 = new ProtocolVersion(3, 2); private final int major; private final int minor; @@ -67,14 +68,25 @@ final class ProtocolVersion implements Comparable, Constructed // Class methods. // ------------------------------------------------------------------------- - static ProtocolVersion read(InputStream in) throws IOException + public static ProtocolVersion read(InputStream in) throws IOException { int major = in.read() & 0xFF; int minor = in.read() & 0xFF; return getInstance(major, minor); } - static ProtocolVersion getInstance(int major, int minor) + public static ProtocolVersion forName (final String name) + { + if (name.equalsIgnoreCase ("SSLv3")) + return SSL_3; + if (name.equalsIgnoreCase ("TLSv1")) + return TLS_1; + if (name.equalsIgnoreCase("TLSv1.1")) + return TLS_1_1; + throw new IllegalArgumentException ("unknown protocol name: " + name); + } + + public static ProtocolVersion getInstance(final int major, final int minor) { if (major == 3) { @@ -88,35 +100,46 @@ final class ProtocolVersion implements Comparable, Constructed return new ProtocolVersion(major, minor); } + public static ProtocolVersion getInstance (final short raw_value) + { + int major = raw_value >>> 8 & 0xFF; + int minor = raw_value & 0xFF; + return getInstance (major, minor); + } + // Instance methods. // ------------------------------------------------------------------------- - public void write(OutputStream out) throws IOException + public int length () { - out.write(major); - out.write(minor); + return 2; } - byte[] getEncoded() + public byte[] getEncoded() { return new byte[] { (byte) major, (byte) minor }; } - int getMajor() + public int major() { return major; } - int getMinor() + public int minor() { return minor; } + public int rawValue () + { + return (major << 8) | minor; + } + public boolean equals(Object o) { - if (o == null || !(o instanceof ProtocolVersion)) + if (!(o instanceof ProtocolVersion)) { return false; } @@ -129,35 +152,33 @@ final class ProtocolVersion implements Comparable, Constructed return major << 8 | minor; } - public int compareTo(Object o) + public int compareTo(ProtocolVersion that) { - if (o == null || !(o instanceof ProtocolVersion)) + if (major > that.major) { return 1; } - if (this.equals(o)) - { - return 0; - } - if (major > ((ProtocolVersion) o).major) - { - return 1; - } - else if (major < ((ProtocolVersion) o).major) + else if (major < that.major) { return -1; } - if (minor > ((ProtocolVersion) o).minor) + + if (minor > that.minor) { return 1; } - else if (minor < ((ProtocolVersion) o).minor) + else if (minor < that.minor) { return -1; } return 0; } + public String toString (String prefix) + { + return toString (); + } + public String toString() { if (this == SSL_3) |