+
+string SAMLInternalConfig::hashSHA1(const char* s, bool toHex)
+{
+ static char DIGITS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+
+ auto_ptr<XSECCryptoHash> hasher(XSECPlatformUtils::g_cryptoProvider->hashSHA1());
+ if (hasher.get()) {
+ auto_ptr<char> dup(strdup(s));
+ unsigned char buf[21];
+ hasher->hash(reinterpret_cast<unsigned char*>(dup.get()),strlen(dup.get()));
+ if (hasher->finish(buf,20)==20) {
+ string ret;
+ if (toHex) {
+ for (unsigned int i=0; i<20; i++) {
+ ret+=(DIGITS[((unsigned char)(0xF0 & buf[i])) >> 4 ]);
+ ret+=(DIGITS[0x0F & buf[i]]);
+ }
+ }
+ else {
+ for (unsigned int i=0; i<20; i++) {
+ ret+=buf[i];
+ }
+ }
+ return ret;
+ }
+ }
+ throw XMLSecurityException("Unable to generate SHA-1 hash.");
+}
+
+void opensaml::log_openssl()
+{
+ const char* file;
+ const char* data;
+ int flags,line;
+
+ unsigned long code=ERR_get_error_line_data(&file,&line,&data,&flags);
+ while (code) {
+ Category& log=Category::getInstance("OpenSSL");
+ log.errorStream() << "error code: " << code << " in " << file << ", line " << line << CategoryStream::ENDLINE;
+ if (data && (flags & ERR_TXT_STRING))
+ log.errorStream() << "error data: " << data << CategoryStream::ENDLINE;
+ code=ERR_get_error_line_data(&file,&line,&data,&flags);
+ }
+}