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 SshPublicKeyFormatFactory { 34 private static String defaultFormat; 35 private static HashMap formatTypes = new HashMap (); 36 private static Log log = LogFactory.getLog(SshPublicKeyFormatFactory.class); 37 38 static { 39 defaultFormat = "SECSH-PublicKey-Base64Encoded"; 40 formatTypes.put(defaultFormat, SECSHPublicKeyFormat.class); 41 } 42 43 52 public static SshPublicKeyFormat newInstance(String type) 53 throws InvalidKeyException { 54 try { 55 if (formatTypes.containsKey(type)) { 56 return (SshPublicKeyFormat) ((Class ) formatTypes.get(type)).newInstance(); 57 } else { 58 throw new InvalidKeyException("The format type " + type + 59 " is not supported"); 60 } 61 } catch (IllegalAccessException iae) { 62 throw new InvalidKeyException( 63 "Illegal access to class implementation of " + type); 64 } catch (InstantiationException ie) { 65 throw new InvalidKeyException( 66 "Failed to create instance of format type " + type); 67 } 68 } 69 70 75 public static String getDefaultFormatType() { 76 return defaultFormat; 77 } 78 } 79 | Popular Tags |