#4400, #5462: Move BASE64 helpers to crypto-utils

On a way to factoring out OpenSSL support to a standalone file to ease
addition of other crypto libraries support in the future, move helpers
providing BASE64 encoding and decoding to crypto-utils.{c,h}. OpenSSL-
related functionality is moved to crypto-utils-openssl.c.

Add new functions to be implemented by crypto backends:
* tr_base64_encode_impl - encode from binary to BASE64,
* tr_base64_decode_impl - decode from BASE64 to binary.

Change `tr_base64_encode` and `tr_base64_decode` functions to expect
non-negative input data length which is considered real and never adjusted.
To process null-terminated strings (which was achieved before by passing 0
or -1 as input data length), add new `tr_base64_encode_str` and
`tr_base64_decode_str` functions which do not accept input data length as
an argument but calculate it on their own.
This commit is contained in:
Mike Gelfand
2014-12-04 19:58:34 +00:00
parent 117ab3e8d2
commit 5c43b5c23c
13 changed files with 312 additions and 136 deletions

View File

@@ -287,22 +287,6 @@ char* tr_strdup_printf (const char * fmt, ...) TR_GNUC_PRINTF (1, 2)
char * tr_strdup_vprintf (const char * fmt,
va_list args) TR_GNUC_MALLOC;
/**
* @brief Translate a block of bytes into base64
* @return a newly-allocated string that can be freed with tr_free ()
*/
char* tr_base64_encode (const void * input,
int inlen,
int * outlen) TR_GNUC_MALLOC;
/**
* @brief Translate a block of bytes from base64 into raw form
* @return a newly-allocated string that can be freed with tr_free ()
*/
char* tr_base64_decode (const void * input,
int inlen,
int * outlen) TR_GNUC_MALLOC;
/** @brief Portability wrapper for strlcpy () that uses the system implementation if available */
size_t tr_strlcpy (char * dst, const void * src, size_t siz);