1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/** 19* @author Vera Y. Petrashkova 20*/ 21 22package org.apache.harmony.auth.tests.support; 23 24import java.io.File; 25import java.security.Security; 26import java.security.Provider; 27import java.util.StringTokenizer; 28 29/** 30 * Additional class for verification spi-engine classes 31 * 32 */ 33 34public class SpiEngUtils { 35 36 public static final String[] invalidValues = { 37 "", 38 "BadAlgorithm", 39 "Long message Long message Long message Long message Long message Long message Long message Long message Long message Long message Long message Long message Long message" }; 40 41 /** 42 * Verification: is algorithm supported or not 43 * 44 * @param algorithm 45 * @param service 46 * @return 47 */ 48 public static Provider isSupport(String algorithm, String service) { 49 try { 50 Provider[] provs = Security.getProviders(service.concat(".") 51 .concat(algorithm)); 52 if (provs == null) { 53 return null; 54 } 55 return (provs.length == 0 ? null : provs[0]); 56 } catch (Exception e) { 57 return null; 58 } 59 } 60 61 public static String getFileName(String dir, String name) { 62 String res = dir; 63 if (res.charAt(res.length() - 1) == '/') { 64 res = res.substring(0, res.length() - 1); 65 } 66 char[] mm = { File.separatorChar }; 67 String sp = String.copyValueOf(mm); 68 StringTokenizer st = new StringTokenizer(name, "/"); 69 while (st.hasMoreElements()) { 70 res = res.concat(sp).concat((String) st.nextElement()); 71 } 72 return res; 73 } 74 75 public class MyProvider extends Provider { 76 private static final long serialVersionUID = 1L; 77 78 public MyProvider(String name, String info, String key, String clName) { 79 super(name, 1.0, info); 80 put(key, clName); 81 } 82 83 } 84 85}