Refactored Signature signing/validation, various Validator bugs fixed.
[shibboleth/cpp-xmltooling.git] / xmltooling / signature / Signature.h
index 3dba1b4..14549ec 100644 (file)
 \r
 #include <xmltooling/exceptions.h>\r
 #include <xmltooling/XMLObjectBuilder.h>\r
-#include <xmltooling/signature/SigningContext.h>\r
-#include <xmltooling/signature/VerifyingContext.h>\r
+#include <xmltooling/signature/KeyInfo.h>\r
+#include <xmltooling/signature/ContentReference.h>\r
+#include <xmltooling/validation/ValidatingXMLObject.h>\r
 #include <xmltooling/util/XMLConstants.h>\r
 \r
+#include <xsec/dsig/DSIGSignature.hpp>\r
+\r
 /**\r
  * @namespace xmlsignature\r
  * Public namespace of XML Signature classes\r
@@ -40,7 +43,7 @@ namespace xmlsignature {
      * The default signature settings include Exclusive c14n w/o comments, SHA-1 digests,\r
      * and RSA-SHA1 signing. \r
      */\r
-    class XMLTOOL_API Signature : public virtual xmltooling::XMLObject\r
+    class XMLTOOL_API Signature : public virtual xmltooling::ValidatingXMLObject\r
     {\r
     public:\r
         virtual ~Signature() {}\r
@@ -61,24 +64,68 @@ namespace xmlsignature {
          * @param sm    the signature algorithm\r
          */\r
         virtual void setSignatureAlgorithm(const XMLCh* sm)=0;\r
-        \r
+\r
         /**\r
-         * Applies an XML signature based on the supplied context.\r
+         * Sets the signing key used to create the signature.\r
          * \r
-         * @param ctx   the signing context that determines the signature's content\r
-         * @throws SignatureException   thrown if the signing operation fails\r
+         * @param signingKey the secret/private key used to create the signature\r
          */\r
-        virtual void sign(SigningContext& ctx)=0;\r
-        \r
+        virtual void setSigningKey(XSECCryptoKey* signingKey)=0;\r
+\r
+        /**\r
+         * Sets a KeyInfo object to embed in the Signature.\r
+         * \r
+         * @param keyInfo   pointer to a KeyInfo object, or NULL\r
+         */\r
+        virtual void setKeyInfo(KeyInfo* keyInfo)=0;\r
+\r
+        /**\r
+         * Gets the KeyInfo object associated with the Signature.\r
+         * This is <strong>NOT</strong> provided for access to the\r
+         * data associated with an unmarshalled signature. It is\r
+         * used only in the creation of signatures. Access to data\r
+         * for validation purposes is provided through the native\r
+         * DSIGSignature object.\r
+         * \r
+         * @return  pointer to a KeyInfo object, or NULL\r
+         */\r
+        virtual KeyInfo* getKeyInfo() const=0;\r
+\r
         /**\r
-         * Verifies an XML signature based on the supplied context.\r
+         * Sets the ContentReference object to the Signature to be applied\r
+         * when the signature is created.\r
          * \r
-         * @param ctx   the verifying context that validates the signature's content\r
-         * @throws SignatureException   thrown if the verifying operation fails\r
+         * @param reference the reference to attach, or NULL \r
          */\r
-        virtual void verify(const VerifyingContext& ctx) const=0;\r
+        virtual void setContentReference(ContentReference* reference)=0;\r
+\r
+        /**\r
+         * Gets the ContentReference object associated with the Signature.\r
+         * This is <strong>NOT</strong> provided for access to the\r
+         * data associated with an unmarshalled signature. It is\r
+         * used only in the creation of signatures. Access to data\r
+         * for validation purposes is provided through the native\r
+         * DSIGSignature object.\r
+         * \r
+         * @return  pointer to a ContentReference object, or NULL\r
+         */\r
+        virtual ContentReference* getContentReference() const=0;\r
+\r
         \r
         /**\r
+         * Gets the native Apache signature object, if present.\r
+         * \r
+         * @return  the native Apache signature interface\r
+         */\r
+        virtual DSIGSignature* getXMLSignature() const=0;\r
+\r
+        /**\r
+         * Compute and append the signature based on the assigned\r
+         * ContentReference, KeyInfo, and signing key.\r
+         */\r
+        virtual void sign()=0;\r
+\r
+        /**\r
          * Type-safe clone operation.\r
          * \r
          * @return  copy of object\r
@@ -106,7 +153,7 @@ namespace xmlsignature {
          */\r
         virtual Signature* buildObject() const;\r
 \r
-        static Signature* newSignature() {\r
+        static Signature* buildSignature() {\r
             const SignatureBuilder* b = dynamic_cast<const SignatureBuilder*>(\r
                 xmltooling::XMLObjectBuilder::getBuilder(\r
                     xmltooling::QName(xmltooling::XMLConstants::XMLSIG_NS,Signature::LOCAL_NAME)\r