You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by mu...@apache.org on 2006/01/27 22:00:36 UTC

svn commit: r372984 [3/4] - in /xml/security/branches/jsr105_0_16/src_unitTests/javax: ./ xml/ xml/crypto/ xml/crypto/test/ xml/crypto/test/dsig/ xml/crypto/test/dsig/dom/ xml/crypto/test/dsig/keyinfo/

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/TestUtils.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/TestUtils.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/TestUtils.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/TestUtils.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,247 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.*;
+import java.security.*;
+import java.security.spec.*;
+import java.util.*;
+import javax.crypto.SecretKey;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dsig.dom.DOMValidateContext;
+import javax.xml.crypto.dsig.keyinfo.*;
+import javax.xml.crypto.dsig.spec.*;
+import javax.xml.crypto.dom.*;
+import javax.xml.crypto.*;
+import java.math.BigInteger;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.*;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.*;
+
+public class TestUtils {
+    
+    private static final String DSA_Y = "07066284216756577193658833512863439617178933165631848358445549382240081120085333137303066923542492834619027404463194956043802393462371310375123430985057160";
+    private static final String DSA_P = "013232376895198612407547930718267435757728527029623408872245156039757713029036368719146452186041204237350521785240337048752071462798273003935646236777459223";
+    private static final String DSA_Q = "0857393771208094202104259627990318636601332086981";
+    private static final String DSA_G = "05421644057436475141609648488325705128047428394380474376834667300766108262613900542681289080713724597310673074119355136085795982097390670890367185141189796";
+    private static final String DSA_X = "0527140396812450214498055937934275626078768840117";
+    private static final String RSA_MOD = "010800185049102889923150759252557522305032794699952150943573164381936603255999071981574575044810461362008102247767482738822150129277490998033971789476107463";
+    private static final String RSA_PUB = "065537";
+    private static final String RSA_PRIV = "0161169735844219697954459962296126719476357984292128166117072108359155865913405986839960884870654387514883422519600695753920562880636800379454345804879553";
+    private static final String RSA_P = "0115424415723722114324966978423259908612124678699162475636761464258454949949323";
+    private static final String RSA_Q = "0102758196571776648976474223306363419966067908877619912985851335233169851905977";
+    private static final String RSA_PE = "046029221736415726351267405909515200750383424291661371450734102390935198695783";
+    private static final String RSA_QE = "044015259993025528938883140770194453900658533927591226289558855038612449192129";
+    private static final String RSA_COEFF = "039865059011857370650977286999500339769808774456169959084951368761860263797695";
+
+    private TestUtils() {}
+    
+    public static PublicKey getPublicKey(String algo) 
+	throws InvalidKeySpecException, NoSuchAlgorithmException {
+	KeyFactory kf = KeyFactory.getInstance(algo);
+	KeySpec kspec;
+	if (algo.equalsIgnoreCase("DSA")) {
+	    kspec = new DSAPublicKeySpec(new BigInteger(DSA_Y), 
+					 new BigInteger(DSA_P), 
+					 new BigInteger(DSA_Q), 
+					 new BigInteger(DSA_G));
+	} else if (algo.equalsIgnoreCase("RSA")) {
+	    kspec = new RSAPublicKeySpec(new BigInteger(RSA_MOD), 
+					 new BigInteger(RSA_PUB));
+	} else throw new RuntimeException("Unsupported key algorithm " + algo);
+	return kf.generatePublic(kspec);
+    }
+
+    public static PrivateKey getPrivateKey(String algo) 
+	throws InvalidKeySpecException, NoSuchAlgorithmException {
+	KeyFactory kf = KeyFactory.getInstance(algo);
+	KeySpec kspec;
+	if (algo.equalsIgnoreCase("DSA")) {
+	    kspec = new DSAPrivateKeySpec
+		(new BigInteger(DSA_X), new BigInteger(DSA_P), 
+		 new BigInteger(DSA_Q), new BigInteger(DSA_G));
+	} else if (algo.equalsIgnoreCase("RSA")) {
+	    kspec = new RSAPrivateKeySpec
+		(new BigInteger(RSA_MOD), new BigInteger(RSA_PRIV));
+	} else throw new RuntimeException("Unsupported key algorithm " + algo);
+	return kf.generatePrivate(kspec);
+    }
+
+    public static SecretKey getSecretKey(final byte[] secret) {
+	return new SecretKey() {
+	    public String getFormat()	{ return "RAW"; }
+	    public byte[] getEncoded()	{ return secret; }
+	    public String getAlgorithm(){ return "SECRET"; }
+	};
+    }
+    
+    public static Document newDocument() {
+	try {
+	    DocumentBuilderFactory docFac =
+                DocumentBuilderFactory.newInstance();
+	    docFac.setNamespaceAware(true);
+            DocumentBuilder docBuilder = docFac.newDocumentBuilder();
+	    return docBuilder.newDocument();
+	} catch (Exception ex) {
+	    return null;
+	}
+    }
+
+    public static class MyOwnC14nParameterSpec implements C14NMethodParameterSpec {}
+    
+    public static class MyOwnDigestMethodParameterSpec 
+	implements DigestMethodParameterSpec {}
+    
+    public static class MyOwnSignatureMethodParameterSpec 
+	implements SignatureMethodParameterSpec {}
+
+    public static XMLValidateContext getXMLValidateContext(String type, 
+						       File input, 
+						       String tag) 
+	throws Exception {
+	if (type.equalsIgnoreCase("dom")) {
+	    DocumentBuilderFactory docFactory =
+		DocumentBuilderFactory.newInstance();
+	    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
+	    Document doc = docBuilder.parse(input);
+	    if (tag == null) {
+		return new DOMValidateContext
+		    (TestUtils.getPublicKey("RSA"), doc.getDocumentElement());
+	    } else {
+		NodeList list = doc.getElementsByTagName(tag);
+		return new DOMValidateContext
+		    (TestUtils.getPublicKey("RSA"), list.item(0));
+	    }
+	} else {
+	    throw new Exception("Unsupported XMLValidateContext type: " + 
+				type);
+	}
+    }
+
+    public static class MyOwnDOMReference extends DOMStructure 
+	implements Reference {
+	private String id;
+	private boolean status;
+	private byte[] digest;
+	private static MessageDigest MD;
+	private static DigestMethod DIG_METHOD;
+	private Data derefData;
+	private InputStream dis;
+	static {
+	    try {
+		MD = MessageDigest.getInstance("SHA");
+		XMLSignatureFactory factory = XMLSignatureFactory.getInstance
+       		    ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+		DIG_METHOD = 
+		    factory.newDigestMethod(DigestMethod.SHA1, null);
+	    } catch (Exception ex) {
+		// should never be thrown
+	    }
+	};
+	
+	public MyOwnDOMReference(String id, boolean status) {
+	    super(newDocument());
+	    this.id = id;
+	    this.status = status;
+	    digest = null;
+	}
+
+	public byte[] getDigestValue() {
+	    if (digest == null) {
+		byte[] inBytes = id.getBytes();
+		digest = new byte[20];
+		if (status) {
+		    digest = MD.digest(inBytes);
+		}
+	    }
+	    return digest;
+	}
+	public byte[] getCalculatedDigestValue() {
+	    return null;
+	}
+	public DigestMethod getDigestMethod() { return DIG_METHOD; }
+	public String getId() {
+	    return id;
+	}
+	public String getType() {
+	    return null;
+	}
+	public String getURI() {
+	    return null;
+	}
+	public List getTransforms() {
+	    return Collections.EMPTY_LIST;
+	}
+	public boolean validate(XMLValidateContext vCtx) 
+	    throws XMLSignatureException {
+	    this.dis = new ByteArrayInputStream(id.getBytes());
+	    this.derefData = new OctetStreamData(this.dis);
+	    return status;
+	}
+	public Data getDereferencedData() {
+	    return derefData;
+	}
+	public InputStream getDigestInputStream() {
+	    return dis;
+        }
+    }
+
+    public static class MyOwnXMLStructure implements XMLStructure {
+	public boolean isFeatureSupported(String feature) 
+	    throws NullPointerException {
+	    if (feature == null) throw new NullPointerException();
+	    return false;
+	}
+    }
+
+    public static class SimpleURIDereferencer implements URIDereferencer {
+	private byte[] data = null;
+	public SimpleURIDereferencer(byte[] in) {
+	    data = (byte[]) in.clone();
+	}
+	public Data dereference(URIReference ref, XMLCryptoContext ctxt) {
+	    return new OctetStreamData(new ByteArrayInputStream(data));
+	}
+	public byte[] getData() {
+	    return data;
+	}
+	public boolean equals(Object obj) {
+	    if (obj instanceof SimpleURIDereferencer) {
+		return Arrays.equals(((SimpleURIDereferencer) obj).getData(),
+				     data);
+	    } else {
+		return false;
+	    }
+	}
+	public int hashCode() {
+	    return 5678;
+	}
+    }
+   
+    public static void dumpDocument(Document doc, String outName)
+	throws Exception {
+        DOMSource source = new DOMSource(doc);
+	File path = new File(System.getProperty("test.dir"), outName);
+        Result result = new StreamResult(new FileOutputStream(path));
+        Transformer trans = TransformerFactory.newInstance().newTransformer();
+        trans.setOutputProperty(OutputKeys.INDENT, "yes");
+        trans.transform(source, result);
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/TransformTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/TransformTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/TransformTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/TransformTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,153 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.util.Collections;
+import javax.xml.crypto.XMLStructure;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dsig.spec.TransformParameterSpec;
+import javax.xml.crypto.dsig.spec.XPathType;
+import javax.xml.crypto.dsig.spec.XPathFilterParameterSpec;
+import javax.xml.crypto.dsig.spec.XPathFilter2ParameterSpec;
+import javax.xml.crypto.dsig.spec.XSLTTransformParameterSpec;
+import java.security.*;
+import java.security.spec.*;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.dsig.Transform
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class TransformTest extends TestCase {
+
+    XMLSignatureFactory factory;
+
+    private static final String TRANSFORM_ALGOS[] = {
+	Transform.BASE64,
+	Transform.ENVELOPED,
+	Transform.XPATH,
+	Transform.XPATH2,
+	Transform.XSLT
+    };
+
+    static {
+        Security.insertProviderAt
+            (new org.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+    }
+
+    public TransformTest() {
+	super("TransformTest");
+    }
+
+    public TransformTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception { 
+	factory = XMLSignatureFactory.getInstance
+            ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+    }
+
+    public void tearDown() { }
+
+    public void testisFeatureSupported() throws Exception {
+	Transform tm; 
+	for (int i = 0; i < TRANSFORM_ALGOS.length; i++) {
+	    String algo = TRANSFORM_ALGOS[i];
+	    TransformParameterSpec params = null;
+	    if (algo.equals(Transform.XPATH)) {
+		params = new XPathFilterParameterSpec("xPath");
+	    } else if (algo.equals(Transform.XPATH2)) {
+		params = new XPathFilter2ParameterSpec
+		    (Collections.singletonList(new XPathType
+			("xPath2", XPathType.Filter.INTERSECT)));
+	    } else if (algo.equals(Transform.XSLT)) {
+		params = new XSLTTransformParameterSpec(new XSLTStructure());
+	    }
+	    tm = factory.newTransform(algo, params);
+	    try {
+		tm.isFeatureSupported(null); 
+		fail(TRANSFORM_ALGOS[i] + 
+		     ": Should raise a NPE for null feature"); 
+	    } catch (NullPointerException npe) {}
+	    
+	    assertTrue(!tm.isFeatureSupported("not supported"));
+	}
+    }
+
+    public void testConstructor() throws Exception {
+	// test newTransform(String algorithm, 
+	//                   AlgorithmParameterSpec params)
+	// for generating Transform objects
+	Transform tm; 
+	for (int i = 0; i < TRANSFORM_ALGOS.length; i++) {
+	    String algo = TRANSFORM_ALGOS[i];
+	    TransformParameterSpec params = null;
+	    if (algo.equals(Transform.XPATH)) {
+		params = new XPathFilterParameterSpec("xPath");
+	    } else if (algo.equals(Transform.XPATH2)) {
+		params = new XPathFilter2ParameterSpec
+		    (Collections.singletonList(new XPathType
+			("xPath2", XPathType.Filter.INTERSECT)));
+	    } else if (algo.equals(Transform.XSLT)) {
+		params = new XSLTTransformParameterSpec(new XSLTStructure());
+	    }
+	    try {
+		tm = factory.newTransform(algo, params);
+		assertNotNull(tm);
+		assertEquals(tm.getAlgorithm(), algo);
+		assertEquals(tm.getParameterSpec(), params);
+	    } catch (Exception ex) {
+		fail(TRANSFORM_ALGOS[i] + ": Unexpected exception " + ex); 
+	    }
+	    try {
+		tm = factory.newTransform
+		    (algo, new TestUtils.MyOwnC14nParameterSpec());
+		fail(TRANSFORM_ALGOS[i] + 
+		     ": Should raise an IAPE for invalid parameters"); 
+	    } catch (InvalidAlgorithmParameterException iape) {
+	    } catch (Exception ex) {
+		fail(TRANSFORM_ALGOS[i] + 
+		     ": Should raise a IAPE instead of " + ex); 
+	    }
+	}
+
+	try {
+	    tm = factory.newTransform(null, (TransformParameterSpec) null); 
+	    fail("Should raise a NPE for null algo"); 
+	} catch (NullPointerException npe) {
+	} catch (Exception ex) {
+	    fail("Should raise a NPE instead of " + ex); 
+	}
+
+	try {
+	    tm = factory.newTransform
+		("non-existent", (TransformParameterSpec) null); 
+	    fail("Should raise an NSAE for non-existent algos"); 
+	} catch (NoSuchAlgorithmException nsae) {
+	} catch (Exception ex) {
+	    fail("Should raise an NSAE instead of " + ex); 
+	}
+    }
+
+    private static class XSLTStructure implements XMLStructure {
+	public boolean isFeatureSupported(String feature) { return false; }
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/X509KeySelector.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/X509KeySelector.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/X509KeySelector.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/X509KeySelector.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,371 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.security.Key;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.PublicKey;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateFactory;
+import java.security.cert.CertSelector;
+import java.security.cert.X509Certificate;
+import java.security.cert.X509CertSelector;
+import java.util.*;
+import javax.security.auth.x500.X500Principal;
+import javax.xml.crypto.*;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dom.*;
+import javax.xml.crypto.dsig.keyinfo.*;
+
+import org.jcp.xml.dsig.internal.dom.DOMRetrievalMethod;
+
+/**
+ * A <code>KeySelector</code> that returns {@link PublicKey}s. If the
+ * selector is created as trusted, it only returns public keys of trusted
+ * {@link X509Certificate}s stored in a {@link KeyStore}. Otherwise, it
+ * returns trusted or untrusted public keys (it doesn't care as long
+ * as it finds one).
+ *
+ * <p>This <code>KeySelector</code> uses the specified <code>KeyStore</code>
+ * to find a trusted <code>X509Certificate</code> that matches information
+ * specified in the {@link KeyInfo} passed to the {@link #select} method. 
+ * The public key from the first match is returned. If no match, 
+ * <code>null</code> is returned. See the <code>select</code> method for more
+ * information.
+ *
+ * <p>NOTE!: This X509KeySelector requires J2SE 1.4 because it uses the
+ * java.security.cert.X509CertSelector & javax.security.auth.x500.X500Principal
+ * classes to parse X.500 DNs and match on certificate attributes.
+ *
+ * @author Sean Mullan
+ */
+public class X509KeySelector extends KeySelector {
+
+    private KeyStore ks;
+    private boolean trusted = true;
+
+    /**
+     * Creates a trusted <code>X509KeySelector</code>.
+     *
+     * @param keyStore the keystore
+     * @throws KeyStoreException if the keystore has not been initialized
+     * @throws NullPointerException if <code>keyStore</code> is 
+     *    <code>null</code>
+     */
+    public X509KeySelector(KeyStore keyStore) throws KeyStoreException {
+	this(keyStore, true);
+    }
+
+    public X509KeySelector(KeyStore keyStore, boolean trusted) 
+	throws KeyStoreException {
+        if (keyStore == null) {
+            throw new NullPointerException("keyStore is null");
+        }
+	this.trusted = trusted;
+        this.ks = keyStore;
+        // test to see if KeyStore has been initialized
+        this.ks.size();
+    }
+
+    /**
+     * Finds a key from the keystore satisfying the specified constraints.
+     *
+     * <p>This method compares data contained in {@link KeyInfo} entries
+     * with information stored in the <code>KeyStore</code>. The implementation
+     * iterates over the KeyInfo types and returns the first {@link PublicKey} 
+     * of an X509Certificate in the keystore that is compatible with the 
+     * specified AlgorithmMethod according to the following rules for each 
+     * keyinfo type:
+     *
+     * X509Data X509Certificate: if it contains a <code>KeyUsage</code>
+     *   extension that asserts the <code>digitalSignature</code> bit and 
+     *   matches an <code>X509Certificate</code> in the <code>KeyStore</code>.
+     * X509Data X509IssuerSerial: if the serial number and issuer DN match an 
+     *    <code>X509Certificate</code> in the <code>KeyStore</code>.
+     * X509Data X509SubjectName: if the subject DN matches an 
+     *    <code>X509Certificate</code> in the <code>KeyStore</code>.
+     * X509Data X509SKI: if the subject key identifier matches an 
+     *    <code>X509Certificate</code> in the <code>KeyStore</code>.
+     * KeyName: if the keyname matches an alias in the <code>KeyStore</code>.
+     * RetrievalMethod: supports rawX509Certificate and X509Data types. If 
+     *    rawX509Certificate type, it must match an <code>X509Certificate</code>
+     *    in the <code>KeyStore</code>.
+     *
+     * @param keyInfo a <code>KeyInfo</code> (may be <code>null</code>)
+     * @param purpose the key's purpose
+     * @param method the algorithm method that this key is to be used for.
+     *    Only keys that are compatible with the algorithm and meet the
+     *    constraints of the specified algorithm should be returned.
+     * @param an <code>XMLCryptoContext</code> that may contain additional
+     *    useful information for finding an appropriate key
+     * @return a key selector result
+     * @throws KeySelectorException if an exceptional condition occurs while
+     *    attempting to find a key. Note that an inability to find a key is not
+     *    considered an exception (<code>null</code> should be
+     *    returned in that case). However, an error condition (ex: network
+     *    communications failure) that prevented the <code>KeySelector</code>
+     *    from finding a potential key should be considered an exception.
+     * @throws ClassCastException if the data type of <code>method</code>
+     *    is not supported by this key selector
+     */
+    public KeySelectorResult select(KeyInfo keyInfo, 
+	KeySelector.Purpose purpose, AlgorithmMethod method,
+	XMLCryptoContext context) throws KeySelectorException {
+
+        SignatureMethod sm = (SignatureMethod) method;
+
+        try {
+            // return null if keyinfo is null or keystore is empty
+            if (keyInfo == null || ks.size() == 0) {
+                return new SimpleKeySelectorResult(null);
+            }
+
+            // Iterate through KeyInfo types
+            Iterator i = keyInfo.getContent().iterator();
+            while (i.hasNext()) {
+                XMLStructure kiType = (XMLStructure) i.next();
+		// check X509Data
+                if (kiType instanceof X509Data) {
+                    X509Data xd = (X509Data) kiType;
+		    KeySelectorResult ksr = x509DataSelect(xd, sm);
+	            if (ksr != null) {
+		        return ksr;
+	            }
+		// check KeyName
+                } else if (kiType instanceof KeyName) {
+		    KeyName kn = (KeyName) kiType;
+		    Certificate cert = ks.getCertificate(kn.getName());
+		    if (cert != null && algEquals(sm.getAlgorithm(),
+			cert.getPublicKey().getAlgorithm())) {
+			return new SimpleKeySelectorResult(cert.getPublicKey());
+		    }
+		// check RetrievalMethod
+                } else if (kiType instanceof RetrievalMethod) {
+		    RetrievalMethod rm = (RetrievalMethod) kiType;
+                    try {
+			KeySelectorResult ksr = null;
+		        if (rm.getType().equals
+			    (X509Data.RAW_X509_CERTIFICATE_TYPE)) {
+			    OctetStreamData data = (OctetStreamData) 
+				rm.dereference(context);
+			    CertificateFactory cf = 
+			        CertificateFactory.getInstance("X.509");
+			    X509Certificate cert = (X509Certificate) 
+			        cf.generateCertificate(data.getOctetStream());
+		            ksr = certSelect(cert, sm);
+		        } else if (rm.getType().equals(X509Data.TYPE)) {
+			    X509Data xd = (X509Data) ((DOMRetrievalMethod) rm).
+				dereferenceAsXMLStructure(context);
+		            ksr = x509DataSelect(xd, sm);
+		        } else {
+			    // skip; keyinfo type is not supported
+			    continue;
+			}
+		        if (ksr != null) {
+		            return ksr;
+	                }
+                    } catch (Exception e) {
+		        throw new KeySelectorException(e);
+		    }
+		}
+            }
+        } catch (KeyStoreException kse) {
+            // throw exception if keystore is uninitialized
+            throw new KeySelectorException(kse);
+        }
+
+        // return null since no match could be found
+        return new SimpleKeySelectorResult(null);
+    }
+
+    /**
+     * Searches the specified keystore for a certificate that matches the
+     * criteria specified in the CertSelector.
+     *
+     * @return a KeySelectorResult containing the cert's public key if there
+     *   is a match; otherwise null
+     */
+    private KeySelectorResult keyStoreSelect(CertSelector cs) 
+	throws KeyStoreException {
+        Enumeration aliases = ks.aliases();
+        while (aliases.hasMoreElements()) {
+	    String alias = (String) aliases.nextElement();
+	    Certificate cert = ks.getCertificate(alias);
+	    if (cert != null && cs.match(cert)) {
+	        return new SimpleKeySelectorResult(cert.getPublicKey());
+	    }
+	}
+	return null;
+    }
+
+    /**
+     * Searches the specified keystore for a certificate that matches the
+     * specified X509Certificate and contains a public key that is compatible
+     * with the specified SignatureMethod.
+     *
+     * @return a KeySelectorResult containing the cert's public key if there
+     *   is a match; otherwise null
+     */
+    private KeySelectorResult certSelect(X509Certificate xcert, 
+	SignatureMethod sm) throws KeyStoreException {
+        // skip non-signer certs
+        boolean[] keyUsage = xcert.getKeyUsage();
+        if (keyUsage != null && keyUsage[0] == false) {
+            return null;
+        }
+        String alias = ks.getCertificateAlias(xcert);
+        if (alias != null) {
+            PublicKey pk = ks.getCertificate(alias).getPublicKey();
+            // make sure algorithm is compatible with method
+            if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) {
+                return new SimpleKeySelectorResult(pk);
+            }
+        }
+	return null;
+    }
+
+    /**
+     * Returns an OID of a public-key algorithm compatible with the specified
+     * signature algorithm URI.
+     */
+    private String getPKAlgorithmOID(String algURI) {
+	if (algURI.equalsIgnoreCase(SignatureMethod.DSA_SHA1)) {
+	    return "1.2.840.10040.4.1";
+	} else if (algURI.equalsIgnoreCase(SignatureMethod.RSA_SHA1)) {
+	    return "1.2.840.113549.1.1";
+	} else {
+	    return null;
+	}
+    }
+
+    /**
+     * A simple KeySelectorResult containing a public key.
+     */
+    private static class SimpleKeySelectorResult implements KeySelectorResult {
+	private final Key key;
+	SimpleKeySelectorResult(Key key) { this.key = key; }
+	public Key getKey() { return key; }
+    }
+
+    /**
+     * Checks if a JCA/JCE public key algorithm name is compatible with
+     * the specified signature algorithm URI.
+     */
+    //@@@FIXME: this should also work for key types other than DSA/RSA
+    private boolean algEquals(String algURI, String algName) {
+        if (algName.equalsIgnoreCase("DSA") &&
+            algURI.equalsIgnoreCase(SignatureMethod.DSA_SHA1)) {
+            return true;
+        } else if (algName.equalsIgnoreCase("RSA") &&
+            algURI.equalsIgnoreCase(SignatureMethod.RSA_SHA1)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Searches the specified keystore for a certificate that matches an
+     * entry of the specified X509Data and contains a public key that is 
+     * compatible with the specified SignatureMethod.
+     *
+     * @return a KeySelectorResult containing the cert's public key if there
+     *   is a match; otherwise null
+     */
+    private KeySelectorResult x509DataSelect(X509Data xd, SignatureMethod sm) 
+	throws KeyStoreException, KeySelectorException {
+
+	// convert signature algorithm to compatible public-key alg OID
+	String algOID = getPKAlgorithmOID(sm.getAlgorithm());
+        X509CertSelector subjectcs = new X509CertSelector();
+	try {
+            subjectcs.setSubjectPublicKeyAlgID(algOID);
+        } catch (IOException ioe) {
+	    throw new KeySelectorException(ioe);
+	}
+        Collection certs = new ArrayList();
+
+        Iterator xi = xd.getContent().iterator();
+        while (xi.hasNext()) {
+            Object o = xi.next();
+	    // check X509IssuerSerial
+	    if (o instanceof X509IssuerSerial) {
+	        X509IssuerSerial xis = (X509IssuerSerial) o;
+	        try {
+	            subjectcs.setSerialNumber(xis.getSerialNumber());
+		    String issuer = new X500Principal(xis.getIssuerName()).getName();
+		    // strip off newline
+		    if (issuer.endsWith("\n")) {
+			issuer = new String
+			    (issuer.toCharArray(), 0, issuer.length()-1);
+		    }
+		    subjectcs.setIssuer(issuer);
+	        } catch (IOException ioe) {
+		    throw new KeySelectorException(ioe);
+		}
+	    // check X509SubjectName
+	    } else if (o instanceof String) {
+	        String sn = (String) o;
+	        try {
+		    String subject = new X500Principal(sn).getName();
+		    // strip off newline
+		    if (subject.endsWith("\n")) {
+			subject = new String
+			    (subject.toCharArray(), 0, subject.length()-1);
+		    }
+		    subjectcs.setSubject(subject);
+		} catch (IOException ioe) {
+		    throw new KeySelectorException(ioe);
+		}
+	    // check X509SKI
+	    } else if (o instanceof byte[]) {
+	        byte[] ski = (byte[]) o;
+		// DER-encode ski - required by X509CertSelector
+		byte[] encodedSki = new byte[ski.length+2];
+		encodedSki[0] = 0x04; // OCTET STRING tag value
+		encodedSki[1] = (byte) ski.length; // length
+		System.arraycopy(ski, 0, encodedSki, 2, ski.length);
+		subjectcs.setSubjectKeyIdentifier(encodedSki);
+	    } else if (o instanceof X509Certificate) {
+		certs.add((X509Certificate) o);
+	    // check X509CRL
+	    // not supported: should use CertPath API
+	    } else {
+	        // skip all other entries
+	        continue;
+	    }
+	}
+	KeySelectorResult ksr = keyStoreSelect(subjectcs);
+	if (ksr != null) {
+	    return ksr;
+	}
+	if (!certs.isEmpty() && !trusted) {
+	    // try to find public key in certs in X509Data
+	    Iterator i = certs.iterator();
+	    while (i.hasNext()) {
+		X509Certificate cert = (X509Certificate) i.next();
+		if (subjectcs.match(cert)) {
+		    return new SimpleKeySelectorResult(cert.getPublicKey());
+		}
+	    }
+	}
+	return null;
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLObjectTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLObjectTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLObjectTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLObjectTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.*;
+import java.util.*;
+import javax.xml.crypto.dsig.*;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.dsig.XMLObject
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class XMLObjectTest extends TestCase {
+
+    private XMLSignatureFactory factory;
+    private String id = "id";
+    private String mimeType = "mime";
+    private String encoding = "encoding";
+
+    public XMLObjectTest() {
+	super("XMLObjectTest");
+    }
+
+    public XMLObjectTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception {
+	factory = XMLSignatureFactory.getInstance
+            ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+    }
+    
+    public void tearDown() {}
+    
+    public void testConstructor() {
+	// test XMLSignatureFactory.newXMLObject(List, String, String, String) 
+	XMLObject obj;
+	
+	obj = factory.newXMLObject(null, null, null, null); 
+	assertNotNull(obj);
+
+	Vector list = new Vector();
+	obj = factory.newXMLObject(list, null, null, null); 
+	assertNotNull(obj);
+	
+	String strEntry = "wrong type";
+	list.add(strEntry);
+	try {
+	    obj = factory.newXMLObject(list, null, null, null); 
+	    fail("Should raise a CCE for content containing " +
+		 "invalid, i.e. non-XMLStructure, entries"); 
+	} catch (ClassCastException cce) {
+	} catch (Exception ex) {
+	    fail("Should raise a CCE for content with invalid entries " +
+		 "instead of " + ex);
+	}
+	list.remove(strEntry);
+	list.add(new TestUtils.MyOwnXMLStructure());
+	obj = factory.newXMLObject(list, id, mimeType, encoding);
+	assertNotNull(obj);
+	assertNotNull(obj.getContent());
+	assertTrue(Arrays.equals(obj.getContent().toArray(), list.toArray()));
+	assertEquals(obj.getId(), id);
+	assertEquals(obj.getMimeType(), mimeType);
+	assertEquals(obj.getEncoding(), encoding);
+
+	List unmodifiable = obj.getContent();
+	try {
+	    unmodifiable.add(new TestUtils.MyOwnXMLStructure());
+	    fail("Should return an unmodifiable List object");
+	} catch (UnsupportedOperationException uoe) {}
+	assertTrue(Arrays.equals(unmodifiable.toArray(), list.toArray()));
+    }
+
+    public void testisFeatureSupported() {
+	List list = new Vector();
+	list.add(new TestUtils.MyOwnXMLStructure());
+	XMLObject obj = factory.newXMLObject(list, id, mimeType, encoding);
+	try {
+	    obj.isFeatureSupported(null); 
+	    fail("Should raise a NPE for null feature"); 
+	} catch (NullPointerException npe) {}
+
+	assertTrue(!obj.isFeatureSupported("not supported"));
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignContextTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignContextTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignContextTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignContextTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.File;
+import java.io.ByteArrayInputStream;
+import javax.xml.crypto.*;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dsig.dom.DOMSignContext;
+import javax.xml.crypto.dom.*;
+import javax.xml.crypto.KeySelector;
+import java.security.*;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+import java.util.Arrays;
+import org.w3c.dom.Document;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.dsig.XMLSignContext
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class XMLSignContextTest extends TestCase {
+
+    private XMLSignContext defContext;
+    private Key[] KEYS;
+    private Document doc;
+
+    public XMLSignContextTest() {
+	super("XMLSignContextTest");
+    }
+
+    public XMLSignContextTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception {
+	// set up the signingKeys
+	KEYS = new Key[3];
+	KEYS[0] = TestUtils.getPrivateKey("DSA");
+	KEYS[1] = TestUtils.getPrivateKey("RSA");
+	KEYS[2] = new SecretKeySpec(new byte[16], "HmacSHA1");
+	// set up the default XMLSignContext
+	SecretKey sk = new SecretKeySpec(new byte[8], "DES");
+	doc = TestUtils.newDocument();
+	defContext = new DOMSignContext(sk, doc);
+    }
+
+    public void tearDown() { }
+
+    public void testsetngetBaseURI() throws Exception {
+	assertNull(defContext.getBaseURI());
+
+	String uri = "http://www.w3.org/2000/09/xmldsig#";
+	defContext.setBaseURI(uri);
+	assertEquals(defContext.getBaseURI(), uri);
+	defContext.setBaseURI(null);
+	assertNull(defContext.getBaseURI());
+    }
+
+
+    public void testsetngetProperty() throws Exception {
+	String name = "key";
+	assertNull(defContext.getProperty(name));
+	try {
+	    defContext.setProperty(null, null);
+	    fail("Should raise a NPE with a null name");
+	} catch (NullPointerException npe) {
+	} catch (Exception ex) {
+	    fail("Should raise a NPE instead of " + ex);
+	}
+	String value1 = "value#1";
+	String value2 = "value#2";
+	assertNull(defContext.setProperty(name, value1));
+	assertEquals(defContext.getProperty(name), value1);
+	assertEquals(defContext.setProperty(name, value2), value1);
+	assertEquals(defContext.getProperty(name), value2);
+	assertEquals(defContext.setProperty(name, null), value2);
+	assertNull(defContext.getProperty(name));
+    }
+
+    public void testsetngetURIDereferencer() throws Exception {
+	assertNull(defContext.getURIDereferencer());
+	byte[] data = "simpleDereferencer".getBytes();
+	URIDereferencer deref = new TestUtils.SimpleURIDereferencer(data);
+
+	defContext.setURIDereferencer(deref);
+	assertEquals(defContext.getURIDereferencer(), deref);
+	defContext.setURIDereferencer(null);
+	assertNull(defContext.getURIDereferencer());
+    }
+
+    public void testsetngetKeySelector() throws Exception {
+	defContext.setKeySelector(null);
+	assertNull(defContext.getKeySelector());
+	KeySelector ks = KeySelector.singletonKeySelector(KEYS[0]);
+	defContext.setKeySelector(ks);
+       	assertEquals(defContext.getKeySelector(), ks);
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureFactoryTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureFactoryTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureFactoryTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureFactoryTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.File;
+import java.math.BigInteger;
+import java.util.*;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.KeyException;
+import java.security.PublicKey;
+import java.security.Security;
+import javax.xml.crypto.dsig.keyinfo.*;
+import javax.xml.crypto.*;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dsig.dom.DOMValidateContext;
+import javax.xml.crypto.dom.*;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.dsig.XMLSignatureFactory
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class XMLSignatureFactoryTest extends TestCase {
+
+    XMLSignatureFactory factory;
+
+    static {
+        Security.insertProviderAt
+            (new org.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+    }
+
+    public XMLSignatureFactoryTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception { 
+	factory = XMLSignatureFactory.getInstance
+            ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+    }
+
+    public void tearDown() { }
+
+    public void testgetInstance() {
+	try {
+	    XMLSignatureFactory fac = 
+		XMLSignatureFactory.getInstance("non-existent");
+	    fail("Should throw NoSuchMechanismException if no impl found");
+	} catch (NoSuchMechanismException ex) {}
+
+	try {
+	    XMLSignatureFactory fac = XMLSignatureFactory.getInstance(null);
+	    fail("Should raise a NPE for null mechanismType"); 
+	} catch (NullPointerException npe) {}
+
+	try {
+	    XMLSignatureFactory fac = 
+		XMLSignatureFactory.getInstance("DOM", "non-existent");
+	    fail("Should throw NoSuchProviderException if specified " +
+		 "provider is not found");
+	} catch (NoSuchProviderException nspe) {
+	} catch (NoSuchMechanismException nse) {
+	    fail("Should raise a NoSuchProviderException instead of " + nse +
+		 " if specified provider is not found"); 
+	}
+
+	try {
+	    XMLSignatureFactory fac = XMLSignatureFactory.getInstance(null);
+	    fail("Should raise a NPE for null mechanismType"); 
+	} catch (NullPointerException npe) {}
+
+	try {
+	    XMLSignatureFactory fac = 
+		XMLSignatureFactory.getInstance("DOM", (Provider) null);
+	    fail("Should raise a NPE for null provider"); 
+	} catch (NullPointerException npe) {}
+    }
+
+    public void testgetMechanismType() {
+	assertNotNull(factory);
+	assertEquals("DOM", factory.getMechanismType());
+    }
+
+    public void testisFeatureSupported() {
+	try {
+	    factory.isFeatureSupported(null); 
+	    fail("Should raise a NPE for null feature"); 
+	} catch (NullPointerException npe) {}
+
+	assertTrue(!factory.isFeatureSupported("not supported"));
+    }
+
+    public void testgetKeyInfoFactory() throws Exception {
+	KeyInfoFactory kifac = factory.getKeyInfoFactory();
+	assertEquals(kifac.getMechanismType(), factory.getMechanismType());
+	assertEquals(kifac.getProvider(), factory.getProvider());
+    }
+
+    public void testunmarshalXMLSignature() throws Exception {
+	XMLSignature stuff;
+	try {
+	    stuff = factory.unmarshalXMLSignature((XMLValidateContext) null);
+	    fail("Should raise an NPE for null inputs"); 
+	} catch (NullPointerException ex) {
+	} catch (Exception ex) {
+	    fail("Should throw an NPE instead of " + ex +
+		 " for null inputs");
+	}
+
+	try {
+	    stuff = factory.unmarshalXMLSignature(
+		new XMLValidateContext() {
+		    public Object getProperty(String name) { return null; }
+		    public Object setProperty(String name, Object property) {
+			return null;
+		    }
+		    public String getBaseURI()	{ return null; }
+		    public void setBaseURI(String uri)	{ return; }
+		    public KeySelector getKeySelector() { return null; }
+		    public void setKeySelector(KeySelector ks) { return; }
+		    public URIDereferencer getURIDereferencer() { return null; }
+		    public void setURIDereferencer(URIDereferencer ud) {return;}
+		    public Object get(Object key) {return null;}
+		    public Object put(Object key, Object value) {return null;}
+                    public void setDefaultNamespacePrefix(String defPrefix) {}
+                    public String getDefaultNamespacePrefix() {return null;}
+                    public String putNamespacePrefix
+                        (String nsURI, String prefix) {return null;}
+                    public String getNamespacePrefix
+                        (String nsURI, String defPrefix) {return null;}
+		    });
+	    fail("Should throw a CCE for input of wrong type"); 
+	} catch (ClassCastException ex) {
+	} catch (Exception ex) {
+	    fail("Should raise a CCE instead of " + ex +
+		 " for wrong inputs"); 
+	}
+
+        DocumentBuilderFactory docFactory =
+            DocumentBuilderFactory.newInstance();
+	docFactory.setNamespaceAware(true);
+	DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
+	String fs = System.getProperty("file.separator");
+	File dir = new File(System.getProperty("basedir") + fs +
+	    "data" + fs + "ie" + fs + "baltimore" + fs + "merlin-examples",
+	    "merlin-xmldsig-twenty-three");
+	Document doc = docBuilder.parse(new File(dir, "signature.xml"));
+	NodeList nl = doc.getElementsByTagName("KeyInfo");
+	try {
+	    stuff = factory.unmarshalXMLSignature
+	    (new DOMValidateContext(TestUtils.getPublicKey("RSA"), nl.item(0)));
+	    fail("Should throw a MarshalException for non-XMLSignature inputs"); 
+	} catch (MarshalException ex) {}
+	
+	nl = doc.getElementsByTagName("Signature");
+	try {
+	    stuff = factory.unmarshalXMLSignature
+	    (new DOMValidateContext(TestUtils.getPublicKey("DSA"), nl.item(0)));
+	    assertNotNull(stuff);
+	} catch (MarshalException ex) {
+	    fail("Unmarshal failed: " + ex.getMessage());
+	    ex.printStackTrace();
+	}
+    }
+
+    // for debugging purposes
+    public static void main(String[] args) throws Exception {
+	XMLSignatureFactoryTest test = 
+	    new XMLSignatureFactoryTest("XMLSignatureFactoryTest");
+	test.setUp();
+	test.testunmarshalXMLSignature();
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,205 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.*;
+import java.util.*;
+import java.security.*;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dsig.keyinfo.*;
+import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec;
+import javax.xml.crypto.dsig.dom.DOMSignContext;
+import javax.xml.crypto.dsig.dom.DOMValidateContext;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+
+import javax.xml.transform.*;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.dsig.XMLSignature
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class XMLSignatureTest extends TestCase {
+    private XMLSignatureFactory fac;
+    private KeyInfoFactory kifac;
+    private SignedInfo defSi;
+    private KeyInfo defKi;
+    private List objs;
+    private String id = "id";
+    private String sigValueId = "signatureValueId";
+    private Key[] SIGN_KEYS;
+    private Key[] VALIDATE_KEYS;
+    private SignatureMethod[] SIG_METHODS;
+
+    static {
+        Security.insertProviderAt
+            (new org.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+    }
+
+    public XMLSignatureTest() {
+	super("XMLSignatureTest");
+    }
+
+    public XMLSignatureTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception {
+	fac = XMLSignatureFactory.getInstance
+            ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+	kifac = KeyInfoFactory.getInstance
+            ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+
+	// set up the corresponding SignatureMethod 
+	SIG_METHODS = new SignatureMethod[3];
+	SIG_METHODS[0] = fac.newSignatureMethod(SignatureMethod.DSA_SHA1, null);
+	SIG_METHODS[1] = fac.newSignatureMethod(SignatureMethod.RSA_SHA1, null);
+	SIG_METHODS[2] = fac.newSignatureMethod(SignatureMethod.HMAC_SHA1, null);
+	// set up the signingKeys
+	SIGN_KEYS = new Key[3];
+	SIGN_KEYS[0] = TestUtils.getPrivateKey("DSA");
+	SIGN_KEYS[1] = TestUtils.getPrivateKey("RSA");
+	SIGN_KEYS[2] = new SecretKeySpec(new byte[16], "HmacSHA1");
+	// set up the validatingKeys
+	VALIDATE_KEYS = new Key[3];
+	VALIDATE_KEYS[0] = TestUtils.getPublicKey("DSA");
+	VALIDATE_KEYS[1] = TestUtils.getPublicKey("RSA");
+	VALIDATE_KEYS[2] = new SecretKeySpec(new byte[16], "HmacSHA1");
+	defSi = createSignedInfo(SIG_METHODS[0]);
+	defKi = kifac.newKeyInfo
+	    (Collections.singletonList(kifac.newKeyName("Alice")));
+	objs = Collections.singletonList
+	    (fac.newXMLObject(null, null, null, null));
+    }
+
+    public void tearDown() {}
+
+    public void testConstructor() throws Exception {
+	XMLSignature sig = null;
+	// test  XMLSignatureFactory.newXMLSignature(SignedInfo, KeyInfo)
+	// and  XMLSignatureFactory.newXMLSignature(SignedInfo,
+	//          KeyInfo, List, String, String)
+	// for generating XMLSignature objects
+	for (int i = 0; i < 2; i++) {
+	    try {
+		switch (i) {
+		case 0:
+		    sig = fac.newXMLSignature(null, defKi);
+		    break;
+		case 1:
+		    sig = fac.newXMLSignature(null, defKi, objs, id, sigValueId);
+		    break;
+		}
+		fail("Should throw a NPE for null references");
+	    } catch (NullPointerException npe) {
+	    } catch (Exception ex) {
+		fail("Should throw a NPE instead of " + ex + 
+		     " for null references");
+	    }
+	}
+	try {
+	    sig = fac.newXMLSignature(defSi, defKi, 
+		     Collections.singletonList("wrongType"), id, sigValueId);
+	    fail("Should throw a CCE for invalid objects");
+	} catch (ClassCastException cce) {
+	} catch (Exception ex) {
+	    fail("Should throw a CCE instead of " + ex + 
+		 " for invalid objects");
+	}
+	sig = fac.newXMLSignature(defSi, defKi, objs, id, sigValueId);
+	assertEquals(sig.getId(), id);
+	assertEquals(sig.getKeyInfo(), defKi);
+	assertTrue(Arrays.equals(sig.getObjects().toArray(), objs.toArray()));
+	assertNull(sig.getSignatureValue().getValue());
+	assertEquals(sig.getSignatureValue().getId(), sigValueId);
+	assertEquals(sig.getSignedInfo(), defSi);
+
+	sig = fac.newXMLSignature(defSi, defKi);
+	assertNull(sig.getId());
+	assertEquals(sig.getKeyInfo(), defKi);
+	assertTrue(sig.getObjects().size()==0);
+	assertNull(sig.getSignatureValue().getValue());
+	assertNull(sig.getSignatureValue().getId());
+	assertEquals(sig.getSignedInfo(), defSi);
+    }
+    
+    public void testisFeatureSupported() throws Exception {
+
+	XMLSignature sig = fac.newXMLSignature(defSi, null);
+	
+	try {
+	    sig.isFeatureSupported(null); 
+	    fail("Should raise a NPE for null feature"); 
+	} catch (NullPointerException npe) {}
+	    
+	assertTrue(!sig.isFeatureSupported("not supported"));
+    }
+
+    public void testsignANDvalidate() throws Exception {
+	XMLSignature sig;
+	SignedInfo si;
+	KeyInfo ki = null;
+	XMLSignContext signContext;
+	XMLValidateContext validateContext;
+	boolean status = true;
+	for (int i = SIGN_KEYS.length-1; i>=0 ; i--) {
+	    si = createSignedInfo(SIG_METHODS[i]);
+	    if (VALIDATE_KEYS[i] instanceof PublicKey) {
+		ki = kifac.newKeyInfo(Collections.singletonList
+		    (kifac.newKeyValue((PublicKey) VALIDATE_KEYS[i])));
+	    } else {
+		ki = kifac.newKeyInfo(Collections.singletonList
+		    (kifac.newKeyName("testuser")));
+	    }
+	    sig = fac.newXMLSignature(si, ki, objs, id, sigValueId); 
+	    Document doc = TestUtils.newDocument();
+	    signContext = new DOMSignContext(SIGN_KEYS[i], doc);
+	    sig.sign(signContext);
+	    validateContext = new DOMValidateContext
+		(VALIDATE_KEYS[i], doc.getDocumentElement());
+	    if (sig.validate(validateContext) == false) {
+		status = false;
+		TestUtils.dumpDocument(doc, "signatureTest_out"+i+".xml");
+	    }
+	}
+	assertTrue(status);
+    }
+
+    private SignedInfo createSignedInfo(SignatureMethod sm) throws Exception {
+	// set up the building blocks
+	CanonicalizationMethod cm = fac.newCanonicalizationMethod
+	    (CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS, 
+	     (C14NMethodParameterSpec) null);
+	DigestMethod dm = fac.newDigestMethod(DigestMethod.SHA1, null);
+	List refs = Collections.singletonList(fac.newReference
+	    ("http://www.w3.org/Signature/2002/04/xml-stylesheet.b64", dm));
+        return fac.newSignedInfo(cm, sm, refs);
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLValidateContextTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLValidateContextTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLValidateContextTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLValidateContextTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.File;
+import java.io.ByteArrayInputStream;
+import javax.xml.crypto.*;
+import javax.xml.crypto.dsig.dom.DOMValidateContext;
+import javax.xml.crypto.dsig.*;
+import java.security.*;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.dsig.XMLValidateContext
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class XMLValidateContextTest extends TestCase {
+
+    private XMLValidateContext defContext;
+    private Key[] KEYS;
+    private KeySelector[] KEY_SELECTORS;
+
+    public XMLValidateContextTest() {
+	super("XMLValidateContextTest");
+    }
+
+    public XMLValidateContextTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception {
+
+	// set up the validatingKeys
+	KEYS = new Key[3];
+	KEYS[0] = TestUtils.getPublicKey("DSA");
+	KEYS[1] = TestUtils.getPublicKey("RSA");
+	KEYS[2] = new SecretKeySpec(new byte[16], "HmacSHA1");
+
+	// set up the default XMLValidateContext
+	SecretKey sk = new SecretKeySpec(new byte[8], "DES");
+	defContext = new DOMValidateContext(sk, TestUtils.newDocument());
+
+	// set up the key selectors
+	KEY_SELECTORS = new KeySelector[1];
+        KEY_SELECTORS[0] = KeySelector.singletonKeySelector(sk);
+    }
+
+    public void tearDown() { }
+
+    public void testsetngetKeySelector() throws Exception {
+	defContext.setKeySelector(null);
+	assertNull(defContext.getKeySelector());
+
+	for (int i = 0; i < KEY_SELECTORS.length; i++) {
+	    defContext.setKeySelector(KEY_SELECTORS[i]);
+	    assertEquals(defContext.getKeySelector(), KEY_SELECTORS[i]);
+	}
+    }
+
+    public void testsetngetBaseURI() throws Exception {
+	assertNull(defContext.getBaseURI());
+
+	String uri = "http://www.w3.org/2000/09/xmldsig#";
+	defContext.setBaseURI(uri);
+	assertEquals(defContext.getBaseURI(), uri);
+	defContext.setBaseURI(null);
+	assertNull(defContext.getBaseURI());
+    }
+
+    public void testsetngetProperty() throws Exception {
+	String name = "key";
+	assertNull(defContext.getProperty(name));
+	try {
+	    defContext.setProperty(null, null);
+	    fail("Should raise a NPE with a null name");
+	} catch (NullPointerException npe) {
+	} catch (Exception ex) {
+	    fail("Should raise a NPE instead of " + ex);
+	}
+	String value1 = "value#1";
+	String value2 = "value#2";
+	assertNull(defContext.setProperty(name, value1));
+	assertEquals(defContext.getProperty(name), value1);
+	assertEquals(defContext.setProperty(name, value2), value1);
+	assertEquals(defContext.getProperty(name), value2);
+	assertEquals(defContext.setProperty(name, null), value2);
+	assertNull(defContext.getProperty(name));
+    }
+
+    public void testsetngetURIDereferencer() throws Exception {
+	assertNull(defContext.getURIDereferencer());
+	byte[] data = "simpleDereferencer".getBytes();
+	URIDereferencer deref = new TestUtils.SimpleURIDereferencer(data);
+
+	defContext.setURIDereferencer(deref);
+	assertEquals(defContext.getURIDereferencer(), deref);
+	defContext.setURIDereferencer(null);
+	assertNull(defContext.getURIDereferencer());
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/dom/DOMValidateContextTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/dom/DOMValidateContextTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/dom/DOMValidateContextTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/dom/DOMValidateContextTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ */
+package javax.xml.crypto.test.dsig.dom;
+
+import java.io.*;
+import java.util.*;
+import javax.xml.crypto.*;
+import javax.xml.crypto.dsig.dom.DOMValidateContext;
+import javax.xml.crypto.dsig.XMLValidateContext;
+
+import junit.framework.*;
+
+import javax.xml.crypto.test.dsig.TestUtils;
+
+/**
+ * Unit test for javax.xml.crypto.dsig.dom.DOMValidateContext
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class DOMValidateContextTest extends TestCase {
+    private DOMValidateContext domVC;
+
+    public DOMValidateContextTest() {
+	super("DOMValidateContext");
+    }
+
+    public DOMValidateContextTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception {
+	String fs = System.getProperty("file.separator");
+	File dir = new File(System.getProperty("basedir") + fs +
+	    "data" + fs + "ie" + fs + "baltimore" + fs + "merlin-examples",
+	    "merlin-xmldsig-twenty-three");
+	File input = new File(dir, "signature.xml");
+	domVC = (DOMValidateContext)
+	    TestUtils.getXMLValidateContext("DOM", input, "Reference");
+    }
+
+    public void tearDown() {}
+
+    public void testConstructor() throws Exception {
+	assertNotNull(domVC);
+	DOMValidateContext vc;
+	try {
+	    vc = new DOMValidateContext(TestUtils.getPublicKey("RSA"), null);
+	    fail("Should throw a NPE for null node");
+	} catch (NullPointerException npe) {
+	} catch (Exception ex) {
+	    fail("Should throw a NPE instead of " + ex + " for null node");
+	}
+    }
+
+    public void testsetngetProperty() throws Exception {
+	try {
+	    domVC.setProperty(null, "value");
+	} catch (NullPointerException npe) {
+	} catch (Exception ex) {
+	    fail("Should throw a NPE instead of " + ex + " for null name");
+	}
+	try {
+	    domVC.getProperty(null);
+	} catch (NullPointerException npe) {
+	} catch (Exception ex) {
+	    fail("Should throw a NPE instead of " + ex + " for null name");
+	}
+	String pname = "name";
+	String pvalue1 = "value";
+	String pvalue2 = "newvalue";
+	assertNull(domVC.setProperty(pname, pvalue1));
+	assertEquals((String)domVC.getProperty(pname), pvalue1);
+	assertEquals(domVC.setProperty(pname, pvalue2), pvalue1);
+       	assertEquals((String)domVC.getProperty(pname), pvalue2);
+    }
+
+    public void testsetngetNode() throws Exception {
+	try {
+	    domVC.setNode(null);
+	} catch (NullPointerException npe) {
+	} catch (Exception ex) {
+	    fail("Should throw a NPE instead of " + ex + " for null node");
+	}
+	assertNotNull(domVC.getNode());
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoFactoryTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoFactoryTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoFactoryTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoFactoryTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,249 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig.keyinfo;
+
+import java.math.BigInteger;
+import java.util.*;
+import java.security.KeyException;
+import java.security.PublicKey;
+import javax.xml.crypto.dsig.keyinfo.*;
+import javax.xml.crypto.*;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dom.*;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.dsig.keyinfo.KeyInfoFactory
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class KeyInfoFactoryTest extends TestCase {
+
+    KeyInfoFactory factory;
+
+    public KeyInfoFactoryTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception { 
+	factory = KeyInfoFactory.getInstance
+	    ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+    }
+
+    public void tearDown() { }
+
+    public void testgetInstance() {
+	try {
+	    KeyInfoFactory fac = KeyInfoFactory.getInstance("non-existent");
+	    fail("Should throw NoSuchMechanismException if no impl found");
+	} catch (NoSuchMechanismException ex) {}
+
+	try {
+	    KeyInfoFactory fac = KeyInfoFactory.getInstance(null);
+	    fail("Should raise a NPE for null xmltype"); 
+	} catch (NullPointerException npe) {}
+    }
+
+    public void testgetMechanismType() {
+	assertNotNull(factory);
+	assertEquals("DOM", factory.getMechanismType());
+    }
+
+    public void testisFeatureSupported() {
+	try {
+	    factory.isFeatureSupported(null); 
+	    fail("Should raise a NPE for null feature"); 
+	} catch (NullPointerException npe) {}
+
+	assertTrue(!factory.isFeatureSupported("not supported"));
+    }
+
+    public void testnewKeyInfo() {
+	String id = "keyId";
+	// test newKeyInfo(List, String)
+	KeyInfo ki = factory.newKeyInfo
+	    (Collections.singletonList(factory.newKeyName("foo")), id);
+	assertEquals(id, ki.getId());
+	try {
+	    ki = factory.newKeyInfo(null, id); 
+	    fail("Should raise a NPE for null key info types"); 
+	} catch (NullPointerException npe) {}
+    }
+
+    public void testnewKeyName() {
+	final String name = "keyName";
+	KeyName kn = factory.newKeyName(name);
+	assertEquals(name, kn.getName());
+	try {
+	    kn = factory.newKeyName(null); 
+	    fail("Should raise a NPE for null key name"); 
+	} catch (NullPointerException npe) {}
+    }
+
+    public void testnewKeyValue() {
+	// test newKeyValue(PublicKey pk)
+	PublicKey myPubKey = new PublicKey() {
+		public byte[] getEncoded() {
+		    return new byte[20];
+		}
+		public String getFormat() {
+		    return "none";
+		}
+		public String getAlgorithm() {
+		    return "test";
+		}
+	    };
+	try {
+	    KeyValue kv = factory.newKeyValue(myPubKey);
+	    assertEquals(myPubKey, kv.getPublicKey());
+	    fail("Should throw a KeyException");
+	} catch (KeyException ke) { }
+  
+	try {
+	    KeyValue kv = factory.newKeyValue((PublicKey) null); 
+	    fail("Should raise a NPE for null key"); 
+	} catch (KeyException ke) {
+	    fail("Should raise a NPE for null key"); 
+	} catch (NullPointerException npe) {}
+    }
+
+    public void testnewPGPKeyId() {
+	byte[] valid_id = { 
+	    0x01, 0x02, 0x03, 0x04,
+	    0x05, 0x06, 0x07, 0x08 
+	};
+	byte[] invalid_id = {
+	    0x01, 0x02, 0x03, 0x04,
+	    0x05, 0x06, 0x07, 0x08,
+	    0x09
+	};
+	byte[] valid_packet = { (byte)0xc6, (byte)0x01, (byte)0x00 };
+	byte[] invalid_packet = { (byte)0xc8, (byte)0x01, (byte)0x00 };
+
+	// test newPGPData(byte[])
+	PGPData pd = factory.newPGPData(valid_id);
+	assertTrue(Arrays.equals(valid_id, pd.getKeyId()));
+	try {
+	    pd = factory.newPGPData(invalid_id);
+	    fail("Should throw IAE for invalid key id values");
+	} catch (IllegalArgumentException ex) {}
+
+	// test newPGPData(byte[], byte[], List)
+	pd = factory.newPGPData(valid_id, valid_packet, null);
+	assertTrue(Arrays.equals(valid_id, pd.getKeyId()));
+	assertTrue(Arrays.equals(valid_packet, pd.getKeyPacket()));
+	try {
+	    pd = factory.newPGPData(invalid_id, valid_packet, null);
+	    fail("Should throw IAE for invalid key id values");
+	} catch (IllegalArgumentException ex) {}
+	try {
+	    pd = factory.newPGPData(valid_id, invalid_packet, null);
+	    fail("Should throw IAE for invalid key packet values");
+	} catch (IllegalArgumentException ex) {}
+	try {
+	    pd = factory.newPGPData(invalid_id, invalid_packet, null);
+	    fail("Should throw IAE for invalid key id and packet values");
+	} catch (IllegalArgumentException ex) {}
+
+	// test newPGPData(byte[], List)
+	pd = factory.newPGPData(valid_packet, null);
+	assertTrue(Arrays.equals(valid_packet, pd.getKeyPacket()));
+	try {
+	    pd = factory.newPGPData(invalid_packet, null);
+	    fail("Should throw IAE for invalid key packet values");
+	} catch (IllegalArgumentException ex) {}
+    }
+
+    public void testnewRetrievalMethod() throws Exception {
+        final String uri = "#X509CertChain";
+        // test RetrievalMethod(String)
+        RetrievalMethod rm = factory.newRetrievalMethod(uri);
+	assertEquals(uri, rm.getURI());
+
+	try {
+	    rm = factory.newRetrievalMethod(null); 
+	    fail("Should raise a NPE for null URI"); 
+        } catch (NullPointerException npe) {}
+
+	// test RetrievalMethod(String, String, List)	
+	try {
+	    rm = factory.newRetrievalMethod(null, null, null); 
+	    fail("Should raise a NPE for null URI"); 
+        } catch (NullPointerException npe) {}
+	
+	String type = "http://www.w3.org/2000/09/xmldsig#X509Data";
+	try {
+	    rm = factory.newRetrievalMethod(null, type, null); 
+	    fail("Should raise a NPE for null URI"); 
+        } catch (NullPointerException npe) {}
+
+        rm = factory.newRetrievalMethod(uri, type, null);
+        assertEquals(uri, rm.getURI());
+        assertEquals(type, rm.getType());
+    }
+
+    public void testnewX509Data() {
+	// test newX509Data(List)
+	X509Data x509 = 
+	    factory.newX509Data(Collections.singletonList("cn=foo"));
+	assertNotNull(x509);
+    }
+
+    public void testnewX509IssuerSerial() {
+	String name = "CN=valeriep";
+	// test newX509IssuerSerial(String, BigInteger)
+	X509IssuerSerial x509is = factory.newX509IssuerSerial(name, 
+							      BigInteger.ONE);
+	assertEquals(name, x509is.getIssuerName());
+	assertEquals(BigInteger.ONE, x509is.getSerialNumber());
+	try {
+	    x509is = factory.newX509IssuerSerial(null, BigInteger.ZERO);
+	    fail("Should raise an NPE for null issuer names"); 
+	} catch (NullPointerException ex) {
+	} catch (IllegalArgumentException ex2) {
+	    fail("Should throw NPE instead of IAE for null issuer names");
+	}
+	try {
+	    x509is = factory.newX509IssuerSerial(name, null);
+	    fail("Should raise an NPE for null serial numbers"); 
+	} catch (NullPointerException ex) {
+	} catch (IllegalArgumentException ex2) {
+	    fail("Should throw NPE instead of IAE for null serial numbers");
+	}
+	try {
+	    x509is = factory.newX509IssuerSerial(null, null);
+	    fail("Should raise an NPE for null issuer names/serial numbers"); 
+	} catch (NullPointerException ex) {
+	} catch (IllegalArgumentException ex2) {
+	    fail("Should throw NPE instead of IAE for null issuer " + 
+		 "names/serial numbers");
+	}
+	try {
+	    x509is = factory.newX509IssuerSerial("valeriep", BigInteger.ZERO);
+	    fail("Should throw IAE for invalid issuer names"); 
+	} catch (IllegalArgumentException ex) {}
+    }
+
+    // for debugging purposes
+    public static void main(String[] args) throws Exception {
+	KeyInfoFactoryTest kifTest = 
+	    new KeyInfoFactoryTest("KeyInfoFactoryTest");
+	kifTest.setUp();
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig.keyinfo;
+
+import java.util.*;
+import javax.xml.crypto.*;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dom.*;
+import javax.xml.crypto.dsig.keyinfo.*;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.dsig.keyinfo.KeyInfo
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class KeyInfoTest extends TestCase {
+
+    private KeyInfoFactory fac;
+
+    public KeyInfoTest() {
+	super("KeyInfoTest");
+    }
+
+    public KeyInfoTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception { 
+	fac = KeyInfoFactory.getInstance
+	    ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+    }
+
+    public void tearDown() { }
+
+    public void testgetId() {
+	KeyInfo ki = fac.newKeyInfo
+	    (Collections.singletonList(fac.newKeyName("foo")), "skeleton");
+	assertNotNull(ki.getId());
+    }
+
+    public void testgetContent() {
+	KeyInfo[] infos = new KeyInfo[2];
+	infos[0] = fac.newKeyInfo
+	    (Collections.singletonList(fac.newKeyName("foo")), "skeleton");
+	infos[1] = fac.newKeyInfo
+	    (Collections.singletonList(fac.newKeyName("foo")));
+	for (int j=0; j < infos.length; j++) {
+	    KeyInfo ki = infos[j];
+	    List li = ki.getContent();
+	    assertNotNull(ki.getContent());
+	    if (!li.isEmpty()) {
+		Object[] content = li.toArray();
+		for (int i=0; i<content.length; i++) {
+		    if (!(content[i] instanceof XMLStructure)) {
+			fail("KeyInfo element has the wrong type");
+		    };
+		}
+	    } else {
+		try {
+		    li.add(new Object());
+		    fail("Added KeyInfo element of wrong type");
+		} catch (ClassCastException ex) {
+		    // expected
+		}
+	    }
+	}
+    }
+
+    public void testConstructor() {
+	final String id = "keyId";
+	// test newKeyInfo(List, String id)
+	KeyInfo ki = fac.newKeyInfo
+	    (Collections.singletonList(fac.newKeyName("foo")), id);
+	assertEquals(id, ki.getId());
+	try {
+	    ki = fac.newKeyInfo(null, id); 
+	    fail("Should raise a NullPointerException"); 
+	} catch (NullPointerException npe) {}
+	// test newKeyInfo(List)
+	ki = fac.newKeyInfo(Collections.singletonList(fac.newKeyName("foo")));
+    }
+
+    public void testisFeatureSupported() {
+	KeyInfo ki = fac.newKeyInfo
+	    (Collections.singletonList(fac.newKeyName("foo")), "keyid");
+	try {
+	    ki.isFeatureSupported(null); 
+	    fail("Should raise a NPE for null feature"); 
+	} catch (NullPointerException npe) {}
+
+	assertTrue(!ki.isFeatureSupported("not supported"));
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyNameTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyNameTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyNameTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyNameTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig.keyinfo;
+
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dom.*;
+import javax.xml.crypto.dsig.keyinfo.*;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Document;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.dsig.keyinfo.KeyName
+ *
+ * @version $Id$
+ * @author Sean Mullan
+ */
+public class KeyNameTest extends TestCase {
+
+    private KeyInfoFactory fac;
+
+    public KeyNameTest() {
+	super("KeyNameTest");
+    }
+
+    public KeyNameTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception { 
+	fac = KeyInfoFactory.getInstance
+	    ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+    }
+
+    public void tearDown() { }
+
+    public void testgetName() {
+	KeyName kn = fac.newKeyName("skeleton");
+	assertNotNull(kn.getName());
+    }
+
+    public void testConstructor() {
+	final String name = "keyName";
+	KeyName kn = fac.newKeyName(name);
+	assertEquals(name, kn.getName());
+	try {
+	    kn = fac.newKeyName(null); 
+	    fail("Should raise a NullPointerException"); 
+	} catch (NullPointerException npe) {}
+    }
+
+    public void testisFeatureSupported() {
+	KeyName kn = fac.newKeyName("keyName");
+	try {
+	    kn.isFeatureSupported(null); 
+	    fail("Should raise a NPE for null feature"); 
+	} catch (NullPointerException npe) {}
+
+	assertTrue(!kn.isFeatureSupported("not supported"));
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyValueTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyValueTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyValueTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyValueTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig.keyinfo;
+
+import java.io.*;
+import java.security.*;
+import java.security.interfaces.*;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dom.*;
+import javax.xml.crypto.dsig.keyinfo.*;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.dsig.keyinfo.KeyValue
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class KeyValueTest extends TestCase {
+
+    private static final String[] ALGOS = { "DSA", "RSA" };
+    private KeyInfoFactory fac;
+    private PublicKey keys[] = null;
+
+    public KeyValueTest() {
+	super("KeyValueTest");
+    }
+
+    public KeyValueTest(String name) {
+	super(name);
+    }
+
+    private PublicKey genPublicKey(String algo, int keysize) throws Exception {
+        KeyPairGenerator kpg = KeyPairGenerator.getInstance(algo);
+        kpg.initialize(keysize, new SecureRandom(("Not so random bytes" 
+	    + System.currentTimeMillis() ).getBytes() ));
+        KeyPair kp = kpg.generateKeyPair();
+        return kp.getPublic();
+    }
+
+    public void setUp() throws Exception { 
+	fac = KeyInfoFactory.getInstance
+	    ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+	// generate PublicKey(s) and XMLStructure(s) for DSA and RSA
+	keys = new PublicKey[ALGOS.length];
+
+	for (int i = 0; i<ALGOS.length; i++) {
+	    keys[i] = genPublicKey(ALGOS[i], 512);
+	}
+    }
+
+    public void tearDown() { }
+
+    public void testgetPublicKey() {
+	try {
+	    KeyValue kv = fac.newKeyValue(keys[0]);
+	    assertNotNull(kv.getPublicKey());
+        } catch (KeyException ke) {
+	    fail("Should pass instead of throwing KeyException");
+        }
+    }
+
+    public void testConstructor() {
+	// test newKeyValue(PublicKey pk)
+	for (int i = 0; i < keys.length; i++) {
+	    try {
+	        KeyValue kv = fac.newKeyValue(keys[i]);
+	        assertEquals(keys[i], kv.getPublicKey());
+	    } catch (KeyException ke) {
+		fail("Should pass instead of throwing KeyException");
+	    }
+	}
+    }
+
+    public void testisFeatureSupported() {
+	KeyValue kv = null;
+        try {
+	    kv = fac.newKeyValue(keys[0]);
+	    kv.isFeatureSupported(null); 
+	    fail("Should raise a NPE for null feature"); 
+        } catch (KeyException ke) {
+	    fail("Should raise a NPE for null feature"); 
+        } catch (NullPointerException npe) {}
+	    
+        assertTrue(!kv.isFeatureSupported("not supported"));
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/PGPDataTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/PGPDataTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/PGPDataTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/PGPDataTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig.keyinfo;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import javax.xml.crypto.*;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dom.*;
+import javax.xml.crypto.dsig.keyinfo.*;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.dsig.keyinfo.PGPData
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class PGPDataTest extends TestCase {
+
+    private KeyInfoFactory fac;
+    private byte[][] values = { 
+	{
+            0x01, 0x02, 0x03, 0x04,
+            0x05, 0x06, 0x07, 0x08
+	},
+	{
+	    (byte)0xc6, (byte)0x01, (byte)0x00
+	}
+    };
+
+    public PGPDataTest() {
+	super("PGPDataTest");
+    }
+
+    public PGPDataTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception { 
+	fac = KeyInfoFactory.getInstance
+	    ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+    }
+
+    public void tearDown() { }
+
+    public void testgetExternalElements() {
+	PGPData[] pds = {
+	    fac.newPGPData(values[0]),
+	    fac.newPGPData(values[0], values[1], null),
+	    fac.newPGPData(values[1], null)
+	};
+	for (int i=0; i<pds.length; i++) {
+	    List li = pds[i].getExternalElements();
+	    assertNotNull(li);
+	    if (!li.isEmpty()) {
+		Object[] types = li.toArray();
+		for (int j=0; j<types.length; j++) {
+		    if (!(types[j] instanceof XMLStructure)) {
+			fail("PGP element has the wrong type");
+		    };
+		}
+	    } 
+        }
+	try {
+	    PGPData pd = fac.newPGPData
+		(values[0], Collections.singletonList(new Object()));
+	    fail("Added PGP element of wrong type");
+	} catch (ClassCastException ex) {
+	    // expected
+	}
+    }
+
+    public void testgetKeyId() {
+	PGPData pd = fac.newPGPData(values[0]);
+	assertNotNull(pd.getKeyId());
+	pd = fac.newPGPData(values[0], values[1], null);
+	assertNotNull(pd.getKeyId());
+	pd = fac.newPGPData(values[1], null);
+    }
+
+    public void testgetKeyPacket() {
+	PGPData pd = fac.newPGPData(values[0]);
+	pd = fac.newPGPData(values[0], values[1], null);
+	assertNotNull(pd.getKeyPacket());
+        pd = fac.newPGPData(values[1], null);
+	assertNotNull(pd.getKeyPacket());
+    }
+
+    public void testConstructor() {
+	// test newPGPKeyData(byte[])
+	PGPData pd = fac.newPGPData(values[0]);
+	assertTrue(Arrays.equals(values[0], pd.getKeyId()));
+
+	// test newPGPData(byte[], byte[], List)
+	pd = fac.newPGPData(values[0], values[1], null);
+	assertTrue(Arrays.equals(values[0], pd.getKeyId()));
+	assertTrue(Arrays.equals(values[1], pd.getKeyPacket()));
+	    
+	// test newPGPData(byte[], List)
+	pd = fac.newPGPData(values[1], null);
+	assertTrue(Arrays.equals(values[1], pd.getKeyPacket()));
+    }
+
+    public void testisFeatureSupported() {
+	PGPData pd = null;
+	for (int i=0; i<3; i++) {
+	    switch (i) {
+	    case 0:
+		pd = fac.newPGPData(values[0]);
+		break;
+	    case 1:
+		pd = fac.newPGPData(values[0], values[1], null);
+		break;
+	    case 2:
+		pd = fac.newPGPData(values[1], null);
+	    }
+	    try {
+		pd.isFeatureSupported(null); 
+		fail("Should raise a NPE for null feature"); 
+	    } catch (NullPointerException npe) {}
+	    
+	    assertTrue(!pd.isFeatureSupported("not supported"));
+	}
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/RetrievalMethodTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/RetrievalMethodTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/RetrievalMethodTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/RetrievalMethodTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig.keyinfo;
+
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dom.*;
+import javax.xml.crypto.dsig.keyinfo.*;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.dsig.keyinfo.RetrievalMethod
+ *
+ * @version $Id$
+ * @author Sean Mullan
+ */
+public class RetrievalMethodTest extends TestCase {
+
+    private KeyInfoFactory fac;
+
+    public RetrievalMethodTest() {
+	super("RetrievalMethodTest");
+    }
+
+    public RetrievalMethodTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception { 
+	fac = KeyInfoFactory.getInstance
+	    ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+    }
+
+    public void tearDown() { }
+
+    public void testgetURI() {
+        RetrievalMethod rm = fac.newRetrievalMethod("#X509Data");
+        assertNotNull(rm.getURI());
+    }
+
+    public void testgetTransforms() {
+        RetrievalMethod rm = fac.newRetrievalMethod("#X509Data");
+        assertNotNull(rm.getTransforms());
+    }
+
+    public void testgetType() {
+        RetrievalMethod rm = fac.newRetrievalMethod("#X509Data");
+        assertNull(rm.getType());
+    }
+
+    public void testConstructors() {
+        final String uri = "#X509CertChain";
+        // test RetrievalMethod(String)
+        RetrievalMethod rm = fac.newRetrievalMethod(uri);
+        assertEquals(uri, rm.getURI());
+
+	try {
+	    rm = fac.newRetrievalMethod(null); 
+	    fail("Should raise a NullPointerException"); 
+        } catch (NullPointerException npe) {}
+
+	// test RetrievalMethod(String, String, Transform[])
+	try {
+	    rm = fac.newRetrievalMethod(null, null, null); 
+	    fail("Should raise a NullPointerException"); 
+        } catch (NullPointerException npe) {}
+
+        final String type = "http://www.w3.org/2000/09/xmldsig#X509Data";
+        rm = fac.newRetrievalMethod(uri, type, null);
+        assertEquals(uri, rm.getURI());
+        assertEquals(type, rm.getType());
+    }
+
+    public void testisFeatureSupported() throws Exception {
+	String uri = "#X509CertChain";
+        String type = "http://www.w3.org/2000/09/xmldsig#X509Data";
+	RetrievalMethod rm = null;
+	for (int i=0; i<2; i++) {
+	    switch (i) {
+	    case 0:
+		rm = fac.newRetrievalMethod(uri);
+		break;
+	    case 1:
+		rm = fac.newRetrievalMethod(uri, type, null);
+		break;
+	    }		
+	    try {
+		rm.isFeatureSupported(null); 
+		fail("Should raise a NPE for null feature"); 
+	    } catch (NullPointerException npe) {}
+	    
+	    assertTrue(!rm.isFeatureSupported("not supported"));
+	}
+    }
+}