mirror of https://github.com/Icinga/icinga2.git
tlsutility: move hex encoding into a separate function BinaryToHex
This commit is contained in:
parent
f976e351f4
commit
6cd3a483a0
|
@ -844,15 +844,7 @@ String SHA1(const String& s, bool binary)
|
||||||
if (binary)
|
if (binary)
|
||||||
return String(reinterpret_cast<const char*>(digest), reinterpret_cast<const char *>(digest + SHA_DIGEST_LENGTH));
|
return String(reinterpret_cast<const char*>(digest), reinterpret_cast<const char *>(digest + SHA_DIGEST_LENGTH));
|
||||||
|
|
||||||
static const char hexdigits[] = "0123456789abcdef";
|
return BinaryToHex(digest, SHA_DIGEST_LENGTH);
|
||||||
char output[SHA_DIGEST_LENGTH*2+1];
|
|
||||||
for (int i = 0; i < SHA_DIGEST_LENGTH; i++) {
|
|
||||||
output[2*i] = hexdigits[digest[i] >> 4];
|
|
||||||
output[2*i + 1] = hexdigits[digest[i] & 0xf];
|
|
||||||
}
|
|
||||||
output[2*SHA_DIGEST_LENGTH] = 0;
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String SHA256(const String& s)
|
String SHA256(const String& s)
|
||||||
|
@ -930,6 +922,18 @@ String RandomString(int length)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String BinaryToHex(const unsigned char* data, size_t length) {
|
||||||
|
static const char hexdigits[] = "0123456789abcdef";
|
||||||
|
|
||||||
|
String output(2*length, 0);
|
||||||
|
for (int i = 0; i < SHA_DIGEST_LENGTH; i++) {
|
||||||
|
output[2 * i] = hexdigits[data[i] >> 4];
|
||||||
|
output[2 * i + 1] = hexdigits[data[i] & 0xf];
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
bool VerifyCertificate(const std::shared_ptr<X509> &caCertificate, const std::shared_ptr<X509> &certificate, const String& crlFile)
|
bool VerifyCertificate(const std::shared_ptr<X509> &caCertificate, const std::shared_ptr<X509> &certificate, const String& crlFile)
|
||||||
{
|
{
|
||||||
X509_STORE *store = X509_STORE_new();
|
X509_STORE *store = X509_STORE_new();
|
||||||
|
|
|
@ -61,6 +61,7 @@ String PBKDF2_SHA256(const String& password, const String& salt, int iterations)
|
||||||
String SHA1(const String& s, bool binary = false);
|
String SHA1(const String& s, bool binary = false);
|
||||||
String SHA256(const String& s);
|
String SHA256(const String& s);
|
||||||
String RandomString(int length);
|
String RandomString(int length);
|
||||||
|
String BinaryToHex(const unsigned char* data, size_t length);
|
||||||
|
|
||||||
bool VerifyCertificate(const std::shared_ptr<X509>& caCertificate, const std::shared_ptr<X509>& certificate, const String& crlFile);
|
bool VerifyCertificate(const std::shared_ptr<X509>& caCertificate, const std::shared_ptr<X509>& certificate, const String& crlFile);
|
||||||
bool IsCa(const std::shared_ptr<X509>& cacert);
|
bool IsCa(const std::shared_ptr<X509>& cacert);
|
||||||
|
|
Loading…
Reference in New Issue