1 19 20 package com.sslexplorer.security.pki; 21 22 import java.util.HashMap ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 28 33 public class SshPrivateKeyFormatFactory { 34 private static String defaultFormat; 35 private static HashMap formatTypes; 36 private static Log log = LogFactory.getLog(SshPrivateKeyFormatFactory.class); 37 38 static { 39 if (log.isInfoEnabled()) 40 log.info("Loading private key formats"); 41 42 formatTypes = new HashMap (); 43 defaultFormat = "SSHTools-PrivateKey-Base64Encoded"; 44 formatTypes.put(defaultFormat, SshtoolsPrivateKeyFormat.class); 45 46 } 47 48 public static void initialize() { 49 } 50 51 60 public static SshPrivateKeyFormat newInstance(String type) 61 throws InvalidKeyException { 62 try { 63 if (formatTypes.containsKey(type)) { 64 return (SshPrivateKeyFormat) ((Class ) formatTypes.get(type)).newInstance(); 65 } else { 66 throw new InvalidKeyException("The format type " + type + 67 " is not supported"); 68 } 69 } catch (IllegalAccessException iae) { 70 throw new InvalidKeyException( 71 "Illegal access to class implementation of " + type); 72 } catch (InstantiationException ie) { 73 throw new InvalidKeyException( 74 "Failed to create instance of format type " + type); 75 } 76 } 77 78 83 public static String getDefaultFormatType() { 84 return defaultFormat; 85 } 86 } 87 | Popular Tags |