1 /*
2  * Copyright (C) 2014 Square, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package okhttp3;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21
22 /**
23  * Versions of TLS that can be offered when negotiating a secure socket. See {@link
24  * javax.net.ssl.SSLSocket#setEnabledProtocols}.
25  */

26 public enum TlsVersion {
27   TLS_1_3("TLSv1.3"), // 2016.
28   TLS_1_2("TLSv1.2"), // 2008.
29   TLS_1_1("TLSv1.1"), // 2006.
30   TLS_1_0("TLSv1"),   // 1999.
31   SSL_3_0("SSLv3"),   // 1996.
32   ;
33
34   final String javaName;
35
36   TlsVersion(String javaName) {
37     this.javaName = javaName;
38   }
39
40   public static TlsVersion forJavaName(String javaName) {
41     switch (javaName) {
42       case "TLSv1.3":
43         return TLS_1_3;
44       case "TLSv1.2":
45         return TLS_1_2;
46       case "TLSv1.1":
47         return TLS_1_1;
48       case "TLSv1":
49         return TLS_1_0;
50       case "SSLv3":
51         return SSL_3_0;
52     }
53     throw new IllegalArgumentException("Unexpected TLS version: " + javaName);
54   }
55
56   static List<TlsVersion> forJavaNames(String... tlsVersions) {
57     List<TlsVersion> result = new ArrayList<>(tlsVersions.length);
58     for (String tlsVersion : tlsVersions) {
59       result.add(forJavaName(tlsVersion));
60     }
61     return Collections.unmodifiableList(result);
62   }
63
64   public String javaName() {
65     return javaName;
66   }
67 }
68