31 import java.math.BigInteger; 32 import java.security.KeyException; 33 import java.security.PublicKey; 34 import java.util.List; 35 import javax.xml.crypto.*; 36 import javax.xml.crypto.dom.DOMCryptoContext; 37 import javax.xml.crypto.dsig.keyinfo.*; 38 import org.w3c.dom.Document; 39 import org.w3c.dom.Element; 40 import org.w3c.dom.Node; 41 42 /** 43 * DOM-based implementation of KeyInfoFactory. 44 * 45 * @author Sean Mullan 46 */ 47 public final class DOMKeyInfoFactory extends KeyInfoFactory { 48 49 public DOMKeyInfoFactory() { } 50 51 public KeyInfo newKeyInfo(List content) { 52 return newKeyInfo(content, null); 53 } 54 55 @SuppressWarnings("unchecked") 56 public KeyInfo newKeyInfo(List content, String id) { 57 return new DOMKeyInfo(content, id); 58 } 59 60 public KeyName newKeyName(String name) { 61 return new DOMKeyName(name); 62 } 63 64 public KeyValue newKeyValue(PublicKey key) throws KeyException { 65 String algorithm = key.getAlgorithm(); 66 if (algorithm.equals("DSA")) { 67 return new DOMKeyValue.DSA(key); 68 } else if (algorithm.equals("RSA")) { 69 return new DOMKeyValue.RSA(key); 70 } else if (algorithm.equals("EC")) { 71 return new DOMKeyValue.EC(key); 72 } else { 73 throw new KeyException("unsupported key algorithm: " + algorithm); 74 } 75 } 76 77 public PGPData newPGPData(byte[] keyId) { 78 return newPGPData(keyId, null, null); 79 } 80 81 @SuppressWarnings("unchecked") 82 public PGPData newPGPData(byte[] keyId, byte[] keyPacket, List other) { 83 return new DOMPGPData(keyId, keyPacket, other); 84 } 85 86 @SuppressWarnings("unchecked") 87 public PGPData newPGPData(byte[] keyPacket, List other) { 88 return new DOMPGPData(keyPacket, other); 89 } 90 91 public RetrievalMethod newRetrievalMethod(String uri) { 92 return newRetrievalMethod(uri, null, null); 93 } 94 95 @SuppressWarnings("unchecked") 96 public RetrievalMethod newRetrievalMethod(String uri, String type, 97 List transforms) { 98 if (uri == null) { 99 throw new NullPointerException("uri must not be null"); 100 } 101 return new DOMRetrievalMethod(uri, type, transforms); 102 } 103 104 @SuppressWarnings("unchecked") 105 public X509Data newX509Data(List content) { 106 return new DOMX509Data(content); 107 } 108 109 public X509IssuerSerial newX509IssuerSerial(String issuerName, 110 BigInteger serialNumber) { 111 return new DOMX509IssuerSerial(issuerName, serialNumber); 112 } 113 114 public boolean isFeatureSupported(String feature) { 115 if (feature == null) { 116 throw new NullPointerException(); 117 } else { 118 return false; 119 } 120 } 121 122 public URIDereferencer getURIDereferencer() { 123 return DOMURIDereferencer.INSTANCE; 124 } | 31 import java.math.BigInteger; 32 import java.security.KeyException; 33 import java.security.PublicKey; 34 import java.util.List; 35 import javax.xml.crypto.*; 36 import javax.xml.crypto.dom.DOMCryptoContext; 37 import javax.xml.crypto.dsig.keyinfo.*; 38 import org.w3c.dom.Document; 39 import org.w3c.dom.Element; 40 import org.w3c.dom.Node; 41 42 /** 43 * DOM-based implementation of KeyInfoFactory. 44 * 45 * @author Sean Mullan 46 */ 47 public final class DOMKeyInfoFactory extends KeyInfoFactory { 48 49 public DOMKeyInfoFactory() { } 50 51 @SuppressWarnings("rawtypes") 52 public KeyInfo newKeyInfo(List content) { 53 return newKeyInfo(content, null); 54 } 55 56 @SuppressWarnings({ "unchecked", "rawtypes" }) 57 public KeyInfo newKeyInfo(List content, String id) { 58 return new DOMKeyInfo(content, id); 59 } 60 61 public KeyName newKeyName(String name) { 62 return new DOMKeyName(name); 63 } 64 65 public KeyValue newKeyValue(PublicKey key) throws KeyException { 66 String algorithm = key.getAlgorithm(); 67 if (algorithm.equals("DSA")) { 68 return new DOMKeyValue.DSA(key); 69 } else if (algorithm.equals("RSA")) { 70 return new DOMKeyValue.RSA(key); 71 } else if (algorithm.equals("EC")) { 72 return new DOMKeyValue.EC(key); 73 } else { 74 throw new KeyException("unsupported key algorithm: " + algorithm); 75 } 76 } 77 78 public PGPData newPGPData(byte[] keyId) { 79 return newPGPData(keyId, null, null); 80 } 81 82 @SuppressWarnings({ "unchecked", "rawtypes" }) 83 public PGPData newPGPData(byte[] keyId, byte[] keyPacket, List other) { 84 return new DOMPGPData(keyId, keyPacket, other); 85 } 86 87 @SuppressWarnings({ "unchecked", "rawtypes" }) 88 public PGPData newPGPData(byte[] keyPacket, List other) { 89 return new DOMPGPData(keyPacket, other); 90 } 91 92 public RetrievalMethod newRetrievalMethod(String uri) { 93 return newRetrievalMethod(uri, null, null); 94 } 95 96 @SuppressWarnings({ "unchecked", "rawtypes" }) 97 public RetrievalMethod newRetrievalMethod(String uri, String type, 98 List transforms) { 99 if (uri == null) { 100 throw new NullPointerException("uri must not be null"); 101 } 102 return new DOMRetrievalMethod(uri, type, transforms); 103 } 104 105 @SuppressWarnings("rawtypes") 106 public X509Data newX509Data(List content) { 107 return new DOMX509Data(content); 108 } 109 110 public X509IssuerSerial newX509IssuerSerial(String issuerName, 111 BigInteger serialNumber) { 112 return new DOMX509IssuerSerial(issuerName, serialNumber); 113 } 114 115 public boolean isFeatureSupported(String feature) { 116 if (feature == null) { 117 throw new NullPointerException(); 118 } else { 119 return false; 120 } 121 } 122 123 public URIDereferencer getURIDereferencer() { 124 return DOMURIDereferencer.INSTANCE; 125 } |