2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org.apache.harmony.xnet.provider.jsse;
19 import java.util.Hashtable;
23 * Represents Protocol Version
25 public class ProtocolVersion {
27 * Protocols supported by this provider implementation
29 public static final String[] supportedProtocols = new String[] { "TLSv1",
32 private static Hashtable<String, ProtocolVersion> protocolsByName = new Hashtable<String, ProtocolVersion>(4);
36 * Returns true if protocol version is supported
40 public static boolean isSupported(byte[] version) {
41 if (version[0] != 3 || (version[1] != 0 && version[1] != 1)) {
48 * Returns ProtocolVersion
53 public static ProtocolVersion getByVersion(byte[] version) {
54 if (version[0] == 3) {
55 if (version[1] == 1) {
58 if (version[1] == 0) {
66 * Returns true if provider supports protocol version
71 public static boolean isSupported(String name) {
72 return protocolsByName.containsKey(name);
76 * Returns ProtocolVersion
81 public static ProtocolVersion getByName(String name) {
82 return protocolsByName.get(name);
86 * Highest protocol version supported by provider implementation
91 public static ProtocolVersion getLatestVersion(String[] protocols) {
92 if (protocols == null || protocols.length == 0) {
95 ProtocolVersion latest = getByName(protocols[0]);
96 ProtocolVersion current;
97 for (int i = 1; i < protocols.length; i++) {
98 current = getByName(protocols[i]);
99 if (current == null) {
103 || (latest.version[0] < current.version[0])
104 || (latest.version[0] == current.version[0] && latest.version[1] < current.version[1])) {
113 * SSL 3.0 protocol version
115 public static ProtocolVersion SSLv3 = new ProtocolVersion("SSLv3",
116 new byte[] { 3, 0 });
119 * TLS 1.0 protocol version
121 public static ProtocolVersion TLSv1 = new ProtocolVersion("TLSv1",
122 new byte[] { 3, 1 });
125 protocolsByName.put(SSLv3.name, SSLv3);
126 protocolsByName.put(TLSv1.name, TLSv1);
127 protocolsByName.put("SSL", SSLv3);
128 protocolsByName.put("TLS", TLSv1);
134 public final String name;
137 * Protocol version as byte array
139 public final byte[] version;
141 private ProtocolVersion(String name, byte[] version) {
143 this.version = version;
147 * Compares this ProtocolVersion to the specified object.
150 public boolean equals(Object o) {
151 if (o instanceof ProtocolVersion
152 && this.version[0] == ((ProtocolVersion) o).version[0]
153 && this.version[1] == ((ProtocolVersion) o).version[1]) {