jdk/test/com/oracle/security/ucrypto/UcryptoTest.java
changeset 20775 a7cd22051d8f
parent 20774 330ea6efa3fd
parent 20773 65f064b13df0
child 20776 6c440a257019
child 20777 ad30bd042ffd
equal deleted inserted replaced
20774:330ea6efa3fd 20775:a7cd22051d8f
     1 /*
       
     2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 
       
    25 // common infrastructure for OracleUcrypto provider tests
       
    26 
       
    27 import java.io.*;
       
    28 import java.util.*;
       
    29 import java.lang.reflect.*;
       
    30 
       
    31 import java.security.*;
       
    32 
       
    33 public abstract class UcryptoTest {
       
    34 
       
    35     protected static final boolean hasUcrypto;
       
    36     static {
       
    37         hasUcrypto = (Security.getProvider("OracleUcrypto") != null);
       
    38     }
       
    39 
       
    40     private static Provider getCustomizedUcrypto(String config) throws Exception {
       
    41         Class clazz = Class.forName("com.oracle.security.ucrypto.OracleUcrypto");
       
    42         Constructor cons = clazz.getConstructor(new Class[] {String.class});
       
    43         Object obj = cons.newInstance(new Object[] {config});
       
    44         return (Provider)obj;
       
    45     }
       
    46 
       
    47     public abstract void doTest(Provider p) throws Exception;
       
    48 
       
    49     public static void main(UcryptoTest test, String config) throws Exception {
       
    50         Provider prov = null;
       
    51         if (hasUcrypto) {
       
    52             if (config != null) {
       
    53                 prov = getCustomizedUcrypto(config);
       
    54             } else {
       
    55                 prov = Security.getProvider("OracleUcrypto");
       
    56             }
       
    57         }
       
    58         if (prov == null) {
       
    59             // un-available, skip testing...
       
    60             System.out.println("No OracleUcrypto provider found, skipping test");
       
    61             return;
       
    62         }
       
    63         test.doTest(prov);
       
    64     }
       
    65 }