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

Function SHA1

lib/base/tlsutility.cpp:934–971  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

932}
933
934String SHA1(const String& s, bool binary)
935{
936 char errbuf[256];
937 SHA_CTX context;
938 unsigned char digest[SHA_DIGEST_LENGTH];
939
940 if (!SHA1_Init(&context)) {
941 ERR_error_string_n(ERR_peek_error(), errbuf, sizeof errbuf);
942 Log(LogCritical, "SSL")
943 << "Error on SHA Init: " << ERR_peek_error() << ", \"" << errbuf << "\"";
944 BOOST_THROW_EXCEPTION(openssl_error()
945 << boost::errinfo_api_function("SHA1_Init")
946 << errinfo_openssl_error(ERR_peek_error()));
947 }
948
949 if (!SHA1_Update(&context, (unsigned char*)s.CStr(), s.GetLength())) {
950 ERR_error_string_n(ERR_peek_error(), errbuf, sizeof errbuf);
951 Log(LogCritical, "SSL")
952 << "Error on SHA Update: " << ERR_peek_error() << ", \"" << errbuf << "\"";
953 BOOST_THROW_EXCEPTION(openssl_error()
954 << boost::errinfo_api_function("SHA1_Update")
955 << errinfo_openssl_error(ERR_peek_error()));
956 }
957
958 if (!SHA1_Final(digest, &context)) {
959 ERR_error_string_n(ERR_peek_error(), errbuf, sizeof errbuf);
960 Log(LogCritical, "SSL")
961 << "Error on SHA Final: " << ERR_peek_error() << ", \"" << errbuf << "\"";
962 BOOST_THROW_EXCEPTION(openssl_error()
963 << boost::errinfo_api_function("SHA1_Final")
964 << errinfo_openssl_error(ERR_peek_error()));
965 }
966
967 if (binary)
968 return String(reinterpret_cast<const char*>(digest), reinterpret_cast<const char *>(digest + SHA_DIGEST_LENGTH));
969
970 return BinaryToHex(digest, SHA_DIGEST_LENGTH);
971}
972
973String SHA256(const String& s)
974{

Callers 5

TruncateUsingHashMethod · 0.85
PrepareObjectMethod · 0.85
SerializeVarsMethod · 0.85
HashValueMethod · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 6

LogClass · 0.85
openssl_errorClass · 0.85
BinaryToHexFunction · 0.85
CStrMethod · 0.80
StringClass · 0.70
GetLengthMethod · 0.45

Tested by

no test coverage detected