Get Signer to take a PEM string rather than a filename.
[libdcp.git] / src / signer.cc
index a280cb07af0ff693fd15f306fca1dbe9ce31584a..a0d9912ad7974cef0c0a21a3e1a158a2bd38b0a0 100644 (file)
@@ -29,6 +29,7 @@
 #include <xmlsec/dl.h>
 #include <xmlsec/app.h>
 #include <xmlsec/crypto.h>
+#include "compose.hpp"
 
 using std::string;
 using std::list;
@@ -113,7 +114,10 @@ Signer::add_signature_value (xmlpp::Node* parent, string ns) const
                throw MiscError ("could not create signature context");
        }
 
-       signature_context->signKey = xmlSecCryptoAppKeyLoad (_key.string().c_str(), xmlSecKeyDataFormatPem, 0, 0, 0);
+       signature_context->signKey = xmlSecCryptoAppKeyLoadMemory (
+               reinterpret_cast<const unsigned char *> (_key.c_str()), _key.size(), xmlSecKeyDataFormatPem, 0, 0, 0
+               );
+       
        if (signature_context->signKey == 0) {
                throw FileError ("could not load private key file", _key, 0);
        }
@@ -123,8 +127,9 @@ Signer::add_signature_value (xmlpp::Node* parent, string ns) const
                throw MiscError ("could not set key name");
        }
 
-       if (xmlSecDSigCtxSign (signature_context, parent->cobj ()) < 0) {
-               throw MiscError ("could not sign");
+       int const r = xmlSecDSigCtxSign (signature_context, parent->cobj ());
+       if (r < 0) {
+               throw MiscError (String::compose ("could not sign (%1)", r));
        }
 
        xmlSecDSigCtxDestroy (signature_context);