From 3472793d24c4e4158d9d274d46eab9fff9e647ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 1 Mar 2020 09:08:48 +0100 Subject: script: call function string_hash in script_repo_sha512sum_file to compute SHA512 hash This removes dependency on libgcrypt in script plugin. --- src/plugins/script/CMakeLists.txt | 1 - src/plugins/script/Makefile.am | 4 ++-- src/plugins/script/script-repo.c | 23 +++-------------------- 3 files changed, 5 insertions(+), 23 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/script/CMakeLists.txt b/src/plugins/script/CMakeLists.txt index 6346a4064..9ece566bb 100644 --- a/src/plugins/script/CMakeLists.txt +++ b/src/plugins/script/CMakeLists.txt @@ -33,7 +33,6 @@ set_target_properties(script PROPERTIES PREFIX "") set(LINK_LIBS) list(APPEND LINK_LIBS ${ZLIB_LIBRARY}) -list(APPEND LINK_LIBS ${GCRYPT_LDFLAGS}) target_link_libraries(script ${LINK_LIBS} coverage_config) diff --git a/src/plugins/script/Makefile.am b/src/plugins/script/Makefile.am index 2be84705a..5fccb6609 100644 --- a/src/plugins/script/Makefile.am +++ b/src/plugins/script/Makefile.am @@ -17,7 +17,7 @@ # along with WeeChat. If not, see . # -AM_CPPFLAGS = -DLOCALEDIR=\"$(datadir)/locale\" $(ZLIB_CFLAGS) $(GCRYPT_CFLAGS) +AM_CPPFLAGS = -DLOCALEDIR=\"$(datadir)/locale\" $(ZLIB_CFLAGS) libdir = ${weechat_libdir}/plugins @@ -43,6 +43,6 @@ script_la_SOURCES = script.c \ script-repo.h script_la_LDFLAGS = -module -no-undefined -script_la_LIBADD = $(SCRIPT_LFLAGS) $(ZLIB_LFLAGS) $(GCRYPT_LFLAGS) +script_la_LIBADD = $(SCRIPT_LFLAGS) $(ZLIB_LFLAGS) EXTRA_DIST = CMakeLists.txt diff --git a/src/plugins/script/script-repo.c b/src/plugins/script/script-repo.c index 2e42c2f49..26dd7db8b 100644 --- a/src/plugins/script/script-repo.c +++ b/src/plugins/script/script-repo.c @@ -36,7 +36,6 @@ #include #include #include -#include #include "../weechat-plugin.h" #include "script.h" @@ -756,13 +755,7 @@ script_repo_sha512sum_file (const char *filename) { struct stat st; FILE *file; - char sha512sum[512]; - const char *hexa = "0123456789abcdef"; - unsigned char *data, *result; - gcry_md_hd_t hd; - int mdlen, i; - - sha512sum[0] = '\0'; + char *data, *hash; if (stat (filename, &st) == -1) return NULL; @@ -780,21 +773,11 @@ script_repo_sha512sum_file (const char *filename) } fclose (file); - gcry_md_open (&hd, GCRY_MD_SHA512, 0); - mdlen = gcry_md_get_algo_dlen (GCRY_MD_SHA512); - gcry_md_write (hd, data, st.st_size); - result = gcry_md_read (hd, GCRY_MD_SHA512); - for (i = 0; i < mdlen; i++) - { - sha512sum[i * 2] = hexa[(result[i] & 0xFF) / 16]; - sha512sum[(i * 2) + 1] = hexa[(result[i] & 0xFF) % 16]; - } - sha512sum[((mdlen - 1) * 2) + 2] = '\0'; - gcry_md_close (hd); + hash = weechat_string_hash (data, st.st_size, "sha512"); free (data); - return strdup (sha512sum); + return hash; } /* -- cgit v1.2.3