summaryrefslogtreecommitdiff
path: root/src/plugins/script/script-repo.c
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2022-08-16 21:40:02 +0200
committerSébastien Helleu <flashcode@flashtux.org>2022-08-16 21:40:02 +0200
commitf5604510cd1a1660fa7f11a70a54361830c495bd (patch)
tree5eccb55e91b0b5172653a55783b000ef8781bbb1 /src/plugins/script/script-repo.c
parent0090695f7d79efa4f50398b55bc59317d1de1d75 (diff)
downloadweechat-f5604510cd1a1660fa7f11a70a54361830c495bd.zip
script: use API function weechat_crypto_hash_file in script_repo_sha512sum_file
Diffstat (limited to 'src/plugins/script/script-repo.c')
-rw-r--r--src/plugins/script/script-repo.c26
1 files 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)
- 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);
+ if (!weechat_crypto_hash_file (filename, "sha512", hash, &hash_size))
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);
}