Add XMLEnc 1.1 constants and MGF supporting code 1.5.0
authorScott Cantor <cantor.2@osu.edu>
Wed, 1 Aug 2012 04:09:47 +0000 (04:09 +0000)
committerScott Cantor <cantor.2@osu.edu>
Wed, 1 Aug 2012 04:09:47 +0000 (04:09 +0000)
xmltooling/encryption/Encryption.h
xmltooling/encryption/impl/EncryptionImpl.cpp
xmltooling/encryption/impl/EncryptionSchemaValidators.cpp
xmltooling/util/XMLConstants.cpp
xmltooling/util/XMLConstants.h

index 934088b..33c5e12 100644 (file)
@@ -48,6 +48,14 @@ namespace xmlsignature {
     DECL_XMLOBJECTBUILDER(XMLTOOL_API,cname,xmlconstants::XMLENC_NS,xmlconstants::XMLENC_PREFIX)
 
 /**
+ * Macro for declaring encryption 1.1 builders.
+ * 
+ * @param cname name of class being built
+ */
+#define DECL_XMLENC11OBJECTBUILDER(cname) \
+    DECL_XMLOBJECTBUILDER(XMLTOOL_API,cname,xmlconstants::XMLENC11_NS,xmlconstants::XMLENC11_PREFIX)
+
+/**
  * @namespace xmlencryption
  * Namespace for XML Encryption schema objects
  */
@@ -146,6 +154,12 @@ namespace xmlencryption {
         static const XMLCh TYPE_NAME[];
     END_XMLOBJECT;
 
+    BEGIN_XMLOBJECT(XMLTOOL_API,MGF,xmltooling::XMLObject,XML Encryption 1.1 MGF element);
+        DECL_STRING_ATTRIB(Algorithm,ALGORITHM);
+        /** MGFType local name */
+        static const XMLCh TYPE_NAME[];
+    END_XMLOBJECT;
+
     DECL_XMLENCOBJECTBUILDER(CarriedKeyName);
     DECL_XMLENCOBJECTBUILDER(CipherData);
     DECL_XMLENCOBJECTBUILDER(CipherReference);
@@ -162,6 +176,8 @@ namespace xmlencryption {
     DECL_XMLENCOBJECTBUILDER(ReferenceList);
     DECL_XMLENCOBJECTBUILDER(Transforms);
 
+    DECL_XMLENC11OBJECTBUILDER(MGF);
+
     /**
      * Registers builders and validators for XML Encryption classes into the runtime.
      */
index 9e766e2..84b213c 100644 (file)
@@ -636,6 +636,46 @@ namespace xmlencryption {
         }
     };
 
+    class XMLTOOL_DLLLOCAL MGFImpl : public virtual MGF,
+        public AbstractSimpleElement,
+        public AbstractDOMCachingXMLObject,
+        public AbstractXMLObjectMarshaller,
+        public AbstractXMLObjectUnmarshaller
+    {
+        void init() {
+            m_Algorithm = nullptr;
+        }
+
+    public:
+        virtual ~MGFImpl() {
+            XMLString::release(&m_Algorithm);
+        }
+
+        MGFImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType)
+                : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
+            init();
+        }
+            
+        MGFImpl(const MGFImpl& src)
+                : AbstractXMLObject(src), AbstractSimpleElement(src), AbstractDOMCachingXMLObject(src) {
+            init();
+            IMPL_CLONE_ATTRIB(Algorithm);
+        }
+        
+        IMPL_XMLOBJECT_CLONE(MGF);
+        IMPL_STRING_ATTRIB(Algorithm);
+
+    protected:
+        void marshallAttributes(DOMElement* domElement) const {
+            MARSHALL_STRING_ATTRIB(Algorithm,ALGORITHM,nullptr);
+        }
+
+        void processAttribute(const DOMAttr* attribute) {
+            PROC_STRING_ATTRIB(Algorithm,ALGORITHM,nullptr);
+            AbstractXMLObjectUnmarshaller::processAttribute(attribute);
+        }
+    };
+
 };
 
 #if defined (_MSC_VER)
@@ -660,6 +700,8 @@ IMPL_XMLOBJECTBUILDER(OAEPparams);
 IMPL_XMLOBJECTBUILDER(ReferenceList);
 IMPL_XMLOBJECTBUILDER(Transforms);
 
+IMPL_XMLOBJECTBUILDER(MGF);
+
 // Unicode literals
 
 const XMLCh CarriedKeyName::LOCAL_NAME[] =              UNICODE_LITERAL_14(C,a,r,r,i,e,d,K,e,y,N,a,m,e);
@@ -700,3 +742,7 @@ const XMLCh ReferenceType::TYPE_NAME[] =                UNICODE_LITERAL_13(R,e,f
 const XMLCh ReferenceType::URI_ATTRIB_NAME[] =          UNICODE_LITERAL_3(U,R,I);
 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);
