diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2020-05-21 00:02:24 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2020-05-21 00:02:24 +0200 |
commit | 1994d5641dda09d3825b4cc6baf3b57a20b2ffc2 (patch) | |
tree | fe874854efeb99ed1a52186fb8f36d456f4b0fee /src/core | |
parent | 0ac936a5cfe3f0b962eb1f6cfea0192107656117 (diff) | |
download | weechat-1994d5641dda09d3825b4cc6baf3b57a20b2ffc2.zip |
core: move functions string_base_encode and string_base_decode from plugin-api.c to wee-string.c
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-string.c | 62 | ||||
-rw-r--r-- | src/core/wee-string.h | 3 |
2 files changed, 59 insertions, 6 deletions
diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 1ff0c53b9..4c41239c3 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -2917,7 +2917,8 @@ string_format_size (unsigned long long size) * Argument "length" is number of bytes in "from" to convert (commonly * strlen(from)). * - * Returns length of string in "*to" (it does not count final \0). + * Returns length of string in "*to" (it does not count final \0), + * -1 if error. */ int @@ -2944,7 +2945,8 @@ string_base16_encode (const char *from, int length, char *to) /* * Decodes a base16 string (hexadecimal). * - * Returns length of string in "*to" (it does not count final \0). + * Returns length of string in "*to" (it does not count final \0), + * -1 if error. */ int @@ -3013,7 +3015,8 @@ string_base16_decode (const char *from, char *to) * See the License for the specific language governing permissions and * limitations under the License. * - * Returns length of string in "*to" (it does not count final \0). + * Returns length of string in "*to" (it does not count final \0), + * -1 if error. */ int @@ -3090,7 +3093,8 @@ string_base32_encode (const char *from, int length, char *to) * limitations under the License. * * - * Returns length of string in "*to" (it does not count final \0). + * Returns length of string in "*to" (it does not count final \0), + * -1 if error. */ int @@ -3166,7 +3170,8 @@ string_convbase64_8x3_to_6x4 (const char *from, char *to) * Argument "length" is number of bytes in "from" to convert (commonly * strlen(from)). * - * Returns length of string in "*to" (it does not count final \0). + * Returns length of string in "*to" (it does not count final \0), + * -1 if error. */ int @@ -3237,7 +3242,8 @@ string_convbase64_6x4_to_8x3 (const unsigned char *from, unsigned char *to) /* * Decodes a base64 string. * - * Returns length of string in "*to" (it does not count final \0). + * Returns length of string in "*to" (it does not count final \0), + * -1 if error. */ int @@ -3301,6 +3307,50 @@ string_base64_decode (const char *from, char *to) } /* + * Encodes a string in base 16, 32, or 64. + * + * Returns length of string in "*to" (it does not count final \0), + * -1 if error. + */ + +int +string_base_encode (int base, const char *from, int length, char *to) +{ + switch (base) + { + case 16: + return string_base16_encode (from, length, to); + case 32: + return string_base32_encode (from, length, to); + case 64: + return string_base64_encode (from, length, to); + } + return -1; +} + +/* + * Decodes a string encoded in base 16, 32, or 64. + * + * Returns length of string in "*to" (it does not count final \0), + * -1 if error. + */ + +int +string_base_decode (int base, const char *from, char *to) +{ + switch (base) + { + case 16: + return string_base16_decode (from, to); + case 32: + return string_base32_decode (from, to); + case 64: + return string_base64_decode (from, to); + } + return -1; +} + +/* * Dumps a data buffer as hexadecimal + ascii. * * Note: result must be freed after use. diff --git a/src/core/wee-string.h b/src/core/wee-string.h index 585cb399d..a34dbd041 100644 --- a/src/core/wee-string.h +++ b/src/core/wee-string.h @@ -115,6 +115,9 @@ extern int string_base32_encode (const char *from, int length, char *to); extern int string_base32_decode (const char *from, char *to); extern int string_base64_encode (const char *from, int length, char *to); extern int string_base64_decode (const char *from, char *to); +extern int string_base_encode (int base, const char *from, int length, + char *to); +extern int string_base_decode (int base, const char *from, char *to); extern char *string_hex_dump (const char *data, int data_size, int bytes_per_line, const char *prefix, const char *suffix); |