MCPcopy Create free account
hub / github.com/Icinga/icinga2 / SHA256

Function SHA256

lib/base/tlsutility.cpp:973–1011  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

971}
972
973String SHA256(const String& s)
974{
975 char errbuf[256];
976 SHA256_CTX context;
977 unsigned char digest[SHA256_DIGEST_LENGTH];
978
979 if (!SHA256_Init(&context)) {
980 ERR_error_string_n(ERR_peek_error(), errbuf, sizeof errbuf);
981 Log(LogCritical, "SSL")
982 << "Error on SHA256 Init: " << ERR_peek_error() << ", \"" << errbuf << "\"";
983 BOOST_THROW_EXCEPTION(openssl_error()
984 << boost::errinfo_api_function("SHA256_Init")
985 << errinfo_openssl_error(ERR_peek_error()));
986 }
987
988 if (!SHA256_Update(&context, (unsigned char*)s.CStr(), s.GetLength())) {
989 ERR_error_string_n(ERR_peek_error(), errbuf, sizeof errbuf);
990 Log(LogCritical, "SSL")
991 << "Error on SHA256 Update: " << ERR_peek_error() << ", \"" << errbuf << "\"";
992 BOOST_THROW_EXCEPTION(openssl_error()
993 << boost::errinfo_api_function("SHA256_Update")
994 << errinfo_openssl_error(ERR_peek_error()));
995 }
996
997 if (!SHA256_Final(digest, &context)) {
998 ERR_error_string_n(ERR_peek_error(), errbuf, sizeof errbuf);
999 Log(LogCritical, "SSL")
1000 << "Error on SHA256 Final: " << ERR_peek_error() << ", \"" << errbuf << "\"";
1001 BOOST_THROW_EXCEPTION(openssl_error()
1002 << boost::errinfo_api_function("SHA256_Final")
1003 << errinfo_openssl_error(ERR_peek_error()));
1004 }
1005
1006 char output[SHA256_DIGEST_LENGTH*2+1];
1007 for (int i = 0; i < 32; i++)
1008 sprintf(output + 2 * i, "%02x", digest[i]);
1009
1010 return output;
1011}
1012
1013String RandomString(int length)
1014{

Callers 6

GetChecksumMethod · 0.85
CalculateConfigHashMethod · 0.85
CalculateConfigHashMethod · 0.85
HashValueMethod · 0.85
CalculateConfigHashMethod · 0.85
HashDowntimeOptionsMethod · 0.85

Calls 4

LogClass · 0.85
openssl_errorClass · 0.85
CStrMethod · 0.80
GetLengthMethod · 0.45

Tested by

no test coverage detected