39030a8a6d9b6baeb9ba49866a497c194002d36b
[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                     return;
303                 }
304                 else if (XMLString::equals(qualifiedName.getLocalPart(),TARGET_ATTRIB_NAME)) {
305                     setTarget(value);
306                     return;
307                 }
308             }
309             AbstractAttributeExtensibleXMLObject::setAttribute(qualifiedName, value);
310         }
311
312     protected:
313         void marshallAttributes(DOMElement* domElement) const {
314             MARSHALL_ID_ATTRIB(Id,ID,NULL);
315             MARSHALL_STRING_ATTRIB(Target,TARGET,NULL);
316
317             // Take care of wildcard.
318             for (map<QName,XMLCh*>::const_iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) {
319                 DOMAttr* attr=domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(),i->first.getLocalPart());
320                 if (i->first.hasPrefix())
321                     attr->setPrefix(i->first.getPrefix());
322                 attr->setNodeValue(i->second);
323                 domElement->setAttributeNode(attr);
324             }
325         }
326
327         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
328             getXMLObjects().push_back(childXMLObject);
329         }
330
331         void processAttribute(const DOMAttr* attribute) {
332             PROC_ID_ATTRIB(Id,ID,NULL);
333             QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix()); 
334             setAttribute(q,attribute->getNodeValue());
335         }
336     };
337
338     class XMLTOOL_DLLLOCAL EncryptionPropertiesImpl : public virtual EncryptionProperties,
339         public AbstractComplexElement,
340         public AbstractDOMCachingXMLObject,
341         public AbstractValidatingXMLObject,
342         public AbstractXMLObjectMarshaller,
343         public AbstractXMLObjectUnmarshaller
344     {
345         void init() {
346             m_Id=NULL;
347         }
348     public:
349         virtual ~EncryptionPropertiesImpl() {
350             XMLString::release(&m_Id);
351         }
352
353         EncryptionPropertiesImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
354             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
355             init();
356         }
357             
358         EncryptionPropertiesImpl(const EncryptionPropertiesImpl& src)
359                 : AbstractXMLObject(src),
360                     AbstractDOMCachingXMLObject(src),
361                     AbstractValidatingXMLObject(src) {
362             init();
363             setId(src.getId());
364             VectorOf(EncryptionProperty) v=getEncryptionPropertys();
365             for (vector<EncryptionProperty*>::const_iterator i=src.m_EncryptionPropertys.begin(); i!=src.m_EncryptionPropertys.end(); i++) {
366                 if (*i) {
367                     v.push_back((*i)->cloneEncryptionProperty());
368                 }
369             }
370         }
371         
372         IMPL_XMLOBJECT_CLONE(EncryptionProperties);
373         IMPL_STRING_ATTRIB(Id);
374         IMPL_TYPED_CHILDREN(EncryptionProperty,m_children.end());
375
376     protected:
377         void marshallAttributes(DOMElement* domElement) const {
378             MARSHALL_ID_ATTRIB(Id,ID,NULL);
379         }
380
381         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
382             PROC_TYPED_CHILDREN(EncryptionProperty,XMLConstants::XMLENC_NS,false);
383             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
384         }
385
386         void processAttribute(const DOMAttr* attribute) {
387             PROC_ID_ATTRIB(Id,ID,NULL);
388             AbstractXMLObjectUnmarshaller::processAttribute(attribute);
389         }
390     };
391
392     class XMLTOOL_DLLLOCAL ReferenceTypeImpl : public virtual ReferenceType,
393         public AbstractElementProxy,
394         public AbstractDOMCachingXMLObject,
395         public AbstractValidatingXMLObject,
396         public AbstractXMLObjectMarshaller,
397         public AbstractXMLObjectUnmarshaller
398     {
399         void init() {
400             m_URI=NULL;
401         }
402         
403     protected:
404         ReferenceTypeImpl() {
405             init();
406         }
407         
408     public:
409         virtual ~ReferenceTypeImpl() {
410             XMLString::release(&m_URI);
411         }
412
413         ReferenceTypeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
414             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
415             init();
416         }
417             
418         ReferenceTypeImpl(const ReferenceTypeImpl& src)
419                 : AbstractXMLObject(src),
420                     AbstractElementProxy(src),
421                     AbstractDOMCachingXMLObject(src),
422                     AbstractValidatingXMLObject(src) {
423             init();
424             setURI(src.getURI());
425             for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
426                 if (*i) {
427                     getXMLObjects().push_back((*i)->clone());
428                 }
429             }
430         }
431         
432         IMPL_XMLOBJECT_CLONE(ReferenceType);
433         IMPL_STRING_ATTRIB(URI);
434
435     protected:
436         void marshallAttributes(DOMElement* domElement) const {
437             MARSHALL_STRING_ATTRIB(URI,URI,NULL);
438         }
439
440         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
441             getXMLObjects().push_back(childXMLObject);
442         }
443
444         void processAttribute(const DOMAttr* attribute) {
445             PROC_STRING_ATTRIB(URI,URI,NULL);
446             AbstractXMLObjectUnmarshaller::processAttribute(attribute);
447         }
448     };
449
450     class XMLTOOL_DLLLOCAL DataReferenceImpl : public virtual DataReference, public ReferenceTypeImpl
451     {
452     public:
453         virtual ~DataReferenceImpl() {}
454
455         DataReferenceImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
456             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {}
457             
458         DataReferenceImpl(const DataReferenceImpl& src) : AbstractXMLObject(src), ReferenceTypeImpl(src) {}
459         
460         IMPL_XMLOBJECT_CLONE(DataReference);
461         ReferenceType* cloneReferenceType() const {
462             return new DataReferenceImpl(*this);
463         }
464     };
465
466     class XMLTOOL_DLLLOCAL KeyReferenceImpl : public virtual KeyReference, public ReferenceTypeImpl
467     {
468     public:
469         virtual ~KeyReferenceImpl() {}
470
471         KeyReferenceImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
472             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {}
473             
474         KeyReferenceImpl(const KeyReferenceImpl& src) : AbstractXMLObject(src), ReferenceTypeImpl(src) {}
475         
476         IMPL_XMLOBJECT_CLONE(KeyReference);
477         ReferenceType* cloneReferenceType() const {
478             return new KeyReferenceImpl(*this);
479         }
480     };
481
482     class XMLTOOL_DLLLOCAL ReferenceListImpl : public virtual ReferenceList,
483         public AbstractComplexElement,
484         public AbstractDOMCachingXMLObject,
485         public AbstractValidatingXMLObject,
486         public AbstractXMLObjectMarshaller,
487         public AbstractXMLObjectUnmarshaller
488     {
489     public:
490         virtual ~ReferenceListImpl() {}
491
492         ReferenceListImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
493             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
494         }
495             
496         ReferenceListImpl(const ReferenceListImpl& src)
497                 : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), AbstractValidatingXMLObject(src) {
498             for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
499                 if (*i) {
500                     DataReference* data=dynamic_cast<DataReference*>(*i);
501                     if (data) {
502                         getDataReferences().push_back(data->cloneDataReference());
503                         continue;
504                     }
505
506                     KeyReference* key=dynamic_cast<KeyReference*>(*i);
507                     if (key) {
508                         getKeyReferences().push_back(key->cloneKeyReference());
509                         continue;
510                     }
511                 }
512             }
513         }
514         
515         IMPL_XMLOBJECT_CLONE(ReferenceList);
516         IMPL_TYPED_CHILDREN(DataReference,m_children.end());
517         IMPL_TYPED_CHILDREN(KeyReference,m_children.end());
518
519     protected:
520         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
521             PROC_TYPED_CHILDREN(DataReference,XMLConstants::XMLENC_NS,false);
522             PROC_TYPED_CHILDREN(KeyReference,XMLConstants::XMLENC_NS,false);
523             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
524         }
525     };
526
527     class XMLTOOL_DLLLOCAL EncryptedTypeImpl : public virtual EncryptedType,
528         public AbstractComplexElement,
529         public AbstractDOMCachingXMLObject,
530         public AbstractValidatingXMLObject,
531         public AbstractXMLObjectMarshaller,
532         public AbstractXMLObjectUnmarshaller
533     {
534         void init() {
535             m_Id=m_Type=m_MimeType=m_Encoding=NULL;
536             m_EncryptionMethod=NULL;
537             m_KeyInfo=NULL;
538             m_CipherData=NULL;
539             m_EncryptionProperties=NULL;
540             m_children.push_back(NULL);
541             m_children.push_back(NULL);
542             m_children.push_back(NULL);
543             m_children.push_back(NULL);
544             m_pos_EncryptionMethod=m_children.begin();
545             m_pos_KeyInfo=m_pos_EncryptionMethod;
546             ++m_pos_KeyInfo;
547             m_pos_CipherData=m_pos_KeyInfo;
548             ++m_pos_CipherData;
549             m_pos_EncryptionProperties=m_pos_CipherData;
550             ++m_pos_EncryptionProperties;
551         }
552     protected:
553         EncryptedTypeImpl() {
554             init();
555         }
556         
557     public:
558         virtual ~EncryptedTypeImpl() {
559             XMLString::release(&m_Id);
560             XMLString::release(&m_Type);
561             XMLString::release(&m_MimeType);
562             XMLString::release(&m_Encoding);
563         }
564
565         EncryptedTypeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
566                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
567             init();
568         }
569             
570         EncryptedTypeImpl(const EncryptedTypeImpl& src)
571                 : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), AbstractValidatingXMLObject(src) {
572             init();
573             setId(src.getId());
574             setType(src.getType());
575             setMimeType(src.getMimeType());
576             setEncoding(src.getEncoding());
577             if (src.getEncryptionMethod())
578                 setEncryptionMethod(src.getEncryptionMethod()->cloneEncryptionMethod());
579             if (src.getKeyInfo())
580                 setKeyInfo(src.getKeyInfo()->cloneKeyInfo());
581             if (src.getCipherData())
582                 setCipherData(src.getCipherData()->cloneCipherData());
583             if (src.getEncryptionProperties())
584                 setEncryptionProperties(src.getEncryptionProperties()->cloneEncryptionProperties());
585         }
586         
587         IMPL_XMLOBJECT_CLONE(EncryptedType);
588         IMPL_STRING_ATTRIB(Id);
589         IMPL_STRING_ATTRIB(Type);
590         IMPL_STRING_ATTRIB(MimeType);
591         IMPL_STRING_ATTRIB(Encoding);
592         IMPL_TYPED_CHILD(EncryptionMethod);
593         IMPL_TYPED_FOREIGN_CHILD(KeyInfo,xmlsignature);
594         IMPL_TYPED_CHILD(CipherData);
595         IMPL_TYPED_CHILD(EncryptionProperties);
596
597     protected:
598         void marshallAttributes(DOMElement* domElement) const {
599             MARSHALL_ID_ATTRIB(Id,ID,NULL);
600             MARSHALL_STRING_ATTRIB(Type,TYPE,NULL);
601             MARSHALL_STRING_ATTRIB(MimeType,MIMETYPE,NULL);
602             MARSHALL_STRING_ATTRIB(Encoding,ENCODING,NULL);
603         }
604
605         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
606             PROC_TYPED_CHILD(EncryptionMethod,XMLConstants::XMLENC_NS,false);
607             PROC_TYPED_FOREIGN_CHILD(KeyInfo,xmlsignature,XMLConstants::XMLSIG_NS,false);
608             PROC_TYPED_CHILD(CipherData,XMLConstants::XMLENC_NS,false);
609             PROC_TYPED_CHILD(EncryptionProperties,XMLConstants::XMLENC_NS,false);
610             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
611         }
612
613         void processAttribute(const DOMAttr* attribute) {
614             PROC_ID_ATTRIB(Id,ID,NULL);
615             PROC_STRING_ATTRIB(Type,TYPE,NULL);
616             PROC_STRING_ATTRIB(MimeType,MIMETYPE,NULL);
617             PROC_STRING_ATTRIB(Encoding,ENCODING,NULL);
618             AbstractXMLObjectUnmarshaller::processAttribute(attribute);
619         }
620     };
621
622     class XMLTOOL_DLLLOCAL EncryptedDataImpl : public virtual EncryptedData, public EncryptedTypeImpl
623     {
624     public:
625         virtual ~EncryptedDataImpl() {}
626
627         EncryptedDataImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
628             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {}
629             
630         EncryptedDataImpl(const EncryptedDataImpl& src) : AbstractXMLObject(src), EncryptedTypeImpl(src) {}
631         
632         IMPL_XMLOBJECT_CLONE(EncryptedData);
633         EncryptedType* cloneEncryptedType() const {
634             return new EncryptedDataImpl(*this);
635         }
636     };
637
638     class XMLTOOL_DLLLOCAL EncryptedKeyImpl : public virtual EncryptedKey, public EncryptedTypeImpl
639     {
640         void init() {
641             m_Recipient=NULL;
642             m_ReferenceList=NULL;
643             m_CarriedKeyName=NULL;
644             m_children.push_back(NULL);
645             m_children.push_back(NULL);
646             m_pos_ReferenceList=m_pos_EncryptionProperties;
647             ++m_pos_ReferenceList;
648             m_pos_CarriedKeyName=m_pos_ReferenceList;
649             ++m_pos_CarriedKeyName;
650         }
651         
652     public:
653         virtual ~EncryptedKeyImpl() {
654             XMLString::release(&m_Recipient);
655         }
656
657         EncryptedKeyImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
658                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
659             init();
660         }
661             
662         EncryptedKeyImpl(const EncryptedKeyImpl& src) : AbstractXMLObject(src), EncryptedTypeImpl(src) {
663             init();
664         }
665         
666         IMPL_XMLOBJECT_CLONE(EncryptedKey);
667         EncryptedType* cloneEncryptedType() const {
668             return new EncryptedKeyImpl(*this);
669         }
670         IMPL_STRING_ATTRIB(Recipient);
671         IMPL_TYPED_CHILD(ReferenceList);
672         IMPL_TYPED_CHILD(CarriedKeyName);
673     
674     protected:
675         void marshallAttributes(DOMElement* domElement) const {
676             MARSHALL_STRING_ATTRIB(Recipient,RECIPIENT,NULL);
677             EncryptedTypeImpl::marshallAttributes(domElement);
678         }
679
680         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
681             PROC_TYPED_CHILD(ReferenceList,XMLConstants::XMLENC_NS,false);
682             PROC_TYPED_CHILD(CarriedKeyName,XMLConstants::XMLENC_NS,false);
683             EncryptedTypeImpl::processChildElement(childXMLObject,root);
684         }
685
686         void processAttribute(const DOMAttr* attribute) {
687             PROC_STRING_ATTRIB(Recipient,RECIPIENT,NULL);
688             EncryptedTypeImpl::processAttribute(attribute);
689         }
690     };
691
692 };
693
694 #if defined (_MSC_VER)
695     #pragma warning( pop )
696 #endif
697
698 // Builder Implementations
699
700 IMPL_XMLOBJECTBUILDER(CarriedKeyName);
701 IMPL_XMLOBJECTBUILDER(CipherData);
702 IMPL_XMLOBJECTBUILDER(CipherReference);
703 IMPL_XMLOBJECTBUILDER(CipherValue);
704 IMPL_XMLOBJECTBUILDER(DataReference);
705 IMPL_XMLOBJECTBUILDER(EncryptedData);
706 IMPL_XMLOBJECTBUILDER(EncryptedKey);
707 IMPL_XMLOBJECTBUILDER(EncryptionMethod);
708 IMPL_XMLOBJECTBUILDER(EncryptionProperties);
709 IMPL_XMLOBJECTBUILDER(EncryptionProperty);
710 IMPL_XMLOBJECTBUILDER(KeyReference);
711 IMPL_XMLOBJECTBUILDER(KeySize);
712 IMPL_XMLOBJECTBUILDER(OAEPparams);
713 IMPL_XMLOBJECTBUILDER(ReferenceList);
714 IMPL_XMLOBJECTBUILDER(Transforms);
715
716 // Unicode literals
717
718 const XMLCh CarriedKeyName::LOCAL_NAME[] =              UNICODE_LITERAL_14(C,a,r,r,i,e,d,K,e,y,N,a,m,e);
719 const XMLCh CipherData::LOCAL_NAME[] =                  UNICODE_LITERAL_10(C,i,p,h,e,r,D,a,t,a);
720 const XMLCh CipherData::TYPE_NAME[] =                   UNICODE_LITERAL_14(C,i,p,h,e,r,D,a,t,a,T,y,p,e);
721 const XMLCh CipherReference::LOCAL_NAME[] =             UNICODE_LITERAL_15(C,i,p,h,e,r,R,e,f,e,r,e,n,c,e);
722 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);
723 const XMLCh CipherReference::URI_ATTRIB_NAME[] =        UNICODE_LITERAL_3(U,R,I);
724 const XMLCh CipherValue::LOCAL_NAME[] =                 UNICODE_LITERAL_11(C,i,p,h,e,r,V,a,l,u,e);
725 const XMLCh DataReference::LOCAL_NAME[] =               UNICODE_LITERAL_13(D,a,t,a,R,e,f,e,r,e,n,c,e);
726 const XMLCh EncryptedData::LOCAL_NAME[] =               UNICODE_LITERAL_13(E,n,c,r,y,p,t,e,d,D,a,t,a);
727 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);
728 const XMLCh EncryptedKey::LOCAL_NAME[] =                UNICODE_LITERAL_12(E,n,c,r,y,p,t,e,d,K,e,y);
729 const XMLCh EncryptedKey::TYPE_NAME[] =                 UNICODE_LITERAL_16(E,n,c,r,y,p,t,e,d,K,e,y,T,y,p,e);
730 const XMLCh EncryptedKey::RECIPIENT_ATTRIB_NAME[] =     UNICODE_LITERAL_9(R,e,c,i,p,i,e,n,t);
731 const XMLCh EncryptedType::LOCAL_NAME[] =               {chNull};
732 const XMLCh EncryptedType::TYPE_NAME[] =                UNICODE_LITERAL_13(E,n,c,r,y,p,t,e,d,T,y,p,e);
733 const XMLCh EncryptedType::ID_ATTRIB_NAME[] =           UNICODE_LITERAL_2(I,d);
734 const XMLCh EncryptedType::TYPE_ATTRIB_NAME[] =         UNICODE_LITERAL_4(T,y,p,e);
735 const XMLCh EncryptedType::MIMETYPE_ATTRIB_NAME[] =     UNICODE_LITERAL_8(M,i,m,e,T,y,p,e);
736 const XMLCh EncryptedType::ENCODING_ATTRIB_NAME[] =     UNICODE_LITERAL_8(E,n,c,o,d,i,n,g);
737 const XMLCh EncryptionMethod::LOCAL_NAME[] =            UNICODE_LITERAL_16(E,n,c,r,y,p,t,i,o,n,M,e,t,h,o,d);
738 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);
739 const XMLCh EncryptionMethod::ALGORITHM_ATTRIB_NAME[] = UNICODE_LITERAL_9(A,l,g,o,r,i,t,h,m);
740 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);
741 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);
742 const XMLCh EncryptionProperties::ID_ATTRIB_NAME[] =    UNICODE_LITERAL_2(I,d);
743 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);
744 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);
745 const XMLCh EncryptionProperty::ID_ATTRIB_NAME[] =      UNICODE_LITERAL_2(I,d);
746 const XMLCh EncryptionProperty::TARGET_ATTRIB_NAME[] =  UNICODE_LITERAL_6(T,a,r,g,e,t);
747 const XMLCh KeyReference::LOCAL_NAME[] =                UNICODE_LITERAL_12(K,e,y,R,e,f,e,r,e,n,c,e);
748 const XMLCh KeySize::LOCAL_NAME[] =                     UNICODE_LITERAL_7(K,e,y,S,i,z,e);
749 const XMLCh OAEPparams::LOCAL_NAME[] =                  UNICODE_LITERAL_10(O,A,E,P,p,a,r,a,m,s);
750 const XMLCh ReferenceList::LOCAL_NAME[] =               UNICODE_LITERAL_13(R,e,f,e,r,e,n,c,e,L,i,s,t);
751 const XMLCh ReferenceType::LOCAL_NAME[] =               {chNull};
752 const XMLCh ReferenceType::TYPE_NAME[] =                UNICODE_LITERAL_13(R,e,f,e,r,e,n,c,e,T,y,p,e);
753 const XMLCh ReferenceType::URI_ATTRIB_NAME[] =          UNICODE_LITERAL_3(U,R,I);
754 const XMLCh Transforms::LOCAL_NAME[] =                  UNICODE_LITERAL_10(T,r,a,n,s,f,o,r,m,s);
755 const XMLCh Transforms::TYPE_NAME[] =                   UNICODE_LITERAL_14(T,r,a,n,s,f,o,r,m,s,T,y,p,e);