From 9ddaa69a244911a649e8b85fbfa9b82962df0970 Mon Sep 17 00:00:00 2001 From: cantor Date: Sun, 2 Apr 2006 22:04:40 +0000 Subject: [PATCH] Moved signature classes into own namespace. git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/trunk@71 de75baf8-a10c-0410-a50a-987c0e22f00f --- xmltooling/XMLObject.h | 16 +-- xmltooling/XMLToolingConfig.cpp | 8 +- xmltooling/base.h | 113 ++++++++++++++------ xmltooling/io/AbstractXMLObjectMarshaller.cpp | 1 + xmltooling/signature/KeyInfo.h | 50 +++++---- xmltooling/signature/Signature.h | 12 ++- xmltooling/signature/SigningContext.h | 2 +- xmltooling/signature/VerifyingContext.h | 2 +- xmltooling/signature/impl/KeyInfoImpl.cpp | 122 ++++++++++++++++++++-- xmltooling/signature/impl/XMLSecSignatureImpl.cpp | 3 +- xmltoolingtest/XMLObjectBaseTestCase.h | 1 + 11 files changed, 257 insertions(+), 73 deletions(-) diff --git a/xmltooling/XMLObject.h b/xmltooling/XMLObject.h index 46157b8..89466a5 100644 --- a/xmltooling/XMLObject.h +++ b/xmltooling/XMLObject.h @@ -32,6 +32,13 @@ using namespace xercesc; +#ifndef XMLTOOLING_NO_XMLSEC +namespace xmlsignature { + class XMLTOOL_API Signature; + class XMLTOOL_API SigningContext; +}; +#endif + #if defined (_MSC_VER) #pragma warning( push ) #pragma warning( disable : 4250 4251 ) @@ -39,11 +46,6 @@ using namespace xercesc; namespace xmltooling { -#ifndef XMLTOOLING_NO_XMLSEC - class XMLTOOL_API Signature; - class XMLTOOL_API SigningContext; -#endif - /** * Supplies additional information to the marshalling process. * Currently this only consists of signature related information. @@ -65,12 +67,12 @@ namespace xmltooling { * @param sig a signature object * @param ctx the signing context to associate with the signature */ - MarshallingContext(Signature* sig, const SigningContext* ctx) { + MarshallingContext(xmlsignature::Signature* sig, const xmlsignature::SigningContext* ctx) { m_signingContexts.push_back(std::make_pair(sig,ctx)); } /** Array of signing contexts, keyed off of the associated Signature */ - std::vector< std::pair > m_signingContexts; + std::vector< std::pair > m_signingContexts; #endif }; diff --git a/xmltooling/XMLToolingConfig.cpp b/xmltooling/XMLToolingConfig.cpp index 5eb291b..6cd8826 100644 --- a/xmltooling/XMLToolingConfig.cpp +++ b/xmltooling/XMLToolingConfig.cpp @@ -46,8 +46,9 @@ #include -using namespace log4cpp; +using namespace xmlsignature; using namespace xmltooling; +using namespace log4cpp; using namespace std; #define REGISTER_ELEMENT(namespaceURI,cname) \ @@ -183,10 +184,15 @@ bool XMLToolingInternalConfig::init() REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,J); REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Seed); REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,PgenCounter); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,XPath); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Transform); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Transforms); REGISTER_TYPE(XMLConstants::XMLSIG_NS,KeyInfo); REGISTER_TYPE(XMLConstants::XMLSIG_NS,KeyValue); REGISTER_TYPE(XMLConstants::XMLSIG_NS,DSAKeyValue); REGISTER_TYPE(XMLConstants::XMLSIG_NS,RSAKeyValue); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,Transform); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,Transforms); #ifndef XMLTOOLING_NO_XMLSEC XMLObjectBuilder::registerBuilder(QName(XMLConstants::XMLSIG_NS,Signature::LOCAL_NAME),new SignatureBuilder()); diff --git a/xmltooling/base.h b/xmltooling/base.h index 9809d52..43903d8 100644 --- a/xmltooling/base.h +++ b/xmltooling/base.h @@ -30,11 +30,6 @@ #include #endif -/** - * @namespace xmltooling - * Public namespace of XML Tooling library - */ - // Windows and GCC4 Symbol Visibility Macros #ifdef WIN32 #define XMLTOOL_IMPORT __declspec(dllimport) @@ -169,9 +164,11 @@ * @param linkage linkage specifier for the class * @param cname the name of the class to declare * @param base the base class to derive from using public virtual inheritance + * @param desc documentation comment for class */ -#define BEGIN_XMLOBJECT(linkage,cname,base) \ - class linkage cname : public virtual base, public virtual ValidatingXMLObject { \ +#define BEGIN_XMLOBJECT(linkage,cname,base,desc) \ + XMLTOOLING_DOXYGEN(desc) \ + class linkage cname : public virtual base, public virtual xmltooling::ValidatingXMLObject { \ protected: \ cname() {} \ public: \ @@ -277,13 +274,65 @@ } /** + * Implements marshalling for an attribute + * + * @param proper the proper name of the attribute + * @param ucase the upcased name of the attribute + * @param namespaceURI the XML namespace of the attribute + */ +#define MARSHALL_XMLOBJECT_ATTRIB(proper,ucase,namespaceURI) \ + if(get##proper()) { \ + domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, get##proper()); \ + } + +/** + * Implements marshalling for an ID attribute + * + * @param proper the proper name of the attribute + * @param ucase the upcased name of the attribute + * @param namespaceURI the XML namespace of the attribute + */ +#define MARSHALL_XMLOBJECT_ID_ATTRIB(proper,ucase,namespaceURI) \ + if(get##proper()) { \ + domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, get##proper()); \ + domElement->setIdAttributeNS(namespaceURI, ucase##_ATTRIB_NAME); \ + } + +/** + * Implements unmarshalling process branch for an attribute + * + * @param proper the proper name of the attribute + * @param ucase the upcased name of the attribute + * @param namespaceURI the XML namespace of the attribute + */ +#define PROC_XMLOBJECT_ATTRIB(proper,ucase,namespaceURI) \ + if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \ + set##proper(attribute->getValue()); \ + return; \ + } + +/** + * Implements unmarshalling process branch for an ID attribute + * + * @param proper the proper name of the attribute + * @param ucase the upcased name of the attribute + * @param namespaceURI the XML namespace of the attribute + */ +#define PROC_XMLOBJECT_ID_ATTRIB(proper,ucase,namespaceURI) \ + if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \ + set##proper(attribute->getValue()); \ + static_cast(attribute->getParentNode())->setIdAttributeNode(attribute); \ + return; \ + } + +/** * Implements unmarshalling process branch for typed child collection element * * @param proper the proper name of the child type * @param namespaceURI the XML namespace of the child element */ #define PROC_XMLOBJECT_CHILDREN(proper,namespaceURI) \ - if (XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \ + if (xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \ proper* typesafe=dynamic_cast(childXMLObject); \ if (typesafe) { \ get##proper##s().push_back(typesafe); \ @@ -298,7 +347,7 @@ * @param namespaceURI the XML namespace of the child element */ #define PROC_XMLOBJECT_CHILD(proper,namespaceURI) \ - if (XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \ + if (xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \ proper* typesafe=dynamic_cast(childXMLObject); \ if (typesafe) { \ set##proper(typesafe); \ @@ -353,7 +402,7 @@ return clone(); \ } \ cname* clone() const { \ - auto_ptr domClone(AbstractDOMCachingXMLObject::clone()); \ + std::auto_ptr domClone(xmltooling::AbstractDOMCachingXMLObject::clone()); \ cname##Impl* ret=dynamic_cast(domClone.get()); \ if (ret) { \ domClone.release(); \ @@ -369,10 +418,10 @@ * @param linkage linkage specifier for the class * @param cname the name of the XMLObject specialization * @param proper the proper name to label the element's content + * @param desc documentation for class */ #define DECL_XMLOBJECT_SIMPLE(linkage,cname,proper,desc) \ - XMLTOOLING_DOXYGEN(desc) \ - BEGIN_XMLOBJECT(linkage,cname,XMLObject); \ + BEGIN_XMLOBJECT(linkage,cname,xmltooling::XMLObject,desc); \ DECL_XMLOBJECT_CONTENT(proper); \ END_XMLOBJECT @@ -387,20 +436,20 @@ #define DECL_XMLOBJECTIMPL_SIMPLE(linkage,cname,proper) \ class linkage cname##Impl \ : public cname, \ - public AbstractDOMCachingXMLObject, \ - public AbstractValidatingXMLObject, \ - public AbstractXMLObjectMarshaller, \ - public AbstractXMLObjectUnmarshaller \ + public xmltooling::AbstractDOMCachingXMLObject, \ + public xmltooling::AbstractValidatingXMLObject, \ + public xmltooling::AbstractXMLObjectMarshaller, \ + public xmltooling::AbstractXMLObjectUnmarshaller \ { \ public: \ virtual ~cname##Impl() {} \ cname##Impl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) \ - : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_##proper(NULL) { \ + : xmltooling::AbstractXMLObject(nsURI, localName, prefix, schemaType), m_##proper(NULL) { \ } \ cname##Impl(const cname##Impl& src) \ - : AbstractXMLObject(src), \ - AbstractDOMCachingXMLObject(src), \ - AbstractValidatingXMLObject(src), \ + : xmltooling::AbstractXMLObject(src), \ + xmltooling::AbstractDOMCachingXMLObject(src), \ + xmltooling::AbstractValidatingXMLObject(src), \ m_##proper(XMLString::replicate(src.m_##proper)) { \ } \ IMPL_XMLOBJECT_CLONE(cname) \ @@ -427,7 +476,7 @@ return buildObject(namespaceURI,cname::LOCAL_NAME,namespacePrefix); \ } \ virtual cname* buildObject( \ - const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL \ + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL \ ) const /** @@ -467,17 +516,17 @@ * @param cname the base name of the Validator specialization */ #define BEGIN_XMLOBJECTVALIDATOR(linkage,cname) \ - class linkage cname##SchemaValidator : public Validator \ + class linkage cname##SchemaValidator : public xmltooling::Validator \ { \ public: \ virtual ~cname##SchemaValidator() {} \ virtual cname##SchemaValidator* clone() const { \ return new cname##SchemaValidator(); \ } \ - virtual void validate(const XMLObject* xmlObject) const { \ + virtual void validate(const xmltooling::XMLObject* xmlObject) const { \ const cname* ptr=dynamic_cast(xmlObject); \ if (!ptr) \ - throw ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name())) + throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name())) /** * Ends the declaration of a Validator specialization. @@ -492,7 +541,7 @@ #define XMLOBJECTVALIDATOR_CHECKTYPE(cname) \ const cname* ptr=dynamic_cast(xmlObject); \ if (!ptr) \ - throw ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name())) + throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name())) /** * Validator code that checks for a required attribute, content, or singleton. @@ -502,7 +551,7 @@ */ #define XMLOBJECTVALIDATOR_REQUIRE(cname,proper) \ if (!ptr->get##proper()) \ - throw ValidationException(#cname" must have "#proper".") + throw xmltooling::ValidationException(#cname" must have "#proper".") /** * Validator code that checks for one of a pair of @@ -514,7 +563,7 @@ */ #define XMLOBJECTVALIDATOR_ONEOF(cname,proper1,proper2) \ if (!ptr->get##proper1() && !ptr->get##proper2()) \ - throw ValidationException(#cname" must have "#proper1" or "#proper2".") + throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2".") /** * Validator code that checks for one of a set of three @@ -527,7 +576,7 @@ */ #define XMLOBJECTVALIDATOR_ONEOF3(cname,proper1,proper2,proper3) \ if (!ptr->get##proper1() && !ptr->get##proper2() && !ptr->get##proper3()) \ - throw ValidationException(#cname" must have "#proper1", "#proper2", or "#proper3".") + throw xmltooling::ValidationException(#cname" must have "#proper1", "#proper2", or "#proper3".") /** * Validator code that checks a co-constraint (if one present, the other must be) @@ -539,7 +588,7 @@ */ #define XMLOBJECTVALIDATOR_NONEORBOTH(cname,proper1,proper2) \ if ((ptr->get##proper1() && !ptr->get##proper2()) || (!ptr->get##proper1() && ptr->get##proper2())) \ - throw ValidationException(#cname" cannot have "#proper1" without "#proper2".") + throw xmltooling::ValidationException(#cname" cannot have "#proper1" without "#proper2".") /** * Validator code that checks for a non-empty collection. @@ -549,7 +598,7 @@ */ #define XMLOBJECTVALIDATOR_NONEMPTY(cname,proper) \ if (ptr->get##proper##s().empty()) \ - throw ValidationException(#cname" must have at least one "#proper".") + throw xmltooling::ValidationException(#cname" must have at least one "#proper".") /** * Declares/defines a Validator specialization that checks object type and @@ -566,6 +615,10 @@ #include +/** + * @namespace xmltooling + * Public namespace of XML Tooling library + */ namespace xmltooling { /** diff --git a/xmltooling/io/AbstractXMLObjectMarshaller.cpp b/xmltooling/io/AbstractXMLObjectMarshaller.cpp index e0f7856..a17476e 100644 --- a/xmltooling/io/AbstractXMLObjectMarshaller.cpp +++ b/xmltooling/io/AbstractXMLObjectMarshaller.cpp @@ -35,6 +35,7 @@ #include #include +using namespace xmlsignature; using namespace xmltooling; using namespace log4cpp; using namespace std; diff --git a/xmltooling/signature/KeyInfo.h b/xmltooling/signature/KeyInfo.h index 786c792..a3b21f0 100644 --- a/xmltooling/signature/KeyInfo.h +++ b/xmltooling/signature/KeyInfo.h @@ -33,9 +33,9 @@ #include #define DECL_XMLSIGOBJECTBUILDER(cname) \ - DECL_XMLOBJECTBUILDER(XMLTOOL_API,cname,XMLConstants::XMLSIG_NS,XMLConstants::XMLSIG_PREFIX) + DECL_XMLOBJECTBUILDER(XMLTOOL_API,cname,xmltooling::XMLConstants::XMLSIG_NS,xmltooling::XMLConstants::XMLSIG_PREFIX) -namespace xmltooling { +namespace xmlsignature { DECL_XMLOBJECT_SIMPLE(XMLTOOL_API,KeyName,Name,XML Digital Signature version 20020212 KeyName element); DECL_XMLOBJECT_SIMPLE(XMLTOOL_API,MgmtData,Data,XML Digital Signature version 20020212 MgmtData element); @@ -48,11 +48,9 @@ namespace xmltooling { DECL_XMLOBJECT_SIMPLE(XMLTOOL_API,G,Value,XML Digital Signature version 20020212 G element); DECL_XMLOBJECT_SIMPLE(XMLTOOL_API,Y,Value,XML Digital Signature version 20020212 Y element); DECL_XMLOBJECT_SIMPLE(XMLTOOL_API,J,Value,XML Digital Signature version 20020212 J element); + DECL_XMLOBJECT_SIMPLE(XMLTOOL_API,XPath,Expression,XML Digital Signature version 20020212 XPath element); - /** - * XML Digital Signature version 20020212 DSAKeyValue element. - */ - BEGIN_XMLOBJECT(XMLTOOL_API,DSAKeyValue,XMLObject); + BEGIN_XMLOBJECT(XMLTOOL_API,DSAKeyValue,xmltooling::XMLObject,XML Digital Signature version 20020212 DSAKeyValue element); DECL_XMLOBJECT_CHILD(P); DECL_XMLOBJECT_CHILD(Q); DECL_XMLOBJECT_CHILD(G); @@ -64,20 +62,14 @@ namespace xmltooling { static const XMLCh TYPE_NAME[]; END_XMLOBJECT; - /** - * XML Digital Signature version 20020212 RSAKeyValue element. - */ - BEGIN_XMLOBJECT(XMLTOOL_API,RSAKeyValue,XMLObject); + BEGIN_XMLOBJECT(XMLTOOL_API,RSAKeyValue,xmltooling::XMLObject,XML Digital Signature version 20020212 RSAKeyValue element); DECL_XMLOBJECT_CHILD(Modulus); DECL_XMLOBJECT_CHILD(Exponent); /** RSAKeyValueType local name */ static const XMLCh TYPE_NAME[]; END_XMLOBJECT; - /** - * XML Digital Signature version 20020212 KeyValue element. - */ - BEGIN_XMLOBJECT(XMLTOOL_API,KeyValue,XMLObject); + BEGIN_XMLOBJECT(XMLTOOL_API,KeyValue,xmltooling::XMLObject,XML Digital Signature version 20020212 KeyValue element); DECL_XMLOBJECT_CHILD(DSAKeyValue); DECL_XMLOBJECT_CHILD(RSAKeyValue); DECL_XMLOBJECT_CHILD(XMLObject); @@ -86,10 +78,20 @@ namespace xmltooling { static const XMLCh TYPE_NAME[]; END_XMLOBJECT; - /** - * XML Digital Signature version 20020212 KeyInfo element. - */ - BEGIN_XMLOBJECT(XMLTOOL_API,KeyInfo,ElementProxy); + BEGIN_XMLOBJECT(XMLTOOL_API,Transform,xmltooling::ElementProxy,XML Digital Signature version 20020212 Transform element); + DECL_XMLOBJECT_ATTRIB(Algorithm,ALGORITHM); + DECL_XMLOBJECT_CHILDREN(XPath); + /** TransformType local name */ + static const XMLCh TYPE_NAME[]; + END_XMLOBJECT; + + BEGIN_XMLOBJECT(XMLTOOL_API,Transforms,xmltooling::XMLObject,XML Digital Signature version 20020212 Transforms element); + DECL_XMLOBJECT_CHILDREN(Transform); + /** TransformsType local name */ + static const XMLCh TYPE_NAME[]; + END_XMLOBJECT; + + BEGIN_XMLOBJECT(XMLTOOL_API,KeyInfo,xmltooling::ElementProxy,XML Digital Signature version 20020212 KeyInfo element); DECL_XMLOBJECT_ATTRIB(Id,ID); DECL_XMLOBJECT_CHILDREN(KeyName); DECL_XMLOBJECT_CHILDREN(MgmtData); @@ -97,6 +99,9 @@ namespace xmltooling { static const XMLCh TYPE_NAME[]; END_XMLOBJECT; + DECL_XMLSIGOBJECTBUILDER(XPath); + DECL_XMLSIGOBJECTBUILDER(Transform); + DECL_XMLSIGOBJECTBUILDER(Transforms); DECL_XMLSIGOBJECTBUILDER(KeyName); DECL_XMLSIGOBJECTBUILDER(MgmtData); DECL_XMLSIGOBJECTBUILDER(Modulus); @@ -125,6 +130,7 @@ namespace xmltooling { XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,G,Value); XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,Y,Value); XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,J,Value); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,XPath,Expression); BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,RSAKeyValue); XMLOBJECTVALIDATOR_REQUIRE(RSAKeyValue,Modulus); @@ -141,6 +147,14 @@ namespace xmltooling { XMLOBJECTVALIDATOR_ONEOF3(KeyValue,DSAKeyValue,RSAKeyValue,XMLObject); END_XMLOBJECTVALIDATOR; + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,Transform); + XMLOBJECTVALIDATOR_REQUIRE(Transform,Algorithm); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,Transforms); + XMLOBJECTVALIDATOR_NONEMPTY(Transforms,Transform); + END_XMLOBJECTVALIDATOR; + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,KeyInfo); XMLOBJECTVALIDATOR_NONEMPTY(KeyInfo,XMLObject); END_XMLOBJECTVALIDATOR; diff --git a/xmltooling/signature/Signature.h b/xmltooling/signature/Signature.h index 707ad2c..717fa74 100644 --- a/xmltooling/signature/Signature.h +++ b/xmltooling/signature/Signature.h @@ -27,14 +27,18 @@ #include #include -namespace xmltooling { +/** + * @namespace xmlsignature + * Public namespace of XML Signature classes + */ +namespace xmlsignature { /** * XMLObject representing XML Digital Signature, version 20020212, Signature element. * The default signature settings include Exclusive c14n w/o comments, SHA-1 digests, * and RSA-SHA1 signing. */ - class XMLTOOL_API Signature : public virtual XMLObject + class XMLTOOL_API Signature : public virtual xmltooling::XMLObject { public: virtual ~Signature() {} @@ -79,11 +83,11 @@ namespace xmltooling { /** * Builder for Signature objects. */ - class XMLTOOL_API SignatureBuilder : public XMLObjectBuilder + class XMLTOOL_API SignatureBuilder : public xmltooling::XMLObjectBuilder { public: virtual Signature* buildObject( - const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL ) const; /** diff --git a/xmltooling/signature/SigningContext.h b/xmltooling/signature/SigningContext.h index 2e6d249..af2e7f4 100644 --- a/xmltooling/signature/SigningContext.h +++ b/xmltooling/signature/SigningContext.h @@ -31,7 +31,7 @@ #pragma warning( disable : 4250 4251 ) #endif -namespace xmltooling { +namespace xmlsignature { /** * Interface to signing process supplied by a signing application diff --git a/xmltooling/signature/VerifyingContext.h b/xmltooling/signature/VerifyingContext.h index 9dfe2cb..7e0e436 100644 --- a/xmltooling/signature/VerifyingContext.h +++ b/xmltooling/signature/VerifyingContext.h @@ -25,7 +25,7 @@ #include -namespace xmltooling { +namespace xmlsignature { /** * Interface to signature verification process supplied by a relying party diff --git a/xmltooling/signature/impl/KeyInfoImpl.cpp b/xmltooling/signature/impl/KeyInfoImpl.cpp index ee095f6..746cd0a 100644 --- a/xmltooling/signature/impl/KeyInfoImpl.cpp +++ b/xmltooling/signature/impl/KeyInfoImpl.cpp @@ -31,6 +31,7 @@ #include +using namespace xmlsignature; using namespace xmltooling; using namespace std; @@ -39,7 +40,7 @@ using namespace std; #pragma warning( disable : 4250 4251 ) #endif -namespace xmltooling { +namespace xmlsignature { class XMLTOOL_DLLLOCAL DSAKeyValueImpl : public DSAKeyValue, public AbstractDOMCachingXMLObject, @@ -219,7 +220,104 @@ namespace xmltooling { throw UnmarshallingException("Invalid child element: $1",params(1,childXMLObject->getElementQName().toString().c_str())); } }; - + + class XMLTOOL_DLLLOCAL TransformImpl : public Transform, + public AbstractDOMCachingXMLObject, + public AbstractElementProxy, + public AbstractValidatingXMLObject, + public AbstractXMLObjectMarshaller, + public AbstractXMLObjectUnmarshaller + { + public: + virtual ~TransformImpl() {} + + TransformImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) + : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_Algorithm(NULL) { + } + + TransformImpl(const TransformImpl& src) + : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), AbstractElementProxy(src), + AbstractValidatingXMLObject(src), m_Algorithm(XMLString::replicate(src.m_Algorithm)) { + for (list::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) { + if (*i) { + XPath* x=dynamic_cast(*i); + if (x) { + getXPaths().push_back(x->cloneXPath()); + continue; + } + getXMLObjects().push_back((*i)->clone()); + } + } + } + + IMPL_XMLOBJECT_CLONE(Transform); + IMPL_XMLOBJECT_ATTRIB(Algorithm); + IMPL_XMLOBJECT_CHILDREN(XPath,m_children.end()); + + protected: + void marshallAttributes(DOMElement* domElement) const { + MARSHALL_XMLOBJECT_ATTRIB(Algorithm,ALGORITHM,NULL); + } + + void marshallElementContent(DOMElement* domElement) const { + if(getTextContent()) { + domElement->appendChild(domElement->getOwnerDocument()->createTextNode(getTextContent())); + } + } + + void processElementContent(const XMLCh* elementContent) { + setTextContent(elementContent); + } + + void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { + PROC_XMLOBJECT_CHILDREN(XPath,XMLConstants::XMLSIG_NS); + + // Unknown child. + const XMLCh* nsURI=root->getNamespaceURI(); + if (!XMLString::equals(nsURI,XMLConstants::XMLSIG_NS) && nsURI && *nsURI) + getXMLObjects().push_back(childXMLObject); + + throw UnmarshallingException("Invalid child element: $1",params(1,childXMLObject->getElementQName().toString().c_str())); + } + + void processAttribute(const DOMAttr* attribute) { + PROC_XMLOBJECT_ATTRIB(Algorithm,ALGORITHM,NULL); + } + }; + + class XMLTOOL_DLLLOCAL TransformsImpl : public Transforms, + public AbstractDOMCachingXMLObject, + public AbstractValidatingXMLObject, + public AbstractXMLObjectMarshaller, + public AbstractXMLObjectUnmarshaller + { + public: + virtual ~TransformsImpl() {} + + TransformsImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) + : AbstractXMLObject(nsURI, localName, prefix, schemaType) { + } + + TransformsImpl(const TransformsImpl& src) + : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), AbstractValidatingXMLObject(src) { + VectorOf(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_XMLOBJECT_CLONE(Transforms); + IMPL_XMLOBJECT_CHILDREN(Transform,m_children.end()); + + protected: + void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { + PROC_XMLOBJECT_CHILDREN(Transform,XMLConstants::XMLSIG_NS); + throw UnmarshallingException("Invalid child element: $1",params(1,childXMLObject->getElementQName().toString().c_str())); + } + }; + class XMLTOOL_DLLLOCAL KeyInfoImpl : public KeyInfo, public AbstractDOMCachingXMLObject, public AbstractElementProxy, @@ -267,10 +365,7 @@ namespace xmltooling { protected: void marshallAttributes(DOMElement* domElement) const { - if(getId()) { - domElement->setAttributeNS(NULL, ID_ATTRIB_NAME, getId()); - domElement->setIdAttributeNS(NULL, ID_ATTRIB_NAME); - } + MARSHALL_XMLOBJECT_ID_ATTRIB(Id,ID,NULL); } void marshallElementContent(DOMElement* domElement) const { @@ -297,10 +392,7 @@ namespace xmltooling { } void processAttribute(const DOMAttr* attribute) { - if (XMLHelper::isNodeNamed(attribute, NULL, ID_ATTRIB_NAME)) { - setId(attribute->getValue()); - static_cast(attribute->getParentNode())->setIdAttributeNode(attribute); - } + PROC_XMLOBJECT_ID_ATTRIB(Id,ID,NULL); } }; @@ -315,6 +407,7 @@ namespace xmltooling { DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,G,Value); DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,Y,Value); DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,J,Value); + DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,XPath,Expression); }; #if defined (_MSC_VER) @@ -323,6 +416,9 @@ namespace xmltooling { // Builder Implementations +IMPL_XMLOBJECTBUILDER(XPath); +IMPL_XMLOBJECTBUILDER(Transform); +IMPL_XMLOBJECTBUILDER(Transforms); IMPL_XMLOBJECTBUILDER(KeyName); IMPL_XMLOBJECTBUILDER(MgmtData); IMPL_XMLOBJECTBUILDER(Modulus); @@ -359,3 +455,9 @@ const XMLCh Q::LOCAL_NAME[] = UNICODE_LITERAL_1(Q); const XMLCh G::LOCAL_NAME[] = UNICODE_LITERAL_1(G); const XMLCh Y::LOCAL_NAME[] = UNICODE_LITERAL_1(Y); const XMLCh J::LOCAL_NAME[] = UNICODE_LITERAL_1(J); +const XMLCh XPath::LOCAL_NAME[] = UNICODE_LITERAL_5(X,P,a,t,h); +const XMLCh Transform::LOCAL_NAME[] = UNICODE_LITERAL_9(T,r,a,n,s,f,o,r,m); +const XMLCh Transform::TYPE_NAME[] = UNICODE_LITERAL_13(T,r,a,n,s,f,o,r,m,T,y,p,e); +const XMLCh Transform::ALGORITHM_ATTRIB_NAME[] = UNICODE_LITERAL_9(A,l,g,o,r,i,t,h,m); +const XMLCh Transforms::LOCAL_NAME[] = UNICODE_LITERAL_10(T,r,a,n,s,f,o,r,m,s); +const XMLCh Transforms::TYPE_NAME[] = UNICODE_LITERAL_14(T,r,a,n,s,f,o,r,m,s,T,y,p,e); diff --git a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp index b561814..adc8df5 100644 --- a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp +++ b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp @@ -36,6 +36,7 @@ #include #include +using namespace xmlsignature; using namespace xmltooling; using namespace log4cpp; using namespace std; @@ -45,7 +46,7 @@ using namespace std; #pragma warning( disable : 4250 4251 ) #endif -namespace xmltooling { +namespace xmlsignature { class XMLTOOL_DLLLOCAL XMLSecSignatureImpl : public UnknownElementImpl, public virtual Signature { diff --git a/xmltoolingtest/XMLObjectBaseTestCase.h b/xmltoolingtest/XMLObjectBaseTestCase.h index ee5fa88..6371026 100644 --- a/xmltoolingtest/XMLObjectBaseTestCase.h +++ b/xmltoolingtest/XMLObjectBaseTestCase.h @@ -31,6 +31,7 @@ #include #include +using namespace xmlsignature; using namespace xmltooling; using namespace std; -- 2.1.4