+
+const XMLCh MGF::LOCAL_NAME[] =                         UNICODE_LITERAL_3(M,G,F);
+const XMLCh MGF::TYPE_NAME[] =                          UNICODE_LITERAL_7(M,G,F,T,y,p,e);
+const XMLCh MGF::ALGORITHM_ATTRIB_NAME[] =              UNICODE_LITERAL_9(A,l,g,o,r,i,t,h,m);
\ No newline at end of file
index ed781e6..c301214 100644 (file)
@@ -34,6 +34,7 @@ using namespace xmlencryption;
 using namespace xmltooling;
 using namespace std;
 using xmlconstants::XMLENC_NS;
+using xmlconstants::XMLENC11_NS;
 
 namespace xmlencryption {
 
@@ -112,7 +113,11 @@ namespace xmlencryption {
     BEGIN_XMLOBJECTVALIDATOR_SUB(XMLTOOL_DLLLOCAL,EncryptedKey,EncryptedType);
         EncryptedTypeSchemaValidator::validate(xmlObject);
     END_XMLOBJECTVALIDATOR;
-    
+
+    BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,MGF);
+        XMLOBJECTVALIDATOR_REQUIRE(MGF,Algorithm);
+    END_XMLOBJECTVALIDATOR;
+
 };
 
 #define REGISTER_ELEMENT(namespaceURI,cname) \
@@ -149,4 +154,7 @@ void xmlencryption::registerEncryptionClasses()
     REGISTER_TYPE(XMLENC_NS,EncryptionProperties);
     REGISTER_TYPE(XMLENC_NS,EncryptionProperty);
     REGISTER_TYPE(XMLENC_NS,Transforms);
+
+    REGISTER_ELEMENT(XMLENC11_NS,MGF);
+    REGISTER_TYPE(XMLENC11_NS,MGF);
 }
index 66d5de9..682e0dc 100644 (file)
@@ -95,6 +95,15 @@ const XMLCh xmlconstants::XMLENC_NS[] = // http://www.w3.org/2001/04/xmlenc#
 
 const XMLCh xmlconstants::XMLENC_PREFIX[] = { chLatin_x, chLatin_e, chLatin_n, chLatin_c, chNull };
 
+const XMLCh xmlconstants::XMLENC11_NS[] = // http://www.w3.org/2009/xmlenc11#
+{ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,
+  chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w, chDigit_3, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash,
+  chDigit_2, chDigit_0, chDigit_0, chDigit_9, chForwardSlash,
+  chLatin_x, chLatin_m, chLatin_l, chLatin_e, chLatin_n, chLatin_c, chDigit_1, chDigit_1, chPound, chNull
+};
+
+const XMLCh xmlconstants::XMLENC11_PREFIX[] = { chLatin_x, chLatin_e, chLatin_n, chLatin_c, chDigit_1, chDigit_1, chNull };
+
 const XMLCh xmlconstants::SOAP11ENV_NS[] = // http://schemas.xmlsoap.org/soap/envelope/
 { chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,
   chLatin_s, chLatin_c, chLatin_h, chLatin_e, chLatin_m, chLatin_a, chLatin_s, chPeriod,
index 961f0de..aef4e59 100644 (file)
@@ -65,10 +65,10 @@ namespace xmlconstants {
     /**  XML Signature QName prefix ("ds") */
     extern XMLTOOL_API const XMLCh XMLSIG_PREFIX[];
 
-    /**  XML Signature namespace ("http://www.w3.org/2009/xmldsig11#") */
+    /**  XML Signature 1.1 namespace ("http://www.w3.org/2009/xmldsig11#") */
     extern XMLTOOL_API const XMLCh XMLSIG11_NS[];
 
-    /**  XML Signature QName prefix ("ds11") */
+    /**  XML Signature 1.1 QName prefix ("ds11") */
     extern XMLTOOL_API const XMLCh XMLSIG11_PREFIX[];
     
     /**  XML Encryption namespace ("http://www.w3.org/2001/04/xmlenc#") */
@@ -77,6 +77,12 @@ namespace xmlconstants {
     /**  XML Encryption QName prefix ("xenc") */
     extern XMLTOOL_API const XMLCh XMLENC_PREFIX[];
     
+    /**  XML Encryption 1.1 namespace ("http://www.w3.org/2009/xmlenc11#") */
+    extern XMLTOOL_API const XMLCh XMLENC11_NS[];
+    
+    /**  XML Encryption 1.1 QName prefix ("xenc11") */
+    extern XMLTOOL_API const XMLCh XMLENC11_PREFIX[];
+
     /**  SOAP 1.1 Envelope XML namespace ("http://schemas.xmlsoap.org/soap/envelope/") */
     extern XMLTOOL_API const XMLCh SOAP11ENV_NS[];