cURL / Mailing Lists / curl-library / Single Mail

curl-library

Request for more curlx_* functions.

From: tetetest tetetest <tetetest_at_rambler.ru>
Date: Thu, 24 Apr 2008 12:27:52 +0400

Hello,

Libcurl defines and uses these handy functions:

Curl_md5it() - computes an MD5 hash of a string;
Curl_base64_encode(), Curl_base64_decode() - encode and decode data in
Base64 encoding.

I feel that these functions can come handy in applications that use
libcurl, so I propose to make them publicly available (with some
modifications):

/* original Curl_md5it() uses strlen() to define the length of input
   data; this makes it unfit for hashing binary data. So we add the
   insize param.
 */
void curlx_md5it(unsigned char *output,
   const unsigned char *input,
   unsigned int insize);

/* Curl_base64_encode() requires session handle to perform transparent
   transforms; I feel that this functionality must be separated from the
   encoding itself (it is logical, isn't it?).
   Besides, the code for base64 encoder can be optimized: using
   snprintf() to fill the output buffer is a bit - errr - inefficient.
 */
size_t curlx_base64_encode(const char *inp, size_t insize, char
**outptr);

/* The decoder is similar to current Curl_base64_decode(), but with one
   fix: it must SKIP any non-base64 characters, not garble the output.
 */
size_t curlx_base64_decode(const char *src, unsigned char **outptr);

I think these functions should be made public because:
- they are in the library already, so making them publicly available is
  easy;
- they are closely related to network tasks: base64 is widely used in
  many protocols; MD5 hashes are widely used in custom authentication
  schemes, email transfers and such.

PS: A simple to understand base64 en/decoder can be found on Wikipedia:
http://en.wikipedia.org/wiki/Base64 (it's Javascript, but translating it
into C is fairly straightforward).
Received on 2008-04-24