Home | History | Annotate | Download | only in okhttp
      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 com.squareup.okhttp;
     17 
     18 import javax.net.ssl.SSLSocket;
     19 
     20 /**
     21  * Versions of TLS that can be offered when negotiating a secure socket. See
     22  * {@link SSLSocket#setEnabledProtocols}.
     23  */
     24 public enum TlsVersion {
     25   TLS_1_2("TLSv1.2"), // 2008.
     26   TLS_1_1("TLSv1.1"), // 2006.
     27   TLS_1_0("TLSv1"),   // 1999.
     28   SSL_3_0("SSLv3"),   // 1996.
     29   ;
     30 
     31   final String javaName;
     32 
     33   TlsVersion(String javaName) {
     34     this.javaName = javaName;
     35   }
     36 
     37   public static TlsVersion forJavaName(String javaName) {
     38     switch (javaName) {
     39       case "TLSv1.2": return TLS_1_2;
     40       case "TLSv1.1": return TLS_1_1;
     41       case "TLSv1": return TLS_1_0;
     42       case "SSLv3": return SSL_3_0;
     43     }
     44     throw new IllegalArgumentException("Unexpected TLS version: " + javaName);
     45   }
     46 
     47   public String javaName() {
     48     return javaName;
     49   }
     50 }
     51