0N/A/*
0N/A * reserved comment block
0N/A * DO NOT REMOVE OR ALTER!
0N/A */
0N/A/*
0N/A * Copyright 1999-2004 The Apache Software Foundation.
0N/A *
0N/A * Licensed under the Apache License, Version 2.0 (the "License");
0N/A * you may not use this file except in compliance with the License.
0N/A * You may obtain a copy of the License at
0N/A *
0N/A * http://www.apache.org/licenses/LICENSE-2.0
0N/A *
0N/A * Unless required by applicable law or agreed to in writing, software
0N/A * distributed under the License is distributed on an "AS IS" BASIS,
0N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0N/A * See the License for the specific language governing permissions and
0N/A * limitations under the License.
0N/A *
0N/A */
0N/Apackage com.sun.org.apache.xml.internal.security.keys.content;
0N/A
0N/Aimport java.security.PublicKey;
0N/A
0N/Aimport com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
0N/Aimport com.sun.org.apache.xml.internal.security.keys.content.keyvalues.DSAKeyValue;
0N/Aimport com.sun.org.apache.xml.internal.security.keys.content.keyvalues.RSAKeyValue;
0N/Aimport com.sun.org.apache.xml.internal.security.utils.Constants;
0N/Aimport com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
0N/Aimport com.sun.org.apache.xml.internal.security.utils.XMLUtils;
0N/Aimport org.w3c.dom.Document;
0N/Aimport org.w3c.dom.Element;
0N/A
0N/A/**
0N/A * The KeyValue element contains a single public key that may be useful in
0N/A * validating the signature. Structured formats for defining DSA (REQUIRED)
0N/A * and RSA (RECOMMENDED) public keys are defined in Signature Algorithms
0N/A * (section 6.4). The KeyValue element may include externally defined public
661N/A * keys values represented as PCDATA or element types from an external
661N/A * namespace.
0N/A *
661N/A * @author $Author: mullan $
0N/A */
0N/Apublic class KeyValue extends SignatureElementProxy implements KeyInfoContent {
0N/A
661N/A /**
661N/A * Constructor KeyValue
661N/A *
661N/A * @param doc
661N/A * @param dsaKeyValue
661N/A */
661N/A public KeyValue(Document doc, DSAKeyValue dsaKeyValue) {
0N/A
661N/A super(doc);
0N/A
661N/A XMLUtils.addReturnToElement(this._constructionElement);
661N/A this._constructionElement.appendChild(dsaKeyValue.getElement());
661N/A XMLUtils.addReturnToElement(this._constructionElement);
661N/A }
0N/A
661N/A /**
661N/A * Constructor KeyValue
661N/A *
661N/A * @param doc
661N/A * @param rsaKeyValue
661N/A */
661N/A public KeyValue(Document doc, RSAKeyValue rsaKeyValue) {
0N/A
661N/A super(doc);
0N/A
661N/A XMLUtils.addReturnToElement(this._constructionElement);
661N/A this._constructionElement.appendChild(rsaKeyValue.getElement());
661N/A XMLUtils.addReturnToElement(this._constructionElement);
661N/A }
0N/A
661N/A /**
661N/A * Constructor KeyValue
661N/A *
661N/A * @param doc
661N/A * @param unknownKeyValue
661N/A */
661N/A public KeyValue(Document doc, Element unknownKeyValue) {
0N/A
661N/A super(doc);
0N/A
661N/A XMLUtils.addReturnToElement(this._constructionElement);
661N/A this._constructionElement.appendChild(unknownKeyValue);
661N/A XMLUtils.addReturnToElement(this._constructionElement);
661N/A }
0N/A
661N/A /**
661N/A * Constructor KeyValue
661N/A *
661N/A * @param doc
661N/A * @param pk
661N/A */
661N/A public KeyValue(Document doc, PublicKey pk) {
0N/A
661N/A super(doc);
0N/A
661N/A XMLUtils.addReturnToElement(this._constructionElement);
0N/A
661N/A if (pk instanceof java.security.interfaces.DSAPublicKey) {
661N/A DSAKeyValue dsa = new DSAKeyValue(this._doc, pk);
0N/A
661N/A this._constructionElement.appendChild(dsa.getElement());
661N/A XMLUtils.addReturnToElement(this._constructionElement);
661N/A } else if (pk instanceof java.security.interfaces.RSAPublicKey) {
661N/A RSAKeyValue rsa = new RSAKeyValue(this._doc, pk);
0N/A
661N/A this._constructionElement.appendChild(rsa.getElement());
661N/A XMLUtils.addReturnToElement(this._constructionElement);
661N/A }
661N/A }
0N/A
661N/A /**
661N/A * Constructor KeyValue
661N/A *
661N/A * @param element
661N/A * @param BaseURI
661N/A * @throws XMLSecurityException
661N/A */
661N/A public KeyValue(Element element, String BaseURI)
0N/A throws XMLSecurityException {
661N/A super(element, BaseURI);
661N/A }
0N/A
661N/A /**
661N/A * Method getPublicKey
661N/A *
661N/A * @return the public key
661N/A * @throws XMLSecurityException
661N/A */
661N/A public PublicKey getPublicKey() throws XMLSecurityException {
0N/A
661N/A Element rsa = XMLUtils.selectDsNode
661N/A (this._constructionElement.getFirstChild(),
661N/A Constants._TAG_RSAKEYVALUE,0);
0N/A
661N/A if (rsa != null) {
661N/A RSAKeyValue kv = new RSAKeyValue(rsa, this._baseURI);
0N/A return kv.getPublicKey();
661N/A }
0N/A
661N/A Element dsa = XMLUtils.selectDsNode
661N/A (this._constructionElement.getFirstChild(),
661N/A Constants._TAG_DSAKEYVALUE,0);
0N/A
661N/A if (dsa != null) {
661N/A DSAKeyValue kv = new DSAKeyValue(dsa, this._baseURI);
0N/A return kv.getPublicKey();
661N/A }
0N/A
661N/A return null;
661N/A }
0N/A
661N/A /** @inheritDoc */
661N/A public String getBaseLocalName() {
661N/A return Constants._TAG_KEYVALUE;
661N/A }
0N/A}