From f5604510cd1a1660fa7f11a70a54361830c495bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Tue, 16 Aug 2022 21:40:02 +0200 Subject: [PATCH] script: use API function weechat_crypto_hash_file in script_repo_sha512sum_file --- src/plugins/script/script-repo.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/src/plugins/script/script-repo.c b/src/plugins/script/script-repo.c index 89e3deb42..bc0e18e4c 100644 --- a/src/plugins/script/script-repo.c +++ b/src/plugins/script/script-repo.c @@ -753,37 +753,15 @@ script_repo_script_is_held (struct t_script_repo *script) char * script_repo_sha512sum_file (const char *filename) { - struct stat st; - FILE *file; - char *data, hash[512 / 8], hash_hexa[((512 / 8) * 2) + 1]; + char hash[512 / 8], hash_hexa[((512 / 8) * 2) + 1]; int hash_size; - if (stat (filename, &st) == -1) + if (!weechat_crypto_hash_file (filename, "sha512", hash, &hash_size)) return NULL; - data = malloc (st.st_size); - if (!data) - return NULL; - - file = fopen (filename, "r"); - if ((int)fread (data, 1, st.st_size, file) < st.st_size) - { - free (data); - fclose (file); - return NULL; - } - fclose (file); - - if (!weechat_crypto_hash (data, st.st_size, "sha512", hash, &hash_size)) - { - free (data); - return NULL; - } weechat_string_base_encode (16, hash, hash_size, hash_hexa); weechat_string_tolower (hash_hexa); - free (data); - return strdup (hash_hexa); }