mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 05:34:48 +02:00
Don't use sprintf for SHA1 to hex conversion
This commit is contained in:
parent
49cfda833e
commit
2a2229a49b
@ -762,9 +762,13 @@ 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";
|
||||||
char output[SHA_DIGEST_LENGTH*2+1];
|
char output[SHA_DIGEST_LENGTH*2+1];
|
||||||
for (int i = 0; i < 20; i++)
|
for (int i = 0; i < SHA_DIGEST_LENGTH; i++) {
|
||||||
sprintf(output + 2 * i, "%02x", digest[i]);
|
output[2*i] = hexdigits[digest[i] >> 4];
|
||||||
|
output[2*i + 1] = hexdigits[digest[i] & 0xf];
|
||||||
|
}
|
||||||
|
output[2*SHA_DIGEST_LENGTH] = 0;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user