Major revamp of credential and trust handling code, PKIX engine still needs work.
[shibboleth/cpp-xmltooling.git] / xmltooling / signature / Signature.h
index 71314ac..d26ccb8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2006 Internet2
+ *  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.
@@ -122,8 +122,10 @@ namespace xmlsignature {
         /**
          * Compute and append the signature based on the assigned
          * ContentReference, KeyInfo, and signing key.
+         *
+         * @param credential    optional source of signing key and KeyInfo
          */
-        virtual void sign()=0;
+        virtual void sign(const xmltooling::Credential* credential=NULL)=0;
 
         /**
          * Type-safe clone operation.
@@ -132,6 +134,51 @@ namespace xmlsignature {
          */
         virtual Signature* cloneSignature() const=0;
 
+        /**
+         * Sign the input data and return a base64-encoded signature. The signature value
+         * <strong>MUST NOT</strong> contain any embedded linefeeds.
+         * 
+         * <p>Allows specialized applications to create raw signatures over any input using
+         * the same cryptography layer as XML Signatures use. 
+         * 
+         * @param key               key to sign with, will <strong>NOT</strong> be freed
+         * @param sigAlgorithm      XML signature algorithm identifier
+         * @param in                input data
+         * @param in_len            size of input data in bytes
+         * @param out               output buffer
+         * @param out_len           size of output buffer in bytes
+         * @return  size in bytes of base64-encoded signature
+         */
+        static unsigned int createRawSignature(
+            XSECCryptoKey* key,
+            const XMLCh* sigAlgorithm,
+            const char* in,
+            unsigned int in_len,
+            char* out,
+            unsigned int out_len
+            );
+         
+        /**
+         * Verifies a base-64 encoded signature over the input data.
+         * 
+         * <p>Allows specialized applications to verify raw signatures over any input using
+         * the same cryptography layer as XML Signatures use. 
+         * 
+         * @param key               key to verify with, will <strong>NOT</strong> be freed
+         * @param sigAlgorithm      XML signature algorithm identifier
+         * @param signature         base64-encoded signature value
+         * @param in                input data
+         * @param in_len            size of input data in bytes
+         * @return  true iff signature verifies
+         */
+        static bool verifyRawSignature(
+            XSECCryptoKey* key,
+            const XMLCh* sigAlgorithm,
+            const char* signature,
+            const char* in,
+            unsigned int in_len
+            );
+
     protected:
         Signature() {}
     };
@@ -142,7 +189,11 @@ namespace xmlsignature {
     class XMLTOOL_API SignatureBuilder : public xmltooling::XMLObjectBuilder
     {
     public:
+#ifdef HAVE_COVARIANT_RETURNS
         virtual Signature* buildObject(
+#else
+        virtual xmltooling::XMLObject* buildObject(
+#endif
             const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL
             ) const;
             
@@ -151,16 +202,25 @@ namespace xmlsignature {
          * 
          * @return empty Signature object
          */
+#ifdef HAVE_COVARIANT_RETURNS
         virtual Signature* buildObject() const;
-
+#else
+        virtual xmltooling::XMLObject* buildObject() const;
+#endif
+        /** Singleton builder. */
         static Signature* buildSignature() {
             const SignatureBuilder* b = dynamic_cast<const SignatureBuilder*>(
                 xmltooling::XMLObjectBuilder::getBuilder(
-                    xmltooling::QName(xmltooling::XMLConstants::XMLSIG_NS,Signature::LOCAL_NAME)
+                    xmltooling::QName(xmlconstants::XMLSIG_NS,Signature::LOCAL_NAME)
                     )
                 );
-            if (b)
+            if (b) {
+#ifdef HAVE_COVARIANT_RETURNS
                 return b->buildObject();
+#else
+                return dynamic_cast<Signature*>(b->buildObject());
+#endif
+            }
             throw xmltooling::XMLObjectException("Unable to obtain typed builder for Signature.");
         }
     };