1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

script: use API function weechat_crypto_hash_file in script_repo_sha512sum_file

This commit is contained in:
Sébastien Helleu
2022-08-16 21:40:02 +02:00
parent 0090695f7d
commit f5604510cd
+2 -24
View File
@@ -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);
}