Support alternate hash algorithms in helper routines.
[shibboleth/cpp-xmltooling.git] / xmltooling / security / SecurityHelper.h
index b62bdf5..e6cbee3 100644 (file)
 #if !defined(__xmltooling_sechelper_h__) && !defined(XMLTOOLING_NO_XMLSEC)
 #define __xmltooling_sechelper_h__
 
-#include <xmltooling/security/XSECCryptoX509CRL.h>
-#include <xmltooling/soap/SOAPTransport.h>
+#include <xmltooling/base.h>
 
+#include <string>
 #include <vector>
-#include <xsec/enc/XSECCryptoKey.hpp>
-#include <xsec/enc/XSECCryptoX509.hpp>
+
+class XSECCryptoKey;
+class XSECCryptoX509;
 
 namespace xmltooling {
+    class XMLTOOL_API Credential;
+    class XMLTOOL_API SOAPTransport;
+    class XMLTOOL_API XSECCryptoX509CRL;
+
     /**
      * A helper class for working with keys, certificates, etc.
      */
@@ -61,6 +66,7 @@ namespace xmltooling {
          * @param certs     array to populate with certificate(s)
          * @param pathname  path to file containing certificate(s)
          * @param format    optional constant identifying certificate encoding format
+         * @param password  optional password to decrypt certificate(s)
          * @return  size of the resulting array
          */
         static std::vector<XSECCryptoX509*>::size_type loadCertificatesFromFile(
@@ -97,6 +103,7 @@ namespace xmltooling {
          * @param transport object to use to acquire certificate(s)
          * @param backing   backing file for certificate(s) (written to or read from if download fails)
          * @param format    optional constant identifying certificate encoding format
+         * @param password  optional password to decrypt certificate(s)
          * @return  size of the resulting array
          */
         static std::vector<XSECCryptoX509*>::size_type loadCertificatesFromURL(
@@ -123,23 +130,40 @@ namespace xmltooling {
          * @param key2 second key to compare
          * @return  true iff the keys match
          */
-        static bool matches(const XSECCryptoKey* key1, const XSECCryptoKey* key2);
+        static bool matches(const XSECCryptoKey& key1, const XSECCryptoKey& key2);
+
+        /**
+         * Returns the base64-encoded DER encoding of a public key in SubjectPublicKeyInfo format.
+         *
+         * @param cred      the credential containing the key to encode
+         * @param hash      if true, the DER encoded data is hashed with SHA-1 before base64 encoding
+         * @param nowrap    if true, any linefeeds will be stripped from the result
+         * @param hashAlg   name of hash algorithm, syntax specific to crypto provider
+         * @return  the base64 encoded key value
+         */
+        static std::string getDEREncoding(const Credential& cred, bool hash=false, bool nowrap=true, const char* hashAlg="SHA1");
 
         /**
          * Returns the base64-encoded DER encoding of a public key in SubjectPublicKeyInfo format.
          *
-         * @param key   the key to encode
+         * @param key       the key to encode
+         * @param hash      if true, the DER encoded data is hashed with SHA-1 before base64 encoding
+         * @param nowrap    if true, any linefeeds will be stripped from the result
+         * @param hashAlg   name of hash algorithm, syntax specific to crypto provider
          * @return  the base64 encoded key value
          */
-        static std::string getDEREncoding(const XSECCryptoKey* key);
+        static std::string getDEREncoding(const XSECCryptoKey& key, bool hash=false, bool nowrap=true, const char* hashAlg="SHA1");
 
         /**
          * Returns the base64-encoded DER encoding of a certifiate's public key in SubjectPublicKeyInfo format.
          *
-         * @param cert   the certificate's key to encode
+         * @param cert      the certificate's key to encode
+         * @param hash      if true, the DER encoded data is hashed with SHA-1 before base64 encoding
+         * @param nowrap    if true, any linefeeds will be stripped from the result
+         * @param hashAlg   name of hash algorithm, syntax specific to crypto provider
          * @return  the base64 encoded key value
          */
-        static std::string getDEREncoding(const XSECCryptoX509* cert);
+        static std::string getDEREncoding(const XSECCryptoX509& cert, bool hash=false, bool nowrap=true, const char* hashAlg="SHA1");
     };
 };