Wrapped encryption schema, also block unknown attributes and handle schemaLocation.
[shibboleth/cpp-xmltooling.git] / xmltooling / encryption / impl / EncryptionImpl.cpp
1 /*
2  *  Copyright 2001-2006 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * EncryptionImpl.cpp
19  * 
20  * Implementation classes for XML Encryption schema
21  */
22
23 #include "internal.h"
24 #include "AbstractAttributeExtensibleXMLObject.h"
25 #include "AbstractChildlessElement.h"
26 #include "AbstractElementProxy.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"
33
34 #include <xercesc/util/XMLUniDefs.hpp>
35
36 using namespace xmlencryption;
37 using namespace xmltooling;
38 using namespace std;
39
40 #if defined (_MSC_VER)
41     #pragma warning( push )
42     #pragma warning( disable : 4250 4251 )
43 #endif
44
45 namespace xmlencryption {
46
47     DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,CarriedKeyName);
48     DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,CipherValue);
49     DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,KeySize);
50     DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,OAEPparams);
51
52     class XMLTOOL_DLLLOCAL EncryptionMethodImpl : public virtual EncryptionMethod,
53         public AbstractComplexElement,
54         public AbstractDOMCachingXMLObject,
55         public AbstractValidatingXMLObject,
56         public AbstractXMLObjectMarshaller,
57         public AbstractXMLObjectUnmarshaller
58     {
59         void init() {
60             m_Algorithm=NULL;
61             m_KeySize=NULL;
62             m_OAEPparams=NULL;
63             m_children.push_back(NULL);
64             m_children.push_back(NULL);
65             m_pos_KeySize=m_children.begin();
66             m_pos_OAEPparams=m_pos_KeySize;
67             ++m_pos_OAEPparams;
68         }
69     public:
70         virtual ~EncryptionMethodImpl() {
71             XMLString::release(&m_Algorithm);
72         }
73
74         EncryptionMethodImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
75                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
76             init();
77         }
78             
79         EncryptionMethodImpl(const EncryptionMethodImpl& src)
80                 : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), AbstractValidatingXMLObject(src) {
81             init();
82             setAlgorithm(src.getAlgorithm());
83             if (src.getKeySize())
84                 setKeySize(src.getKeySize()->cloneKeySize());
85             if (src.getOAEPparams())
86                 setOAEPparams(src.getOAEPparams()->cloneOAEPparams());
87             VectorOf(XMLObject) v=getOtherParameters();
88             for (vector<XMLObject*>::const_iterator i=src.m_OtherParameters.begin(); i!=src.m_OtherParameters.end(); i++) {
89                 if (*i) {
90                     v.push_back((*i)->clone());
91                 }
92             }
93         }
94         
95         IMPL_XMLOBJECT_CLONE(EncryptionMethod);
96         IMPL_STRING_ATTRIB(Algorithm);
97         IMPL_TYPED_CHILD(KeySize);
98         IMPL_TYPED_CHILD(OAEPparams);
99         IMPL_XMLOBJECT_CHILDREN(OtherParameter,m_children.end());
100
101     protected:
102         void marshallAttributes(DOMElement* domElement) const {
103             MARSHALL_STRING_ATTRIB(Algorithm,ALGORITHM,NULL);
104         }
105
106         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
107             PROC_TYPED_CHILD(KeySize,XMLConstants::XMLENC_NS,false);
108             PROC_TYPED_CHILD(OAEPparams,XMLConstants::XMLENC_NS,false);
109             
110             // Unknown child.
111             const XMLCh* nsURI=root->getNamespaceURI();
112             if (!XMLString::equals(nsURI,XMLConstants::XMLENC_NS) && nsURI && *nsURI)
113                 getOtherParameters().push_back(childXMLObject);
114             
115             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
116         }
117
118         void processAttribute(const DOMAttr* attribute) {
119             PROC_STRING_ATTRIB(Algorithm,ALGORITHM,NULL);
120             AbstractXMLObjectUnmarshaller::processAttribute(attribute);
121         }
122     };
123
124     class XMLTOOL_DLLLOCAL TransformsImpl : public virtual Transforms,
125         public AbstractComplexElement,
126         public AbstractDOMCachingXMLObject,
127         public AbstractValidatingXMLObject,
128         public AbstractXMLObjectMarshaller,
129         public AbstractXMLObjectUnmarshaller
130     {
131     public:
132         virtual ~TransformsImpl() {}
133
134         TransformsImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
135             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
136         }
137             
138         TransformsImpl(const TransformsImpl& src)
139                 : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), AbstractValidatingXMLObject(src) {
140             VectorOf(xmlsignature::Transform) v=getTransforms();
141             for (vector<xmlsignature::Transform*>::const_iterator i=src.m_Transforms.begin(); i!=src.m_Transforms.end(); i++) {
142                 if (*i) {
143                     v.push_back((*i)->cloneTransform());
144                 }
145             }
146         }
147         
148         IMPL_XMLOBJECT_CLONE(Transforms);
149         IMPL_TYPED_FOREIGN_CHILDREN(Transform,xmlsignature,m_children.end());
150
151     protected:
152         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
153             PROC_TYPED_FOREIGN_CHILDREN(Transform,xmlsignature,XMLConstants::XMLSIG_NS,false);
154             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
155         }
156     };
157
158     class XMLTOOL_DLLLOCAL CipherReferenceImpl : public virtual CipherReference,
159         public AbstractComplexElement,
160         public AbstractDOMCachingXMLObject,
161         public AbstractValidatingXMLObject,
162         public AbstractXMLObjectMarshaller,
163         public AbstractXMLObjectUnmarshaller
164     {
165         void init() {
166             m_URI=NULL;
167             m_Transforms=NULL;
168             m_children.push_back(NULL);
169             m_pos_Transforms=m_children.begin();
170         }
171     public:
172         virtual ~CipherReferenceImpl() {
173             XMLString::release(&m_URI);
174         }
175
176         CipherReferenceImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
177                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
178             init();
179         }
180             
181         CipherReferenceImpl(const CipherReferenceImpl& src)
182                 : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), AbstractValidatingXMLObject(src) {
183             init();
184             setURI(src.getURI());
185             if (src.getTransforms())
186                 setTransforms(src.getTransforms()->cloneTransforms());
187         }
188         
189         IMPL_XMLOBJECT_CLONE(CipherReference);
190         IMPL_STRING_ATTRIB(URI);
191         IMPL_TYPED_CHILD(Transforms);
192
193     protected:
194         void marshallAttributes(DOMElement* domElement) const {
195             MARSHALL_STRING_ATTRIB(URI,URI,NULL);
196         }
197
198         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
199             PROC_TYPED_CHILD(Transforms,XMLConstants::XMLENC_NS,false);
200             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
201         }
202
203         void processAttribute(const DOMAttr* attribute) {
204             PROC_STRING_ATTRIB(URI,URI,NULL);
205             AbstractXMLObjectUnmarshaller::processAttribute(attribute);
206         }
207     };
208
209     class XMLTOOL_DLLLOCAL CipherDataImpl : public virtual CipherData,
210         public AbstractComplexElement,
211         public AbstractDOMCachingXMLObject,
212         public AbstractValidatingXMLObject,
213         public AbstractXMLObjectMarshaller,
214         public AbstractXMLObjectUnmarshaller
215     {
216         void init() {
217             m_CipherValue=NULL;
218             m_CipherReference=NULL;
219             m_children.push_back(NULL);
220             m_children.push_back(NULL);
221             m_pos_CipherValue=m_children.begin();
222             m_pos_CipherReference=m_pos_CipherValue;
223             ++m_pos_CipherReference;
224         }
225     public:
226         virtual ~CipherDataImpl() {}
227
228         CipherDataImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
229                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
230             init();
231         }
232             
233         CipherDataImpl(const CipherDataImpl& src)
234                 : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), AbstractValidatingXMLObject(src) {
235             init();
236             if (src.getCipherValue())
237                 setCipherValue(src.getCipherValue()->cloneCipherValue());
238             if (src.getCipherReference())
239                 setCipherReference(src.getCipherReference()->cloneCipherReference());
240         }
241         
242         IMPL_XMLOBJECT_CLONE(CipherData);
243         IMPL_TYPED_CHILD(CipherValue);
244         IMPL_TYPED_CHILD(CipherReference);
245
246     protected:
247         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
248             PROC_TYPED_CHILD(CipherValue,XMLConstants::XMLENC_NS,false);
249             PROC_TYPED_CHILD(CipherReference,XMLConstants::XMLENC_NS,false);
250             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
251         }
252     };
253
254     class XMLTOOL_DLLLOCAL EncryptionPropertyImpl : public virtual EncryptionProperty,
255         public AbstractElementProxy,
256         public AbstractAttributeExtensibleXMLObject,
257         public AbstractDOMCachingXMLObject,
258         public AbstractValidatingXMLObject,
259         public AbstractXMLObjectMarshaller,
260         public AbstractXMLObjectUnmarshaller
261     {
262         void init() {
263             m_Id=m_Target=NULL;
264         }
265     public:
266         virtual ~EncryptionPropertyImpl() {
267             XMLString::release(&m_Id);
268             XMLString::release(&m_Target);
269         }
270
271         EncryptionPropertyImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
272             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
273             init();
274         }
275             
276         EncryptionPropertyImpl(const EncryptionPropertyImpl& src)
277                 : AbstractXMLObject(src),
278                     AbstractElementProxy(src),
279                     AbstractAttributeExtensibleXMLObject(src),
280                     AbstractDOMCachingXMLObject(src),
281                     AbstractValidatingXMLObject(src) {
282             init();
283             setId(src.getId());
284             setTarget(src.getTarget());
285             for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
286                 if (*i) {
287                     getXMLObjects().push_back((*i)->clone());
288                 }
289             }
290         }
291         
292         IMPL_XMLOBJECT_CLONE(EncryptionProperty);
293         IMPL_STRING_ATTRIB(Id);
294         IMPL_STRING_ATTRIB(Target);
295
296         void setAttribute(QName& qualifiedName, const XMLCh* value) {
297             if (!qualifiedName.hasNamespaceURI()) {
298                 if (XMLString::equals(qualifiedName.getLocalPart(),ID_ATTRIB_NAME))
299                     setId(value);
300                 else if (XMLString::equals(qualifiedName.getLocalPart(),TARGET_ATTRIB_NAME))
301                     setTarget(value);
302             }
303             AbstractAttributeExtensibleXMLObject::setAttribute(qualifiedName, value);
304         }
305
306     protected:
307         void marshallAttributes(DOMElement* domElement) const {
308             MARSHALL_ID_ATTRIB(Id,ID,NULL);
309             MARSHALL_STRING_ATTRIB(Target,TARGET,NULL);
310
311             // Take care of wildcard.
312             for (map<QName,XMLCh*>::const_iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) {
313                 DOMAttr* attr=domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(),i->first.getLocalPart());
314                 if (i->first.hasPrefix())
315                     attr->setPrefix(i->first.getPrefix());
316                 attr->setNodeValue(i->second);
317                 domElement->setAttributeNode(attr);
318             }
319         }
320
321         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
322             getXMLObjects().push_back(childXMLObject);
323         }
324
325         void processAttribute(const DOMAttr* attribute) {
326             PROC_ID_ATTRIB(Id,ID,NULL);
327             QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix()); 
328             setAttribute(q,attribute->getNodeValue());
329         }
330     };
331
332     class XMLTOOL_DLLLOCAL EncryptionPropertiesImpl : public virtual EncryptionProperties,
333         public AbstractComplexElement,
334         public AbstractDOMCachingXMLObject,
335         public AbstractValidatingXMLObject,
336         public AbstractXMLObjectMarshaller,
337         public AbstractXMLObjectUnmarshaller
338     {
339         void init() {
340             m_Id=NULL;
341         }
342     public:
343         virtual ~EncryptionPropertiesImpl() {
344             XMLString::release(&m_Id);
345         }
346
347         EncryptionPropertiesImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
348             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
349             init();
350         }
351             
352         EncryptionPropertiesImpl(const EncryptionPropertiesImpl& src)
353                 : AbstractXMLObject(src),
354                     AbstractDOMCachingXMLObject(src),
355                     AbstractValidatingXMLObject(src) {
356             init();
357             setId(src.getId());
358             VectorOf(EncryptionProperty) v=getEncryptionPropertys();
359             for (vector<EncryptionProperty*>::const_iterator i=src.m_EncryptionPropertys.begin(); i!=src.m_EncryptionPropertys.end(); i++) {
360                 if (*i) {
361                     v.push_back((*i)->cloneEncryptionProperty());
362                 }
363             }
364         }
365         
366         IMPL_XMLOBJECT_CLONE(EncryptionProperties);
367         IMPL_STRING_ATTRIB(Id);
368         IMPL_TYPED_CHILDREN(EncryptionProperty,m_children.end());
369
370     protected:
371         void marshallAttributes(DOMElement* domElement) const {
372             MARSHALL_ID_ATTRIB(Id,ID,NULL);
373         }
374
375         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
376             PROC_TYPED_CHILDREN(EncryptionProperty,XMLConstants::XMLENC_NS,false);
377             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
378         }
379
380         void processAttribute(const DOMAttr* attribute) {
381             PROC_ID_ATTRIB(Id,ID,NULL);
382             AbstractXMLObjectUnmarshaller::processAttribute(attribute);
383         }
384     };
385
386     class XMLTOOL_DLLLOCAL ReferenceTypeImpl : public virtual ReferenceType,
387         public AbstractElementProxy,
388         public AbstractDOMCachingXMLObject,
389         public AbstractValidatingXMLObject,
390         public AbstractXMLObjectMarshaller,
391         public AbstractXMLObjectUnmarshaller
392     {
393         void init() {
394             m_URI=NULL;
395         }
396         
397     protected:
398         ReferenceTypeImpl() {
399             init();
400         }
401         
402     public:
403         virtual ~ReferenceTypeImpl() {
404             XMLString::release(&m_URI);
405         }
406
407         ReferenceTypeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
408             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
409             init();
410         }
411             
412         ReferenceTypeImpl(const ReferenceTypeImpl& src)
413                 : AbstractXMLObject(src),
414                     AbstractElementProxy(src),
415                     AbstractDOMCachingXMLObject(src),
416                     AbstractValidatingXMLObject(src) {
417             init();
418             setURI(src.getURI());
419             for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
420                 if (*i) {
421                     getXMLObjects().push_back((*i)->clone());
422                 }
423             }
424         }
425         
426         IMPL_XMLOBJECT_CLONE(ReferenceType);
427         IMPL_STRING_ATTRIB(URI);
428
429     protected:
430         void marshallAttributes(DOMElement* domElement) const {
431             MARSHALL_STRING_ATTRIB(URI,URI,NULL);
432         }
433
434         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
435             getXMLObjects().push_back(childXMLObject);
436         }
437
438         void processAttribute(const DOMAttr* attribute) {
439             PROC_STRING_ATTRIB(URI,URI,NULL);
440             AbstractXMLObjectUnmarshaller::processAttribute(attribute);
441         }
442     };
443
444     class XMLTOOL_DLLLOCAL DataReferenceImpl : public virtual DataReference, public ReferenceTypeImpl
445     {
446     public:
447         virtual ~DataReferenceImpl() {}
448
449         DataReferenceImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
450             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {}
451             
452         DataReferenceImpl(const DataReferenceImpl& src) : AbstractXMLObject(src), ReferenceTypeImpl(src) {}
453         
454         IMPL_XMLOBJECT_CLONE(DataReference);
455         ReferenceType* cloneReferenceType() const {
456             return new DataReferenceImpl(*this);
457         }
458     };
459
460     class XMLTOOL_DLLLOCAL KeyReferenceImpl : public virtual KeyReference, public ReferenceTypeImpl
461     {
462     public:
463         virtual ~KeyReferenceImpl() {}
464
465         KeyReferenceImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
466             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {}
467             
468         KeyReferenceImpl(const KeyReferenceImpl& src) : AbstractXMLObject(src), ReferenceTypeImpl(src) {}
469         
470         IMPL_XMLOBJECT_CLONE(KeyReference);
471         ReferenceType* cloneReferenceType() const {
472             return new KeyReferenceImpl(*this);
473         }
474     };
475
476     class XMLTOOL_DLLLOCAL ReferenceListImpl : public virtual ReferenceList,
477         public AbstractComplexElement,
478         public AbstractDOMCachingXMLObject,
479         public AbstractValidatingXMLObject,
480         public AbstractXMLObjectMarshaller,
481         public AbstractXMLObjectUnmarshaller
482     {
483     public:
484         virtual ~ReferenceListImpl() {}
485
486         ReferenceListImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
487             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
488         }
489             
490         ReferenceListImpl(const ReferenceListImpl& src)
491                 : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), AbstractValidatingXMLObject(src) {
492             for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
493                 if (*i) {
494                     DataReference* data=dynamic_cast<DataReference*>(*i);
495                     if (data) {
496                         getDataReferences().push_back(data->cloneDataReference());
497                         continue;
498                     }
499
500                     KeyReference* key=dynamic_cast<KeyReference*>(*i);
501                     if (key) {
502                         getKeyReferences().push_back(key->cloneKeyReference());
503                         continue;
504                     }
505                 }
506             }
507         }
508         
509         IMPL_XMLOBJECT_CLONE(ReferenceList);
510         IMPL_TYPED_CHILDREN(DataReference,m_children.end());
511         IMPL_TYPED_CHILDREN(KeyReference,m_children.end());
512
513     protected:
514         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
515             PROC_TYPED_CHILDREN(DataReference,XMLConstants::XMLENC_NS,false);
516             PROC_TYPED_CHILDREN(KeyReference,XMLConstants::XMLENC_NS,false);
517             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
518         }
519     };
520
521     class XMLTOOL_DLLLOCAL EncryptedTypeImpl : public virtual EncryptedType,
522         public AbstractComplexElement,
523         public AbstractDOMCachingXMLObject,
524         public AbstractValidatingXMLObject,
525         public AbstractXMLObjectMarshaller,
526         public AbstractXMLObjectUnmarshaller
527     {
528         void init() {
529             m_Id=m_Type=m_MimeType=m_Encoding=NULL;
530             m_EncryptionMethod=NULL;
531             m_KeyInfo=NULL;
532             m_CipherData=NULL;
533             m_EncryptionProperties=NULL;
534             m_children.push_back(NULL);
535             m_children.push_back(NULL);
536             m_children.push_back(NULL);
537             m_children.push_back(NULL);
538             m_pos_EncryptionMethod=m_children.begin();
539             m_pos_KeyInfo=m_pos_EncryptionMethod;
540             ++m_pos_KeyInfo;
541             m_pos_CipherData=m_pos_KeyInfo;
542             ++m_pos_CipherData;
543             m_pos_EncryptionProperties=m_pos_CipherData;
544             ++m_pos_EncryptionProperties;
545         }
546     protected:
547         EncryptedTypeImpl() {
548             init();
549         }
550         
551     public:
552         virtual ~EncryptedTypeImpl() {
553             XMLString::release(&m_Id);
554             XMLString::release(&m_Type);
555             XMLString::release(&m_MimeType);
556             XMLString::release(&m_Encoding);
557         }
558
559         EncryptedTypeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
560                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
561             init();
562         }
563             
564         EncryptedTypeImpl(const EncryptedTypeImpl& src)
565                 : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), AbstractValidatingXMLObject(src) {
566             init();
567             setId(src.getId());
568             setType(src.getType());
569             setMimeType(src.getMimeType());
570             setEncoding(src.getEncoding());
571             if (src.getEncryptionMethod())
572                 setEncryptionMethod(src.getEncryptionMethod()->cloneEncryptionMethod());
573             if (src.getKeyInfo())
574                 setKeyInfo(src.getKeyInfo()->cloneKeyInfo());
575             if (src.getCipherData())
576                 setCipherData(src.getCipherData()->cloneCipherData());
577             if (src.getEncryptionProperties())
578                 setEncryptionProperties(src.getEncryptionProperties()->cloneEncryptionProperties());
579         }
580         
581         IMPL_XMLOBJECT_CLONE(EncryptedType);
582         IMPL_STRING_ATTRIB(Id);
583         IMPL_STRING_ATTRIB(Type);
584         IMPL_STRING_ATTRIB(MimeType);
585         IMPL_STRING_ATTRIB(Encoding);
586         IMPL_TYPED_CHILD(EncryptionMethod);
587         IMPL_TYPED_FOREIGN_CHILD(KeyInfo,xmlsignature);
588         IMPL_TYPED_CHILD(CipherData);
589         IMPL_TYPED_CHILD(EncryptionProperties);
590
591     protected:
592         void marshallAttributes(DOMElement* domElement) const {
593             MARSHALL_ID_ATTRIB(Id,ID,NULL);
594             MARSHALL_STRING_ATTRIB(Type,TYPE,NULL);
595             MARSHALL_STRING_ATTRIB(MimeType,MIMETYPE,NULL);
596             MARSHALL_STRING_ATTRIB(Encoding,ENCODING,NULL);
597         }
598
599         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
600             PROC_TYPED_CHILD(EncryptionMethod,XMLConstants::XMLENC_NS,false);
601             PROC_TYPED_FOREIGN_CHILD(KeyInfo,xmlsignature,XMLConstants::XMLSIG_NS,false);
602             PROC_TYPED_CHILD(CipherData,XMLConstants::XMLENC_NS,false);
603             PROC_TYPED_CHILD(EncryptionProperties,XMLConstants::XMLENC_NS,false);
604             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
605         }
606
607         void processAttribute(const DOMAttr* attribute) {
608             PROC_ID_ATTRIB(Id,ID,NULL);
609             PROC_STRING_ATTRIB(Type,TYPE,NULL);
610             PROC_STRING_ATTRIB(MimeType,MIMETYPE,NULL);
611             PROC_STRING_ATTRIB(Encoding,ENCODING,NULL);
612             AbstractXMLObjectUnmarshaller::processAttribute(attribute);
613         }
614     };
615
616     class XMLTOOL_DLLLOCAL EncryptedDataImpl : public virtual EncryptedData, public EncryptedTypeImpl
617     {
618     public:
619         virtual ~EncryptedDataImpl() {}
620
621         EncryptedDataImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
622             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {}
623             
624         EncryptedDataImpl(const EncryptedDataImpl& src) : AbstractXMLObject(src), EncryptedTypeImpl(src) {}
625         
626         IMPL_XMLOBJECT_CLONE(EncryptedData);
627         EncryptedType* cloneEncryptedType() const {
628             return new EncryptedDataImpl(*this);
629         }
630     };
631
632     class XMLTOOL_DLLLOCAL EncryptedKeyImpl : public virtual EncryptedKey, public EncryptedTypeImpl
633     {
634         void init() {
635             m_Recipient=NULL;
636             m_ReferenceList=NULL;
637             m_CarriedKeyName=NULL;
638             m_children.push_back(NULL);
639             m_children.push_back(NULL);
640             m_pos_ReferenceList=m_pos_EncryptionProperties;
641             ++m_pos_ReferenceList;
642             m_pos_CarriedKeyName=m_pos_ReferenceList;
643             ++m_pos_CarriedKeyName;
644         }
645         
646     public:
647         virtual ~EncryptedKeyImpl() {
648             XMLString::release(&m_Recipient);
649         }
650
651         EncryptedKeyImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
652                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
653             init();
654         }
655             
656         EncryptedKeyImpl(const EncryptedKeyImpl& src) : AbstractXMLObject(src), EncryptedTypeImpl(src) {
657             init();
658         }
659         
660         IMPL_XMLOBJECT_CLONE(EncryptedKey);
661         EncryptedType* cloneEncryptedType() const {
662             return new EncryptedKeyImpl(*this);
663         }
664         IMPL_STRING_ATTRIB(Recipient);
665         IMPL_TYPED_CHILD(ReferenceList);
666         IMPL_TYPED_CHILD(CarriedKeyName);
667     
668     protected:
669         void marshallAttributes(DOMElement* domElement) const {
670             MARSHALL_STRING_ATTRIB(Recipient,RECIPIENT,NULL);
671             EncryptedTypeImpl::marshallAttributes(domElement);
672         }
673
674         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
675             PROC_TYPED_CHILD(ReferenceList,XMLConstants::XMLENC_NS,false);
676             PROC_TYPED_CHILD(CarriedKeyName,XMLConstants::XMLENC_NS,false);
677             EncryptedTypeImpl::processChildElement(childXMLObject,root);
678         }
679
680         void processAttribute(const DOMAttr* attribute) {
681             PROC_STRING_ATTRIB(Recipient,RECIPIENT,NULL);
682             EncryptedTypeImpl::processAttribute(attribute);
683         }
684     };
685
686 };
687
688 #if defined (_MSC_VER)
689     #pragma warning( pop )
690 #endif
691
692 // Builder Implementations
693
694 IMPL_XMLOBJECTBUILDER(CarriedKeyName);
695 IMPL_XMLOBJECTBUILDER(CipherData);
696 IMPL_XMLOBJECTBUILDER(CipherReference);
697 IMPL_XMLOBJECTBUILDER(CipherValue);
698 IMPL_XMLOBJECTBUILDER(DataReference);
699 IMPL_XMLOBJECTBUILDER(EncryptedData);
700 IMPL_XMLOBJECTBUILDER(EncryptedKey);
701 IMPL_XMLOBJECTBUILDER(EncryptionMethod);
702 IMPL_XMLOBJECTBUILDER(EncryptionProperties);
703 IMPL_XMLOBJECTBUILDER(EncryptionProperty);
704 IMPL_XMLOBJECTBUILDER(KeyReference);
705 IMPL_XMLOBJECTBUILDER(KeySize);
706 IMPL_XMLOBJECTBUILDER(OAEPparams);
707 IMPL_XMLOBJECTBUILDER(ReferenceList);
708 IMPL_XMLOBJECTBUILDER(Transforms);
709
710 // Unicode literals
711
712 const XMLCh CarriedKeyName::LOCAL_NAME[] =              UNICODE_LITERAL_14(C,a,r,r,i,e,d,K,e,y,N,a,m,e);
713 const XMLCh CipherData::LOCAL_NAME[] =                  UNICODE_LITERAL_10(C,i,p,h,e,r,D,a,t,a);
714 const XMLCh CipherData::TYPE_NAME[] =                   UNICODE_LITERAL_14(C,i,p,h,e,r,D,a,t,a,T,y,p,e);
715 const XMLCh CipherReference::LOCAL_NAME[] =             UNICODE_LITERAL_15(C,i,p,h,e,r,R,e,f,e,r,e,n,c,e);
716 const XMLCh CipherReference::TYPE_NAME[] =              UNICODE_LITERAL_19(C,i,p,h,e,r,R,e,f,e,r,e,n,c,e,T,y,p,e);
717 const XMLCh CipherReference::URI_ATTRIB_NAME[] =        UNICODE_LITERAL_3(U,R,I);
718 const XMLCh CipherValue::LOCAL_NAME[] =                 UNICODE_LITERAL_11(C,i,p,h,e,r,V,a,l,u,e);
719 const XMLCh DataReference::LOCAL_NAME[] =               UNICODE_LITERAL_13(D,a,t,a,R,e,f,e,r,e,n,c,e);
720 const XMLCh EncryptedData::LOCAL_NAME[] =               UNICODE_LITERAL_13(E,n,c,r,y,p,t,e,d,D,a,t,a);
721 const XMLCh EncryptedData::TYPE_NAME[] =                UNICODE_LITERAL_17(E,n,c,r,y,p,t,e,d,D,a,t,a,T,y,p,e);
722 const XMLCh EncryptedKey::LOCAL_NAME[] =                UNICODE_LITERAL_12(E,n,c,r,y,p,t,e,d,K,e,y);
723 const XMLCh EncryptedKey::TYPE_NAME[] =                 UNICODE_LITERAL_16(E,n,c,r,y,p,t,e,d,K,e,y,T,y,p,e);
724 const XMLCh EncryptedKey::RECIPIENT_ATTRIB_NAME[] =     UNICODE_LITERAL_9(R,e,c,i,p,i,e,n,t);
725 const XMLCh EncryptedType::LOCAL_NAME[] =               {chNull};
726 const XMLCh EncryptedType::TYPE_NAME[] =                UNICODE_LITERAL_13(E,n,c,r,y,p,t,e,d,T,y,p,e);
727 const XMLCh EncryptedType::ID_ATTRIB_NAME[] =           UNICODE_LITERAL_2(I,d);
728 const XMLCh EncryptedType::TYPE_ATTRIB_NAME[] =         UNICODE_LITERAL_4(T,y,p,e);
729 const XMLCh EncryptedType::MIMETYPE_ATTRIB_NAME[] =     UNICODE_LITERAL_8(M,i,m,e,T,y,p,e);
730 const XMLCh EncryptedType::ENCODING_ATTRIB_NAME[] =     UNICODE_LITERAL_8(E,n,c,o,d,i,n,g);
731 const XMLCh EncryptionMethod::LOCAL_NAME[] =            UNICODE_LITERAL_16(E,n,c,r,y,p,t,i,o,n,M,e,t,h,o,d);
732 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);
733 const XMLCh EncryptionMethod::ALGORITHM_ATTRIB_NAME[] = UNICODE_LITERAL_9(A,l,g,o,r,i,t,h,m);
734 const XMLCh EncryptionProperties::LOCAL_NAME[] =        UNICODE_LITERAL_20(E,n,c,r,y,p,t,i,o,n,P,r,o,p,e,r,t,i,e,s);
735 const XMLCh EncryptionProperties::TYPE_NAME[] =         UNICODE_LITERAL_24(E,n,c,r,y,p,t,i,o,n,P,r,o,p,e,r,t,i,e,s,T,y,p,e);
736 const XMLCh EncryptionProperties::ID_ATTRIB_NAME[] =    UNICODE_LITERAL_2(I,d);
737 const XMLCh EncryptionProperty::LOCAL_NAME[] =          UNICODE_LITERAL_18(E,n,c,r,y,p,t,i,o,n,P,r,o,p,e,r,t,y);
738 const XMLCh EncryptionProperty::TYPE_NAME[] =           UNICODE_LITERAL_22(E,n,c,r,y,p,t,i,o,n,P,r,o,p,e,r,t,y,T,y,p,e);
739 const XMLCh EncryptionProperty::ID_ATTRIB_NAME[] =      UNICODE_LITERAL_2(I,d);
740 const XMLCh EncryptionProperty::TARGET_ATTRIB_NAME[] =  UNICODE_LITERAL_6(T,a,r,g,e,t);
741 const XMLCh KeyReference::LOCAL_NAME[] =                UNICODE_LITERAL_12(K,e,y,R,e,f,e,r,e,n,c,e);
742 const XMLCh KeySize::LOCAL_NAME[] =                     UNICODE_LITERAL_7(K,e,y,S,i,z,e);
743 const XMLCh OAEPparams::LOCAL_NAME[] =                  UNICODE_LITERAL_10(O,A,E,P,p,a,r,a,m,s);
744 const XMLCh ReferenceList::LOCAL_NAME[] =               UNICODE_LITERAL_13(R,e,f,e,r,e,n,c,e,L,i,s,t);
745 const XMLCh ReferenceType::LOCAL_NAME[] =               {chNull};
746 const XMLCh ReferenceType::TYPE_NAME[] =                UNICODE_LITERAL_13(R,e,f,e,r,e,n,c,e,T,y,p,e);
747 const XMLCh ReferenceType::URI_ATTRIB_NAME[] =          UNICODE_LITERAL_3(U,R,I);
748 const XMLCh Transforms::LOCAL_NAME[] =                  UNICODE_LITERAL_10(T,r,a,n,s,f,o,r,m,s);
749 const XMLCh Transforms::TYPE_NAME[] =                   UNICODE_LITERAL_14(T,r,a,n,s,f,o,r,m,s,T,y,p,e);