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