From dcc249a616d9efe48d56a1ad5f86d178e824f6c1 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Tue, 4 Sep 2018 13:19:23 +0200 Subject: Use libstrophe sha1 functions Using libstrophes sha1 functions in p_sha1_hash() to get rid of the p_sha1.c dependency. Relates to https://github.com/boothj5/profanity/issues/882 --- src/common.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/common.c b/src/common.c index 164523a2..a4120e9b 100644 --- a/src/common.c +++ b/src/common.c @@ -55,7 +55,7 @@ #include "log.h" #include "common.h" -#include "tools/p_sha1.h" +#include struct curl_data_t { @@ -333,17 +333,16 @@ release_is_new(char *found_version) char* p_sha1_hash(char *str) { - P_SHA1_CTX ctx; - uint8_t digest[20]; - uint8_t *input = (uint8_t*)malloc(strlen(str) + 1); - memcpy(input, str, strlen(str) + 1); + unsigned char *digest = (unsigned char*)malloc(XMPP_SHA1_DIGEST_SIZE); + assert(digest != NULL); - P_SHA1_Init(&ctx); - P_SHA1_Update(&ctx, input, strlen(str)); - P_SHA1_Final(&ctx, digest); + xmpp_sha1_digest((unsigned char*)str, strlen(str), digest); - free(input); - return g_base64_encode(digest, sizeof(digest)); + char *b64 = g_base64_encode(digest, XMPP_SHA1_DIGEST_SIZE); + assert(b64 != NULL); + free(digest); + + return b64; } static size_t -- cgit 1.4.1-2-gfad0