X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2Fencryption%2Fimpl%2FEncryptionImpl.cpp;h=9e766e2370f5c8a7e79ee57a05651fe354ae2fff;hb=73308303d23af62494bfeef0c0d5224c344c6d6f;hp=a6d0af7f07e5684418dcd0f2a97ec0797440c58b;hpb=a5e86d37cf40004e6a43a21ab67d26695fa8619c;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/encryption/impl/EncryptionImpl.cpp b/xmltooling/encryption/impl/EncryptionImpl.cpp index a6d0af7..9e766e2 100644 --- a/xmltooling/encryption/impl/EncryptionImpl.cpp +++ b/xmltooling/encryption/impl/EncryptionImpl.cpp @@ -1,23 +1,27 @@ -/* - * Copyright 2001-2007 Internet2 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at +/** + * Licensed to the University Corporation for Advanced Internet + * Development, Inc. (UCAID) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + * + * UCAID licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. */ /** * EncryptionImpl.cpp * - * Implementation classes for XML Encryption schema + * Implementation classes for XML Encryption schema. */ #include "internal.h" @@ -28,8 +32,13 @@ #include "encryption/Encryption.h" #include "io/AbstractXMLObjectMarshaller.h" #include "io/AbstractXMLObjectUnmarshaller.h" +#include "signature/KeyInfo.h" #include "util/XMLHelper.h" +#include +#include +#include +#include #include using namespace xmlencryption; @@ -58,15 +67,16 @@ namespace xmlencryption { public AbstractXMLObjectUnmarshaller { void init() { - m_Algorithm=NULL; - m_KeySize=NULL; - m_OAEPparams=NULL; - m_children.push_back(NULL); - m_children.push_back(NULL); + m_Algorithm=nullptr; + m_KeySize=nullptr; + m_OAEPparams=nullptr; + m_children.push_back(nullptr); + m_children.push_back(nullptr); m_pos_KeySize=m_children.begin(); m_pos_OAEPparams=m_pos_KeySize; ++m_pos_OAEPparams; } + public: virtual ~EncryptionMethodImpl() { XMLString::release(&m_Algorithm); @@ -80,14 +90,10 @@ namespace xmlencryption { EncryptionMethodImpl(const EncryptionMethodImpl& src) : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) { init(); - setAlgorithm(src.getAlgorithm()); - if (src.getKeySize()) - setKeySize(src.getKeySize()->cloneKeySize()); - if (src.getOAEPparams()) - setOAEPparams(src.getOAEPparams()->cloneOAEPparams()); - VectorOf(XMLObject) v=getUnknownXMLObjects(); - for (vector::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i) - v.push_back((*i)->clone()); + IMPL_CLONE_ATTRIB(Algorithm); + IMPL_CLONE_TYPED_CHILD(KeySize); + IMPL_CLONE_TYPED_CHILD(OAEPparams); + IMPL_CLONE_XMLOBJECT_CHILDREN(UnknownXMLObject); } IMPL_XMLOBJECT_CLONE(EncryptionMethod); @@ -98,7 +104,7 @@ namespace xmlencryption { protected: void marshallAttributes(DOMElement* domElement) const { - MARSHALL_STRING_ATTRIB(Algorithm,ALGORITHM,NULL); + MARSHALL_STRING_ATTRIB(Algorithm,ALGORITHM,nullptr); } void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { @@ -116,7 +122,7 @@ namespace xmlencryption { } void processAttribute(const DOMAttr* attribute) { - PROC_STRING_ATTRIB(Algorithm,ALGORITHM,NULL); + PROC_STRING_ATTRIB(Algorithm,ALGORITHM,nullptr); AbstractXMLObjectUnmarshaller::processAttribute(attribute); } }; @@ -136,12 +142,7 @@ namespace xmlencryption { TransformsImpl(const TransformsImpl& src) : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) { - VectorOf(xmlsignature::Transform) v=getTransforms(); - for (vector::const_iterator i=src.m_Transforms.begin(); i!=src.m_Transforms.end(); i++) { - if (*i) { - v.push_back((*i)->cloneTransform()); - } - } + IMPL_CLONE_TYPED_FOREIGN_CHILDREN(Transform,xmlsignature); } IMPL_XMLOBJECT_CLONE(Transforms); @@ -161,11 +162,12 @@ namespace xmlencryption { public AbstractXMLObjectUnmarshaller { void init() { - m_URI=NULL; - m_Transforms=NULL; - m_children.push_back(NULL); + m_URI=nullptr; + m_Transforms=nullptr; + m_children.push_back(nullptr); m_pos_Transforms=m_children.begin(); } + public: virtual ~CipherReferenceImpl() { XMLString::release(&m_URI); @@ -179,9 +181,8 @@ namespace xmlencryption { CipherReferenceImpl(const CipherReferenceImpl& src) : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) { init(); - setURI(src.getURI()); - if (src.getTransforms()) - setTransforms(src.getTransforms()->cloneTransforms()); + IMPL_CLONE_ATTRIB(URI); + IMPL_CLONE_TYPED_CHILD(Transforms); } IMPL_XMLOBJECT_CLONE(CipherReference); @@ -190,7 +191,7 @@ namespace xmlencryption { protected: void marshallAttributes(DOMElement* domElement) const { - MARSHALL_STRING_ATTRIB(URI,URI,NULL); + MARSHALL_STRING_ATTRIB(URI,URI,nullptr); } void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { @@ -199,7 +200,7 @@ namespace xmlencryption { } void processAttribute(const DOMAttr* attribute) { - PROC_STRING_ATTRIB(URI,URI,NULL); + PROC_STRING_ATTRIB(URI,URI,nullptr); AbstractXMLObjectUnmarshaller::processAttribute(attribute); } }; @@ -211,14 +212,15 @@ namespace xmlencryption { public AbstractXMLObjectUnmarshaller { void init() { - m_CipherValue=NULL; - m_CipherReference=NULL; - m_children.push_back(NULL); - m_children.push_back(NULL); + m_CipherValue=nullptr; + m_CipherReference=nullptr; + m_children.push_back(nullptr); + m_children.push_back(nullptr); m_pos_CipherValue=m_children.begin(); m_pos_CipherReference=m_pos_CipherValue; ++m_pos_CipherReference; } + public: virtual ~CipherDataImpl() {} @@ -230,10 +232,8 @@ namespace xmlencryption { CipherDataImpl(const CipherDataImpl& src) : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) { init(); - if (src.getCipherValue()) - setCipherValue(src.getCipherValue()->cloneCipherValue()); - if (src.getCipherReference()) - setCipherReference(src.getCipherReference()->cloneCipherReference()); + IMPL_CLONE_TYPED_CHILD(CipherValue); + IMPL_CLONE_TYPED_CHILD(CipherReference); } IMPL_XMLOBJECT_CLONE(CipherData); @@ -256,8 +256,9 @@ namespace xmlencryption { public AbstractXMLObjectUnmarshaller { void init() { - m_Id=m_Target=NULL; + m_Id=m_Target=nullptr; } + public: virtual ~EncryptionPropertyImpl() { XMLString::release(&m_Id); @@ -275,15 +276,13 @@ namespace xmlencryption { AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) { init(); - setId(src.getId()); - setTarget(src.getTarget()); - VectorOf(XMLObject) v=getUnknownXMLObjects(); - for (vector::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i) - v.push_back((*i)->clone()); + IMPL_CLONE_ATTRIB(Id); + IMPL_CLONE_ATTRIB(Target); + IMPL_CLONE_XMLOBJECT_CHILDREN(UnknownXMLObject); } IMPL_XMLOBJECT_CLONE(EncryptionProperty); - IMPL_ID_ATTRIB(Id); + IMPL_ID_ATTRIB_EX(Id,ID,nullptr); IMPL_STRING_ATTRIB(Target); IMPL_XMLOBJECT_CHILDREN(UnknownXMLObject, m_children.end()); @@ -303,8 +302,8 @@ namespace xmlencryption { protected: void marshallAttributes(DOMElement* domElement) const { - MARSHALL_ID_ATTRIB(Id,ID,NULL); - MARSHALL_STRING_ATTRIB(Target,TARGET,NULL); + MARSHALL_ID_ATTRIB(Id,ID,nullptr); + MARSHALL_STRING_ATTRIB(Target,TARGET,nullptr); marshallExtensionAttributes(domElement); } @@ -313,7 +312,7 @@ namespace xmlencryption { } void processAttribute(const DOMAttr* attribute) { - PROC_ID_ATTRIB(Id,ID,NULL); + PROC_ID_ATTRIB(Id,ID,nullptr); unmarshallExtensionAttribute(attribute); } }; @@ -325,8 +324,9 @@ namespace xmlencryption { public AbstractXMLObjectUnmarshaller { void init() { - m_Id=NULL; + m_Id=nullptr; } + public: virtual ~EncryptionPropertiesImpl() { XMLString::release(&m_Id); @@ -340,22 +340,17 @@ namespace xmlencryption { EncryptionPropertiesImpl(const EncryptionPropertiesImpl& src) : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) { init(); - setId(src.getId()); - VectorOf(EncryptionProperty) v=getEncryptionPropertys(); - for (vector::const_iterator i=src.m_EncryptionPropertys.begin(); i!=src.m_EncryptionPropertys.end(); i++) { - if (*i) { - v.push_back((*i)->cloneEncryptionProperty()); - } - } + IMPL_CLONE_ATTRIB(Id); + IMPL_CLONE_TYPED_CHILDREN(EncryptionProperty); } IMPL_XMLOBJECT_CLONE(EncryptionProperties); - IMPL_ID_ATTRIB(Id); + IMPL_ID_ATTRIB_EX(Id,ID,nullptr); IMPL_TYPED_CHILDREN(EncryptionProperty,m_children.end()); protected: void marshallAttributes(DOMElement* domElement) const { - MARSHALL_ID_ATTRIB(Id,ID,NULL); + MARSHALL_ID_ATTRIB(Id,ID,nullptr); } void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { @@ -364,7 +359,7 @@ namespace xmlencryption { } void processAttribute(const DOMAttr* attribute) { - PROC_ID_ATTRIB(Id,ID,NULL); + PROC_ID_ATTRIB(Id,ID,nullptr); AbstractXMLObjectUnmarshaller::processAttribute(attribute); } }; @@ -375,13 +370,9 @@ namespace xmlencryption { public AbstractXMLObjectMarshaller, public AbstractXMLObjectUnmarshaller { - void init() { - m_URI=NULL; - } - protected: ReferenceTypeImpl() { - init(); + m_URI=nullptr; } public: @@ -390,26 +381,25 @@ namespace xmlencryption { } ReferenceTypeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType) - : AbstractXMLObject(nsURI, localName, prefix, schemaType) { - init(); + : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_URI(nullptr) { } ReferenceTypeImpl(const ReferenceTypeImpl& src) - : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) { - init(); - setURI(src.getURI()); - VectorOf(XMLObject) v=getUnknownXMLObjects(); - for (vector::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i) - v.push_back((*i)->clone()); + : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src), m_URI(nullptr) { + } + + void _clone(const ReferenceTypeImpl& src) { + IMPL_CLONE_ATTRIB(URI); + IMPL_CLONE_XMLOBJECT_CHILDREN(UnknownXMLObject); } - IMPL_XMLOBJECT_CLONE(ReferenceType); + IMPL_XMLOBJECT_CLONE_EX(ReferenceType); IMPL_STRING_ATTRIB(URI); IMPL_XMLOBJECT_CHILDREN(UnknownXMLObject,m_children.end()); protected: void marshallAttributes(DOMElement* domElement) const { - MARSHALL_STRING_ATTRIB(URI,URI,NULL); + MARSHALL_STRING_ATTRIB(URI,URI,nullptr); } void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { @@ -417,7 +407,7 @@ namespace xmlencryption { } void processAttribute(const DOMAttr* attribute) { - PROC_STRING_ATTRIB(URI,URI,NULL); + PROC_STRING_ATTRIB(URI,URI,nullptr); AbstractXMLObjectUnmarshaller::processAttribute(attribute); } }; @@ -431,11 +421,8 @@ namespace xmlencryption { : AbstractXMLObject(nsURI, localName, prefix, schemaType) {} DataReferenceImpl(const DataReferenceImpl& src) : AbstractXMLObject(src), ReferenceTypeImpl(src) {} - - IMPL_XMLOBJECT_CLONE(DataReference); - ReferenceType* cloneReferenceType() const { - return new DataReferenceImpl(*this); - } + + IMPL_XMLOBJECT_CLONE_EX(DataReference); }; class XMLTOOL_DLLLOCAL KeyReferenceImpl : public virtual KeyReference, public ReferenceTypeImpl @@ -448,10 +435,7 @@ namespace xmlencryption { KeyReferenceImpl(const KeyReferenceImpl& src) : AbstractXMLObject(src), ReferenceTypeImpl(src) {} - IMPL_XMLOBJECT_CLONE(KeyReference); - ReferenceType* cloneReferenceType() const { - return new KeyReferenceImpl(*this); - } + IMPL_XMLOBJECT_CLONE_EX(KeyReference); }; class XMLTOOL_DLLLOCAL ReferenceListImpl : public virtual ReferenceList, @@ -469,21 +453,10 @@ namespace xmlencryption { ReferenceListImpl(const ReferenceListImpl& src) : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) { - for (list::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) { - if (*i) { - DataReference* data=dynamic_cast(*i); - if (data) { - getDataReferences().push_back(data->cloneDataReference()); - continue; - } - - KeyReference* key=dynamic_cast(*i); - if (key) { - getKeyReferences().push_back(key->cloneKeyReference()); - continue; - } - } - } + IMPL_CLONE_CHILDBAG_BEGIN; + IMPL_CLONE_TYPED_CHILD_IN_BAG(DataReference); + IMPL_CLONE_TYPED_CHILD_IN_BAG(KeyReference); + IMPL_CLONE_CHILDBAG_END; } IMPL_XMLOBJECT_CLONE(ReferenceList); @@ -505,15 +478,15 @@ namespace xmlencryption { public AbstractXMLObjectUnmarshaller { void init() { - m_Id=m_Type=m_MimeType=m_Encoding=NULL; - m_EncryptionMethod=NULL; - m_KeyInfo=NULL; - m_CipherData=NULL; - m_EncryptionProperties=NULL; - m_children.push_back(NULL); - m_children.push_back(NULL); - m_children.push_back(NULL); - m_children.push_back(NULL); + m_Id=m_Type=m_MimeType=m_Encoding=nullptr; + m_EncryptionMethod=nullptr; + m_KeyInfo=nullptr; + m_CipherData=nullptr; + m_EncryptionProperties=nullptr; + m_children.push_back(nullptr); + m_children.push_back(nullptr); + m_children.push_back(nullptr); + m_children.push_back(nullptr); m_pos_EncryptionMethod=m_children.begin(); m_pos_KeyInfo=m_pos_EncryptionMethod; ++m_pos_KeyInfo; @@ -522,6 +495,7 @@ namespace xmlencryption { m_pos_EncryptionProperties=m_pos_CipherData; ++m_pos_EncryptionProperties; } + protected: EncryptedTypeImpl() { init(); @@ -543,22 +517,21 @@ namespace xmlencryption { EncryptedTypeImpl(const EncryptedTypeImpl& src) : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) { init(); - setId(src.getId()); - setType(src.getType()); - setMimeType(src.getMimeType()); - setEncoding(src.getEncoding()); - if (src.getEncryptionMethod()) - setEncryptionMethod(src.getEncryptionMethod()->cloneEncryptionMethod()); - if (src.getKeyInfo()) - setKeyInfo(src.getKeyInfo()->cloneKeyInfo()); - if (src.getCipherData()) - setCipherData(src.getCipherData()->cloneCipherData()); - if (src.getEncryptionProperties()) - setEncryptionProperties(src.getEncryptionProperties()->cloneEncryptionProperties()); + } + + void _clone(const EncryptedTypeImpl& src) { + IMPL_CLONE_ATTRIB(Id); + IMPL_CLONE_ATTRIB(Type); + IMPL_CLONE_ATTRIB(MimeType); + IMPL_CLONE_ATTRIB(Encoding); + IMPL_CLONE_TYPED_CHILD(EncryptionMethod); + IMPL_CLONE_TYPED_CHILD(KeyInfo); + IMPL_CLONE_TYPED_CHILD(CipherData); + IMPL_CLONE_TYPED_CHILD(EncryptionProperties); } - IMPL_XMLOBJECT_CLONE(EncryptedType); - IMPL_ID_ATTRIB(Id); + IMPL_XMLOBJECT_CLONE_EX(EncryptedType); + IMPL_ID_ATTRIB_EX(Id,ID,nullptr); IMPL_STRING_ATTRIB(Type); IMPL_STRING_ATTRIB(MimeType); IMPL_STRING_ATTRIB(Encoding); @@ -569,10 +542,10 @@ namespace xmlencryption { protected: void marshallAttributes(DOMElement* domElement) const { - MARSHALL_ID_ATTRIB(Id,ID,NULL); - MARSHALL_STRING_ATTRIB(Type,TYPE,NULL); - MARSHALL_STRING_ATTRIB(MimeType,MIMETYPE,NULL); - MARSHALL_STRING_ATTRIB(Encoding,ENCODING,NULL); + MARSHALL_ID_ATTRIB(Id,ID,nullptr); + MARSHALL_STRING_ATTRIB(Type,TYPE,nullptr); + MARSHALL_STRING_ATTRIB(MimeType,MIMETYPE,nullptr); + MARSHALL_STRING_ATTRIB(Encoding,ENCODING,nullptr); } void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { @@ -584,10 +557,10 @@ namespace xmlencryption { } void processAttribute(const DOMAttr* attribute) { - PROC_ID_ATTRIB(Id,ID,NULL); - PROC_STRING_ATTRIB(Type,TYPE,NULL); - PROC_STRING_ATTRIB(MimeType,MIMETYPE,NULL); - PROC_STRING_ATTRIB(Encoding,ENCODING,NULL); + PROC_ID_ATTRIB(Id,ID,nullptr); + PROC_STRING_ATTRIB(Type,TYPE,nullptr); + PROC_STRING_ATTRIB(MimeType,MIMETYPE,nullptr); + PROC_STRING_ATTRIB(Encoding,ENCODING,nullptr); AbstractXMLObjectUnmarshaller::processAttribute(attribute); } }; @@ -602,20 +575,17 @@ namespace xmlencryption { EncryptedDataImpl(const EncryptedDataImpl& src) : AbstractXMLObject(src), EncryptedTypeImpl(src) {} - IMPL_XMLOBJECT_CLONE(EncryptedData); - EncryptedType* cloneEncryptedType() const { - return new EncryptedDataImpl(*this); - } + IMPL_XMLOBJECT_CLONE_EX(EncryptedData); }; class XMLTOOL_DLLLOCAL EncryptedKeyImpl : public virtual EncryptedKey, public EncryptedTypeImpl { void init() { - m_Recipient=NULL; - m_ReferenceList=NULL; - m_CarriedKeyName=NULL; - m_children.push_back(NULL); - m_children.push_back(NULL); + m_Recipient=nullptr; + m_ReferenceList=nullptr; + m_CarriedKeyName=nullptr; + m_children.push_back(nullptr); + m_children.push_back(nullptr); m_pos_ReferenceList=m_pos_EncryptionProperties; ++m_pos_ReferenceList; m_pos_CarriedKeyName=m_pos_ReferenceList; @@ -636,17 +606,21 @@ namespace xmlencryption { init(); } - IMPL_XMLOBJECT_CLONE(EncryptedKey); - EncryptedType* cloneEncryptedType() const { - return new EncryptedKeyImpl(*this); + void _clone(const EncryptedKeyImpl& src) { + EncryptedTypeImpl::_clone(src); + IMPL_CLONE_ATTRIB(Recipient); + IMPL_CLONE_TYPED_CHILD(ReferenceList); + IMPL_CLONE_TYPED_CHILD(CarriedKeyName); } + + IMPL_XMLOBJECT_CLONE_EX(EncryptedKey); IMPL_STRING_ATTRIB(Recipient); IMPL_TYPED_CHILD(ReferenceList); IMPL_TYPED_CHILD(CarriedKeyName); protected: void marshallAttributes(DOMElement* domElement) const { - MARSHALL_STRING_ATTRIB(Recipient,RECIPIENT,NULL); + MARSHALL_STRING_ATTRIB(Recipient,RECIPIENT,nullptr); EncryptedTypeImpl::marshallAttributes(domElement); } @@ -657,7 +631,7 @@ namespace xmlencryption { } void processAttribute(const DOMAttr* attribute) { - PROC_STRING_ATTRIB(Recipient,RECIPIENT,NULL); + PROC_STRING_ATTRIB(Recipient,RECIPIENT,nullptr); EncryptedTypeImpl::processAttribute(attribute); } };