AlgorithmIdTest.java revision 8118de3b2fc80daf5fc61c15ced9c84da4d02da7
18118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro/*
28118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro * Copyright (C) 2016 The Android Open Source Project
38118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro *
48118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro * Licensed under the Apache License, Version 2.0 (the "License");
58118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro * you may not use this file except in compliance with the License.
68118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro * You may obtain a copy of the License at
78118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro *
88118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro *      http://www.apache.org/licenses/LICENSE-2.0
98118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro *
108118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro * Unless required by applicable law or agreed to in writing, software
118118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro * distributed under the License is distributed on an "AS IS" BASIS,
128118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro * See the License for the specific language governing permissions and
148118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro * limitations under the License
158118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro */
168118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro
178118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giropackage libcore.sun.security.x509;
188118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro
198118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giroimport junit.framework.TestCase;
208118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro
218118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giroimport java.util.function.Function;
228118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro
238118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giroimport sun.security.util.ObjectIdentifier;
248118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giroimport sun.security.x509.AlgorithmId;
258118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro
268118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro
278118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giropublic class AlgorithmIdTest extends TestCase {
288118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro
298118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro    public void test_get_String() throws Exception {
308118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro        assertEquals("2.16.840.1.101.3.4.2.4", AlgorithmId.get("SHA-224").getOID().toString());
318118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro        assertEquals("2.16.840.1.101.3.4.2.4", AlgorithmId.get("SHA224").getOID().toString());
328118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro        assertEquals(
338118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro                "2.16.840.1.101.3.4.3.1", AlgorithmId.get("SHA224WithDSA").getOID().toString());
348118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro        assertEquals(
358118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro                "2.16.840.1.101.3.4.3.2", AlgorithmId.get("SHA256WithDSA").getOID().toString());
368118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro        // Case is irrelevant.
378118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro        assertEquals(
388118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro                "2.16.840.1.101.3.4.3.1", AlgorithmId.get("sHA224withDSA").getOID().toString());
398118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro        assertEquals(
408118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro                "2.16.840.1.101.3.4.3.2", AlgorithmId.get("sHA256withDSA").getOID().toString());
418118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro    }
428118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro
438118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro    public void test_getName() throws Exception {
448118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro        assertEquals("SHA224", getOidName("2.16.840.1.101.3.4.2.4"));
458118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro        assertEquals("SHA224withDSA", getOidName("2.16.840.1.101.3.4.3.1"));
468118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro        assertEquals("SHA256withDSA", getOidName("2.16.840.1.101.3.4.3.2"));
478118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro        assertEquals("SHA224withRSA", getOidName("1.2.840.113549.1.1.14"));
488118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro    }
498118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro
508118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro    private String getOidName(String oid) throws Exception {
518118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro        return new AlgorithmId(new ObjectIdentifier(oid)).getName();
528118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro    }
538118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro}
548118de3b2fc80daf5fc61c15ced9c84da4d02da7Sergio Giro
55