Main Page Data Structures File List Data Fields Globals Related Pages

# inet/base64.cpp File Reference

`#include <stdlib.h>`
`#include <string.h>`
`#include <stdio.h>`
`#include <assert.h>`
`#include "inet/base64.h"`

Go to the source code of this file.

## Functions
unsigned char * | base64encode (const unsigned char *str, unsigned length, unsigned *ret_length)
| Encodes data with MIME base64.
unsigned char * | base64decode (const unsigned char *str, unsigned length, unsigned *ret_length)
| Decodes data encoded with MIME base64.
## Variables
char | base64_table []
char | base64_pad = '='

## Function Documentation

unsigned char* base64decode | ( | const unsigned char * | str,
|  | unsigned | length,
|  | unsigned * | ret_length
| ) |

  | Decodes data encoded with MIME base64. base64_decode() decodes encoded_data and returns the original data. The returned data may be binary. Parameters:
  str | pointer to base64 encoded string
  length | maximum length for the decoded data
  ret_length | pointer to an integer for storing the actual length of the decoded data (may be NULL).
Returns: pointer to decoded data, or 0 if out of memory. (needs to be free'd after use) Todo: This function contains a potential buffer overflow, if the given maximum length is too low. (It just doesn't check for overflow!). It better should calculate the length itself.. Definition at line 116 of file base64.cpp. References base64_pad, and base64_table.

unsigned char* base64encode | ( | const unsigned char * | str,
|  | unsigned | length,
|  | unsigned * | ret_length
| ) |

  | Encodes data with MIME base64. This encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean, such as mail bodies. Base64-encoded data takes about 33% more space than the original data. See also: base64_decode(), http://www.ietf.org/rfc/rfc2045.txt section 6.8. Parameters:
  str | pointer to data to encode
  length | length of data to encode
  ret_length | pointer to an integer for storing the lenght of the encoded data (may be NULL)
Returns: pointer to encoded string, or 0 if out of memory. (needs to be free'd after use) Definition at line 51 of file base64.cpp. References base64_pad, and base64_table. Referenced by http_connect(), and http_get().

## Variable Documentation

char base64_pad = '='`[static]`

| Definition at line 32 of file base64.cpp. Referenced by base64decode(), and base64encode().

char base64_table[]`[static]`

| Initial value:
      { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
        'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
        'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
      }
Definition at line 24 of file base64.cpp. Referenced by base64decode(), and base64encode().