1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-10 11:43:13 +02:00

api: add functions string_hash_binary and string_hash

This commit is contained in:
Sébastien Helleu
2020-02-29 21:02:42 +01:00
parent 7e808e2ef7
commit 410a5b341f
14 changed files with 700 additions and 22 deletions
+110
View File
@@ -2061,6 +2061,116 @@ char *dump = weechat_string_hex_dump (string, strlen (string), 8, " >> ", NULL);
[NOTE]
This function is not available in scripting API.
==== string_hash_binary
_WeeChat ≥ 2.8._
Compute hash of data.
Prototype:
[source,C]
----
void string_hash_binary (const char *data, int length_data, const char *hash_algo,
char **hash, int *length_hash);
----
Arguments:
* _data_: the data to hash
* _length_data_: number of bytes to hash in _data_
* _hash_algo_: the hash algorithm, see table below
* _hash_: pointer to the hash variable, which is allocated by the function and
used to store the resulting hash (NULL if error)
* _length_hash_: pointer to a variable used to store the length of the hash
computed (in bytes) (0 if error)
Supported hash algorithms:
[width="100%",cols="4,4,4,5,12",options="header"]
|===
| Value | Algorithm | Hash size | Output (binary) | Notes
| `+md5+` | MD5 | 128 bits | 16 bytes | *Weak*, not recommended for cryptography usage.
| `+sha1+` | SHA-1 | 160 bits | 20 bytes | *Weak*, not recommended for cryptography usage.
| `+sha224+` | SHA-224 | 224 bits | 28 bytes |
| `+sha256+` | SHA-256 | 256 bits | 32 bytes |
| `+sha384+` | SHA-384 | 384 bits | 48 bytes |
| `+sha512+` | SHA-512 | 512 bits | 64 bytes |
| `+sha3-224+` | SHA3-224 | 224 bits | 28 bytes |
| `+sha3-256+` | SHA3-256 | 256 bits | 32 bytes |
| `+sha3-384+` | SHA3-384 | 384 bits | 48 bytes |
| `+sha3-512+` | SHA3-512 | 512 bits | 64 bytes |
|===
C example:
[source,C]
----
const char *data = "abcdefghijklmnopqrstuvwxyz";
char *hash;
int length_hash;
weechat_string_hash_binary (data, strlen (data), "sha256", &hash, &length_hash);
/* hash is a binary buffer with:
71 c4 80 df 93 d6 ae 2f 1e fa d1 44 7c 66 c9 52 5e 31 62 18 cf 51 fc 8d 9e d8 32 f2 da f1 8b 73 */
----
[NOTE]
This function is not available in scripting API.
==== string_hash
_WeeChat ≥ 2.8._
Compute hash of data, as hexadecimal string.
Prototype:
[source,C]
----
char *string_hash (const char *data, int length_data, const char *hash_algo);
----
Arguments:
* _data_: the data to hash
* _length_data_: number of bytes to hash in _data_
* _hash_algo_: the hash algorithm, see table below
Supported hash algorithms:
[width="100%",cols="4,4,4,5,12",options="header"]
|===
| Value | Algorithm | Hash size | Output (string) | Notes
| `+md5+` | MD5 | 128 bits | 32 hex chars | *Weak*, not recommended for cryptography usage.
| `+sha1+` | SHA-1 | 160 bits | 40 hex chars | *Weak*, not recommended for cryptography usage.
| `+sha224+` | SHA-224 | 224 bits | 56 hex chars |
| `+sha256+` | SHA-256 | 256 bits | 64 hex chars |
| `+sha384+` | SHA-384 | 384 bits | 96 hex chars |
| `+sha512+` | SHA-512 | 512 bits | 128 hex chars |
| `+sha3-224+` | SHA3-224 | 224 bits | 56 hex chars |
| `+sha3-256+` | SHA3-256 | 256 bits | 64 hex chars |
| `+sha3-384+` | SHA3-384 | 384 bits | 96 hex chars |
| `+sha3-512+` | SHA3-512 | 512 bits | 128 hex chars |
|===
Return value:
* string with hash of data as hexadecimal (must be freed by calling "free"
after use), NULL if error
C example:
[source,C]
----
const char *data = "abcdefghijklmnopqrstuvwxyz";
char *hash;
hash = weechat_string_hash (data, strlen (data), "sha256");
/* hash == "71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73"
----
[NOTE]
This function is not available in scripting API.
==== string_is_command_char
_WeeChat ≥ 0.3.2._
+110
View File
@@ -2099,6 +2099,116 @@ char *dump = weechat_string_hex_dump (string, strlen (string), 8, " >> ", NULL);
[NOTE]
Cette fonction n'est pas disponible dans l'API script.
==== string_hash_binary
_WeeChat ≥ 2.8._
Calculer le hachage des données.
Prototype :
[source,C]
----
void string_hash_binary (const char *data, int length_data, const char *hash_algo,
char **hash, int *length_hash);
----
Paramètres :
* _data_ : les données à hacher
* _length_data_ : nombre d'octets à hacher dans _data_
* _hash_algo_ : l'algorithme de hachage, voir le tableau ci-dessous
* _hash_ : pointeur vers la variable de hachage, qui est allouée par la fonction
et utilisée pour stocker le résultat du hachage (NULL si erreur)
* _length_hash_ : pointeur vers une variable utiliser pour stocker la longueur
du résultat du hachage (en octets) (0 si erreur)
Algorithmes de hachage supportés :
[width="100%",cols="4,4,4,5,12",options="header"]
|===
| Valeur | Algorithme | Taille du haché | Sortie (binaire) | Notes
| `+md5+` | MD5 | 128 bits | 16 octets | *Faible*, non recommandé pour un usage cryptographique.
| `+sha1+` | SHA-1 | 160 bits | 20 octets | *Faible*, non recommandé pour un usage cryptographique.
| `+sha224+` | SHA-224 | 224 bits | 28 octets |
| `+sha256+` | SHA-256 | 256 bits | 32 octets |
| `+sha384+` | SHA-384 | 384 bits | 48 octets |
| `+sha512+` | SHA-512 | 512 bits | 64 octets |
| `+sha3-224+` | SHA3-224 | 224 bits | 28 octets |
| `+sha3-256+` | SHA3-256 | 256 bits | 32 octets |
| `+sha3-384+` | SHA3-384 | 384 bits | 48 octets |
| `+sha3-512+` | SHA3-512 | 512 bits | 64 octets |
|===
Exemple en C :
[source,C]
----
const char *data = "abcdefghijklmnopqrstuvwxyz";
char *hash;
int length_hash;
weechat_string_hash_binary (data, strlen (data), "sha256", &hash, &length_hash);
/* hash is a binary buffer with:
71 c4 80 df 93 d6 ae 2f 1e fa d1 44 7c 66 c9 52 5e 31 62 18 cf 51 fc 8d 9e d8 32 f2 da f1 8b 73 */
----
[NOTE]
Cette fonction n'est pas disponible dans l'API script.
==== string_hash
_WeeChat ≥ 2.8._
Calculer le hachage des données, sous forme de chaîne hexadécimale.
Prototype :
[source,C]
----
char *string_hash (const char *data, int length_data, const char *hash_algo);
----
Paramètres :
* _data_ : les données à hacher
* _length_data_ : nombre d'octets à hacher dans _data_
* _hash_algo_ : l'algorithme de hachage, voir le tableau ci-dessous
Algorithmes de hachage supportés :
[width="100%",cols="4,4,4,5,12",options="header"]
|===
| Valeur | Algorithme | Taille du haché | Sortie (chaîne) | Notes
| `+md5+` | MD5 | 128 bits | 32 caractères hexa | *Faible*, non recommandé pour un usage cryptographique.
| `+sha1+` | SHA-1 | 160 bits | 40 caractères hexa | *Faible*, non recommandé pour un usage cryptographique.
| `+sha224+` | SHA-224 | 224 bits | 56 caractères hexa |
| `+sha256+` | SHA-256 | 256 bits | 64 caractères hexa |
| `+sha384+` | SHA-384 | 384 bits | 96 caractères hexa |
| `+sha512+` | SHA-512 | 512 bits | 128 caractères hexa |
| `+sha3-224+` | SHA3-224 | 224 bits | 56 caractères hexa |
| `+sha3-256+` | SHA3-256 | 256 bits | 64 caractères hexa |
| `+sha3-384+` | SHA3-384 | 384 bits | 96 caractères hexa |
| `+sha3-512+` | SHA3-512 | 512 bits | 128 caractères hexa |
|===
Valeur de retour :
* chaîne avec le résultat du hachage en hexadécimal (doit être supprimée par un
appel à "free" après utilisation), NULL si erreur
Exemple en C :
[source,C]
----
const char *data = "abcdefghijklmnopqrstuvwxyz";
char *hash;
hash = weechat_string_hash (data, strlen (data), "sha256");
/* hash == "71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73"
----
[NOTE]
Cette fonction n'est pas disponible dans l'API script.
==== string_is_command_char
_WeeChat ≥ 0.3.2._
+112
View File
@@ -2152,6 +2152,118 @@ char *dump = weechat_string_hex_dump (string, strlen (string), 8, " >> ", NULL);
[NOTE]
Questa funzione non è disponibile nelle API per lo scripting.
// TRANSLATION MISSING
==== string_hash_binary
_WeeChat ≥ 2.8._
Compute hash of data.
Prototipo:
[source,C]
----
void string_hash_binary (const char *data, int length_data, const char *hash_algo,
char **hash, int *length_hash);
----
Argomenti:
* _data_: the data to hash
* _length_data_: number of bytes to hash in _data_
* _hash_algo_: the hash algorithm, see table below
* _hash_: pointer to the hash variable, which is allocated by the function and
used to store the resulting hash (NULL if error)
* _length_hash_: pointer to a variable used to store the length of the hash
computed (in bytes) (0 if error)
Supported hash algorithms:
[width="100%",cols="4,4,4,5,12",options="header"]
|===
| Value | Algorithm | Hash size | Output (binary) | Notes
| `+md5+` | MD5 | 128 bits | 16 bytes | *Weak*, not recommended for cryptography usage.
| `+sha1+` | SHA-1 | 160 bits | 20 bytes | *Weak*, not recommended for cryptography usage.
| `+sha224+` | SHA-224 | 224 bits | 28 bytes |
| `+sha256+` | SHA-256 | 256 bits | 32 bytes |
| `+sha384+` | SHA-384 | 384 bits | 48 bytes |
| `+sha512+` | SHA-512 | 512 bits | 64 bytes |
| `+sha3-224+` | SHA3-224 | 224 bits | 28 bytes |
| `+sha3-256+` | SHA3-256 | 256 bits | 32 bytes |
| `+sha3-384+` | SHA3-384 | 384 bits | 48 bytes |
| `+sha3-512+` | SHA3-512 | 512 bits | 64 bytes |
|===
Esempio in C:
[source,C]
----
const char *data = "abcdefghijklmnopqrstuvwxyz";
char *hash;
int length_hash;
weechat_string_hash_binary (data, strlen (data), "sha256", &hash, &length_hash);
/* hash is a binary buffer with:
71 c4 80 df 93 d6 ae 2f 1e fa d1 44 7c 66 c9 52 5e 31 62 18 cf 51 fc 8d 9e d8 32 f2 da f1 8b 73 */
----
[NOTE]
Questa funzione non è disponibile nelle API per lo scripting.
// TRANSLATION MISSING
==== string_hash
_WeeChat ≥ 2.8._
Compute hash of data, as hexadecimal string.
Prototipo:
[source,C]
----
char *string_hash (const char *data, int length_data, const char *hash_algo);
----
Argomenti:
* _data_: the data to hash
* _length_data_: number of bytes to hash in _data_
* _hash_algo_: the hash algorithm, see table below
Supported hash algorithms:
[width="100%",cols="4,4,4,5,12",options="header"]
|===
| Value | Algorithm | Hash size | Output (string) | Notes
| `+md5+` | MD5 | 128 bits | 32 hex chars | *Weak*, not recommended for cryptography usage.
| `+sha1+` | SHA-1 | 160 bits | 40 hex chars | *Weak*, not recommended for cryptography usage.
| `+sha224+` | SHA-224 | 224 bits | 56 hex chars |
| `+sha256+` | SHA-256 | 256 bits | 64 hex chars |
| `+sha384+` | SHA-384 | 384 bits | 96 hex chars |
| `+sha512+` | SHA-512 | 512 bits | 128 hex chars |
| `+sha3-224+` | SHA3-224 | 224 bits | 56 hex chars |
| `+sha3-256+` | SHA3-256 | 256 bits | 64 hex chars |
| `+sha3-384+` | SHA3-384 | 384 bits | 96 hex chars |
| `+sha3-512+` | SHA3-512 | 512 bits | 128 hex chars |
|===
Valore restituito:
* string with hash of data as hexadecimal (must be freed by calling "free"
after use), NULL if error
Esempio in C:
[source,C]
----
const char *data = "abcdefghijklmnopqrstuvwxyz";
char *hash;
hash = weechat_string_hash (data, strlen (data), "sha256");
/* hash == "71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73"
----
[NOTE]
Questa funzione non è disponibile nelle API per lo scripting.
==== string_is_command_char
_WeeChat ≥ 0.3.2._
+112
View File
@@ -2074,6 +2074,118 @@ char *dump = weechat_string_hex_dump (string, strlen (string), 8, " >> ", NULL);
[NOTE]
スクリプト API ではこの関数を利用できません。
// TRANSLATION MISSING
==== string_hash_binary
_WeeChat バージョン 2.8 以上で利用可。_
Compute hash of data.
プロトタイプ:
[source,C]
----
void string_hash_binary (const char *data, int length_data, const char *hash_algo,
char **hash, int *length_hash);
----
引数:
* _data_: the data to hash
* _length_data_: number of bytes to hash in _data_
* _hash_algo_: the hash algorithm, see table below
* _hash_: pointer to the hash variable, which is allocated by the function and
used to store the resulting hash (NULL if error)
* _length_hash_: pointer to a variable used to store the length of the hash
computed (in bytes) (0 if error)
Supported hash algorithms:
[width="100%",cols="4,4,4,5,12",options="header"]
|===
| Value | Algorithm | Hash size | Output (binary) | Notes
| `+md5+` | MD5 | 128 bits | 16 bytes | *Weak*, not recommended for cryptography usage.
| `+sha1+` | SHA-1 | 160 bits | 20 bytes | *Weak*, not recommended for cryptography usage.
| `+sha224+` | SHA-224 | 224 bits | 28 bytes |
| `+sha256+` | SHA-256 | 256 bits | 32 bytes |
| `+sha384+` | SHA-384 | 384 bits | 48 bytes |
| `+sha512+` | SHA-512 | 512 bits | 64 bytes |
| `+sha3-224+` | SHA3-224 | 224 bits | 28 bytes |
| `+sha3-256+` | SHA3-256 | 256 bits | 32 bytes |
| `+sha3-384+` | SHA3-384 | 384 bits | 48 bytes |
| `+sha3-512+` | SHA3-512 | 512 bits | 64 bytes |
|===
C 言語での使用例:
[source,C]
----
const char *data = "abcdefghijklmnopqrstuvwxyz";
char *hash;
int length_hash;
weechat_string_hash_binary (data, strlen (data), "sha256", &hash, &length_hash);
/* hash is a binary buffer with:
71 c4 80 df 93 d6 ae 2f 1e fa d1 44 7c 66 c9 52 5e 31 62 18 cf 51 fc 8d 9e d8 32 f2 da f1 8b 73 */
----
[NOTE]
スクリプト API ではこの関数を利用できません。
// TRANSLATION MISSING
==== string_hash
_WeeChat バージョン 2.8 以上で利用可。_
Compute hash of data, as hexadecimal string.
プロトタイプ:
[source,C]
----
char *string_hash (const char *data, int length_data, const char *hash_algo);
----
引数:
* _data_: the data to hash
* _length_data_: number of bytes to hash in _data_
* _hash_algo_: the hash algorithm, see table below
Supported hash algorithms:
[width="100%",cols="4,4,4,5,12",options="header"]
|===
| Value | Algorithm | Hash size | Output (string) | Notes
| `+md5+` | MD5 | 128 bits | 32 hex chars | *Weak*, not recommended for cryptography usage.
| `+sha1+` | SHA-1 | 160 bits | 40 hex chars | *Weak*, not recommended for cryptography usage.
| `+sha224+` | SHA-224 | 224 bits | 56 hex chars |
| `+sha256+` | SHA-256 | 256 bits | 64 hex chars |
| `+sha384+` | SHA-384 | 384 bits | 96 hex chars |
| `+sha512+` | SHA-512 | 512 bits | 128 hex chars |
| `+sha3-224+` | SHA3-224 | 224 bits | 56 hex chars |
| `+sha3-256+` | SHA3-256 | 256 bits | 64 hex chars |
| `+sha3-384+` | SHA3-384 | 384 bits | 96 hex chars |
| `+sha3-512+` | SHA3-512 | 512 bits | 128 hex chars |
|===
戻り値:
* string with hash of data as hexadecimal (must be freed by calling "free"
after use), NULL if error
C 言語での使用例:
[source,C]
----
const char *data = "abcdefghijklmnopqrstuvwxyz";
char *hash;
hash = weechat_string_hash (data, strlen (data), "sha256");
/* hash == "71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73"
----
[NOTE]
スクリプト API ではこの関数を利用できません。
==== string_is_command_char
_WeeChat バージョン 0.3.2 以上で利用可。_