|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
package com.sun.org.apache.xml.internal.security.keys.content; |
|
|
|
import java.security.PublicKey; |
|
|
|
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; |
|
import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.DSAKeyValue; |
|
import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.ECKeyValue; |
|
import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.RSAKeyValue; |
|
import com.sun.org.apache.xml.internal.security.utils.Constants; |
|
import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; |
|
import com.sun.org.apache.xml.internal.security.utils.XMLUtils; |
|
import org.w3c.dom.Document; |
|
import org.w3c.dom.Element; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public class KeyValue extends SignatureElementProxy implements KeyInfoContent { |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public KeyValue(Document doc, DSAKeyValue dsaKeyValue) { |
|
super(doc); |
|
|
|
addReturnToSelf(); |
|
appendSelf(dsaKeyValue); |
|
addReturnToSelf(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public KeyValue(Document doc, RSAKeyValue rsaKeyValue) { |
|
super(doc); |
|
|
|
addReturnToSelf(); |
|
appendSelf(rsaKeyValue); |
|
addReturnToSelf(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public KeyValue(Document doc, Element unknownKeyValue) { |
|
super(doc); |
|
|
|
addReturnToSelf(); |
|
appendSelf(unknownKeyValue); |
|
addReturnToSelf(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public KeyValue(Document doc, PublicKey pk) { |
|
super(doc); |
|
|
|
addReturnToSelf(); |
|
|
|
if (pk instanceof java.security.interfaces.DSAPublicKey) { |
|
DSAKeyValue dsa = new DSAKeyValue(getDocument(), pk); |
|
|
|
appendSelf(dsa); |
|
addReturnToSelf(); |
|
} else if (pk instanceof java.security.interfaces.RSAPublicKey) { |
|
RSAKeyValue rsa = new RSAKeyValue(getDocument(), pk); |
|
|
|
appendSelf(rsa); |
|
addReturnToSelf(); |
|
} else if (pk instanceof java.security.interfaces.ECPublicKey) { |
|
ECKeyValue ec = new ECKeyValue(getDocument(), pk); |
|
|
|
appendSelf(ec); |
|
addReturnToSelf(); |
|
} else { |
|
String error = "The given PublicKey type " + pk + " is not supported. Only DSAPublicKey and " |
|
+ "RSAPublicKey and ECPublicKey types are currently supported"; |
|
throw new IllegalArgumentException(error); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public KeyValue(Element element, String baseURI) throws XMLSecurityException { |
|
super(element, baseURI); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public PublicKey getPublicKey() throws XMLSecurityException { |
|
Element rsa = |
|
XMLUtils.selectDsNode( |
|
getFirstChild(), Constants._TAG_RSAKEYVALUE, 0); |
|
|
|
if (rsa != null) { |
|
RSAKeyValue kv = new RSAKeyValue(rsa, this.baseURI); |
|
return kv.getPublicKey(); |
|
} |
|
|
|
Element dsa = |
|
XMLUtils.selectDsNode( |
|
getFirstChild(), Constants._TAG_DSAKEYVALUE, 0); |
|
|
|
if (dsa != null) { |
|
DSAKeyValue kv = new DSAKeyValue(dsa, this.baseURI); |
|
return kv.getPublicKey(); |
|
} |
|
|
|
return null; |
|
} |
|
|
|
|
|
public String getBaseLocalName() { |
|
return Constants._TAG_KEYVALUE; |
|
} |
|
} |