2 * Copyright 2001-2006 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * Implementation classes for XML Encryption schema
24 #include "AbstractChildlessElement.h"
25 #include "AbstractComplexElement.h"
26 #include "AbstractSimpleElement.h"
27 #include "exceptions.h"
28 #include "encryption/Encryption.h"
29 #include "io/AbstractXMLObjectMarshaller.h"
30 #include "io/AbstractXMLObjectUnmarshaller.h"
31 #include "util/XMLHelper.h"
32 #include "validation/AbstractValidatingXMLObject.h"
34 #include <xercesc/util/XMLUniDefs.hpp>
36 using namespace xmlencryption;
37 using namespace xmltooling;
40 #if defined (_MSC_VER)
41 #pragma warning( push )
42 #pragma warning( disable : 4250 4251 )
45 namespace xmlencryption {
47 DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,KeySize);
48 DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,OAEPparams);
50 class XMLTOOL_DLLLOCAL EncryptionMethodImpl : public virtual EncryptionMethod,
51 public AbstractComplexElement,
52 public AbstractDOMCachingXMLObject,
53 public AbstractValidatingXMLObject,
54 public AbstractXMLObjectMarshaller,
55 public AbstractXMLObjectUnmarshaller
61 m_children.push_back(NULL);
62 m_children.push_back(NULL);
63 m_pos_KeySize=m_children.begin();
64 m_pos_OAEPparams=m_pos_KeySize;
68 virtual ~EncryptionMethodImpl() {
69 XMLString::release(&m_Algorithm);
72 EncryptionMethodImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
73 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
77 EncryptionMethodImpl(const EncryptionMethodImpl& src)
78 : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), AbstractValidatingXMLObject(src) {
80 setAlgorithm(src.getAlgorithm());
82 setKeySize(src.getKeySize()->cloneKeySize());
83 if (src.getOAEPparams())
84 setOAEPparams(src.getOAEPparams()->cloneOAEPparams());
85 VectorOf(XMLObject) v=getOtherParameters();
86 for (vector<XMLObject*>::const_iterator i=src.m_OtherParameters.begin(); i!=src.m_OtherParameters.end(); i++) {
88 v.push_back((*i)->clone());
93 IMPL_XMLOBJECT_CLONE(EncryptionMethod);
94 IMPL_STRING_ATTRIB(Algorithm);
95 IMPL_TYPED_CHILD(KeySize);
96 IMPL_TYPED_CHILD(OAEPparams);
97 IMPL_XMLOBJECT_CHILDREN(OtherParameter,m_children.end());
100 void marshallAttributes(DOMElement* domElement) const {
101 MARSHALL_STRING_ATTRIB(Algorithm,ALGORITHM,NULL);
104 void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
105 PROC_TYPED_CHILD(KeySize,XMLConstants::XMLENC_NS,false);
106 PROC_TYPED_CHILD(OAEPparams,XMLConstants::XMLENC_NS,false);
109 const XMLCh* nsURI=root->getNamespaceURI();
110 if (!XMLString::equals(nsURI,XMLConstants::XMLENC_NS) && nsURI && *nsURI)
111 getOtherParameters().push_back(childXMLObject);
113 AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
116 void processAttribute(const DOMAttr* attribute) {
117 PROC_STRING_ATTRIB(Algorithm,ALGORITHM,NULL);
123 #if defined (_MSC_VER)
124 #pragma warning( pop )
127 // Builder Implementations
129 IMPL_XMLOBJECTBUILDER(KeySize);
130 IMPL_XMLOBJECTBUILDER(OAEPparams);
131 IMPL_XMLOBJECTBUILDER(EncryptionMethod);
135 const XMLCh KeySize::LOCAL_NAME[] = UNICODE_LITERAL_7(K,e,y,S,i,z,e);
136 const XMLCh OAEPparams::LOCAL_NAME[] = UNICODE_LITERAL_10(O,A,E,P,p,a,r,a,m,s);
137 const XMLCh EncryptionMethod::LOCAL_NAME[] = UNICODE_LITERAL_16(E,n,c,r,y,p,t,i,o,n,M,e,t,h,o,d);
138 const XMLCh EncryptionMethod::TYPE_NAME[] = UNICODE_LITERAL_20(E,n,c,r,y,p,t,i,o,n,M,e,t,h,o,d,T,y,p,e);
139 const XMLCh EncryptionMethod::ALGORITHM_ATTRIB_NAME[] = UNICODE_LITERAL_9(A,l,g,o,r,i,t,h,m);