mirror of
https://github.com/weechat/weechat.git
synced 2026-07-07 10:13:12 +02:00
api: add function crypto_hash_file
This commit is contained in:
@@ -127,6 +127,36 @@ plugin_api_crypto_hash (const void *data, int data_size, const char *hash_algo,
|
||||
return weecrypto_hash (data, data_size, algo, hash, hash_size);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
|
||||
@@ -33,6 +33,9 @@ extern const char *plugin_api_ngettext (const char *single, const char *plural,
|
||||
extern int plugin_api_crypto_hash (const void *data, int data_size,
|
||||
const char *hash_algo,
|
||||
void *hash, int *hash_size);
|
||||
extern int plugin_api_crypto_hash_file (const char *filename,
|
||||
const char *hash_algo,
|
||||
void *hash, int *hash_size);
|
||||
extern int plugin_api_crypto_hash_pbkdf2 (const void *data, int data_size,
|
||||
const char *hash_algo,
|
||||
const void *salt, int salt_size,
|
||||
|
||||
@@ -665,6 +665,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
|
||||
new_plugin->utf8_strndup = &utf8_strndup;
|
||||
|
||||
new_plugin->crypto_hash = &plugin_api_crypto_hash;
|
||||
new_plugin->crypto_hash_file = &plugin_api_crypto_hash_file;
|
||||
new_plugin->crypto_hash_pbkdf2 = &plugin_api_crypto_hash_pbkdf2;
|
||||
new_plugin->crypto_hmac = &plugin_api_crypto_hmac;
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ struct timeval;
|
||||
* please change the date with current one; for a second change at same
|
||||
* date, increment the 01, otherwise please keep 01.
|
||||
*/
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20220720-02"
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20220816-01"
|
||||
|
||||
/* macros for defining plugin infos */
|
||||
#define WEECHAT_PLUGIN_NAME(__name) \
|
||||
@@ -380,6 +380,8 @@ struct t_weechat_plugin
|
||||
/* crypto */
|
||||
int (*crypto_hash) (const void *data, int data_size,
|
||||
const char *hash_algo, void *hash, int *hash_size);
|
||||
int (*crypto_hash_file) (const char *fliename,
|
||||
const char *hash_algo, void *hash, int *hash_size);
|
||||
int (*crypto_hash_pbkdf2) (const void *data, int data_size,
|
||||
const char *hash_algo,
|
||||
const void *salt, int salt_size,
|
||||
@@ -1372,6 +1374,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
|
||||
__hash, __hash_size) \
|
||||
(weechat_plugin->crypto_hash)(__data, __data_size, __hash_algo, \
|
||||
__hash, __hash_size)
|
||||
#define weechat_crypto_hash_file(__filename, __hash_algo, __hash, \
|
||||
__hash_size) \
|
||||
(weechat_plugin->crypto_hash_file)(__filename, __hash_algo, __hash, \
|
||||
__hash_size)
|
||||
#define weechat_crypto_hash_pbkdf2(__data, __data_size, __hash_algo, \
|
||||
__salt, __salt_size, __iterations, \
|
||||
__hash, __hash_size) \
|
||||
|
||||
Reference in New Issue
Block a user