summaryrefslogtreecommitdiff
path: root/src/plugins/plugin-api.c
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2022-08-16 21:25:30 +0200
committerSébastien Helleu <flashcode@flashtux.org>2022-08-16 21:33:50 +0200
commit0090695f7d79efa4f50398b55bc59317d1de1d75 (patch)
tree9c1adbf669c3cdca080bd8aea4cbb9a119bb2d18 /src/plugins/plugin-api.c
parente61441081520bcada6de699229ce9af241302665 (diff)
downloadweechat-0090695f7d79efa4f50398b55bc59317d1de1d75.zip
api: add function crypto_hash_file
Diffstat (limited to 'src/plugins/plugin-api.c')
-rw-r--r--src/plugins/plugin-api.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c
index 3ae8a6332..d4a374899 100644
--- a/src/plugins/plugin-api.c
+++ b/src/plugins/plugin-api.c
@@ -128,6 +128,36 @@ plugin_api_crypto_hash (const void *data, int data_size, const char *hash_algo,
}
/*
+ * Computes hash of a file using the given algorithm.
+ *
+ * Returns:
+ * 1: OK
+ * 0: error
+ */
+
+int
+plugin_api_crypto_hash_file (const char *filename, const char *hash_algo,
+ void *hash, int *hash_size)
+{
+ int algo;
+
+ if (!hash)
+ return 0;
+
+ if (hash_size)
+ *hash_size = 0;
+
+ if (!filename || !filename[0] || !hash_algo)
+ return 0;
+
+ algo = weecrypto_get_hash_algo (hash_algo);
+ if (algo == GCRY_MD_NONE)
+ return 0;
+
+ return weecrypto_hash_file (filename, algo, hash, hash_size);
+}
+
+/*
* Computes PKCS#5 Passphrase Based Key Derivation Function number 2 (PBKDF2)
* hash of data.
*