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);
}
{
public:
/** @param c Certificate chain to sign with.
- * @param k Key to sign with.
+ * @param k Key to sign with as a PEM-format string.
*/
- Signer (CertificateChain c, boost::filesystem::path k)
+ Signer (CertificateChain c, std::string k)
: _certificates (c)
, _key (k)
{}
/** Certificate chain to sign with */
CertificateChain _certificates;
- /** Filename of signer key */
- boost::filesystem::path _key;
+ /** Key to sign with as a PEM-format string */
+ std::string _key;
};
}
trim (b);
return a == b;
}
+
+string
+dcp::file_to_string (boost::filesystem::path p)
+{
+ uintmax_t len = boost::filesystem::file_size (p);
+ char* c = new char[len];
+
+ FILE* f = fopen_boost (p, "r");
+ if (!f) {
+ return "";
+ }
+
+ fread (c, 1, len, f);
+ fclose (f);
+
+ string s (c);
+ delete[] c;
+
+ return s;
+}
extern int base64_decode (std::string const & in, unsigned char* out, int out_length);
extern boost::optional<boost::filesystem::path> relative_to_root (boost::filesystem::path root, boost::filesystem::path file);
extern FILE * fopen_boost (boost::filesystem::path, std::string);
+extern std::string file_to_string (boost::filesystem::path);
template <class F, class T>
std::list<boost::shared_ptr<T> >
shared_ptr<dcp::Signer> signer (
new dcp::Signer (
chain,
- "test/ref/crypt/leaf.key"
+ dcp::file_to_string ("test/ref/crypt/leaf.key")
)
);
shared_ptr<dcp::Signer> signer (
new dcp::Signer (
chain,
- "test/data/signer.key"
+ dcp::file_to_string ("test/data/signer.key")
)
);