1/* 2 * Copyright (C) 2013 The Android Open Source Project 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 17package org.conscrypt; 18 19import junit.framework.TestCase; 20import java.util.Arrays; 21import java.util.HashSet; 22 23public class SSLParametersImplTest extends TestCase { 24 25 public void testGetClientKeyType() throws Exception { 26 // See http://www.ietf.org/assignments/tls-parameters/tls-parameters.xml 27 byte b = Byte.MIN_VALUE; 28 do { 29 String byteString = Byte.toString(b); 30 String keyType = SSLParametersImpl.getClientKeyType(b); 31 switch (b) { 32 case 1: 33 assertEquals(byteString, "RSA", keyType); 34 break; 35 case 3: 36 assertEquals(byteString, "DH_RSA", keyType); 37 break; 38 case 64: 39 assertEquals(byteString, "EC", keyType); 40 break; 41 case 65: 42 assertEquals(byteString, "EC_RSA", keyType); 43 break; 44 case 66: 45 assertEquals(byteString, "EC_EC", keyType); 46 break; 47 default: 48 assertNull(byteString, keyType); 49 } 50 b++; 51 } while (b != Byte.MIN_VALUE); 52 } 53 54 public void testGetSupportedClientKeyTypes() throws Exception { 55 // Create an array with all possible values. Also, duplicate all values. 56 byte[] allClientCertificateTypes = new byte[512]; 57 for (int i = 0; i < allClientCertificateTypes.length; i++) { 58 allClientCertificateTypes[i] = (byte) i; 59 } 60 assertEquals( 61 new HashSet<String>(Arrays.asList("RSA", "DH_RSA", "EC", "EC_RSA", "EC_EC")), 62 SSLParametersImpl.getSupportedClientKeyTypes(allClientCertificateTypes)); 63 } 64} 65