Defines | Functions

sofia-sip/base64.h File Reference

Base64 encoding and decoding functions. More...

#include <sofia-sip/su_types.h>
Include dependency graph for base64.h:

Go to the source code of this file.

Defines

#define BASE64_SIZE(n)
 Calculate size of n bytes encoded in base64.
#define BASE64_MINSIZE(n)
 Calculate size of n bytes encoded in base64 sans trailing =.

Functions

isize_t base64_d (char buf[], isize_t bsiz, char const *b64s)
 Decode a BASE64-encoded string.
isize_t base64_e (char buf[], isize_t bsiz, void *data, isize_t dsiz)
 Encode data with BASE64.

Detailed Description

Base64 encoding and decoding functions.

This module contains base64 encoding and decoding functions. Base64 encodes arbitrary octet strings as strings containing characters [A-Za-z0-9+/=]. Base64 is defined as part of MIME mail format, but it is used widely by other text-based protocols as well.

See also:
RFC 2045, "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies", N. Freed, N. Borenstein, November 1996.
Author:
Pekka Pessi <Pekka.Pessi@nokia-email.address.hidden>

Define Documentation

#define BASE64_MINSIZE (   n  ) 

Calculate size of n bytes encoded in base64 sans trailing =.

Since:
New in 1.12.5.

Function Documentation

isize_t base64_d ( char  buf[],
isize_t  bsiz,
char const *  b64s 
)

Decode a BASE64-encoded string.

The function base64_d() decodes a string b64s encoded with BASE64. It stores the result in the buffer buf of bsiz bytes.

If the buf is NULL, the function just returns the length of decoded data. In any case, no decoded data is stored in buf beyond bsiz. The function always returns the full length of decodable data.

Parameters:
buf Buffer to store decoded data
bsiz Size of buf
b64s Base64-encoded string.
Returns:
Length of data that can be decoded in bytes.
See also:
RFC 2045, "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies", N. Freed, N. Borenstein, November 1996.
Example
The following example code decodes a string of BASE64 data into a memory area allocated from heap:
 int decoder(char const *encoded, void **return_decoded)
 {
   int len = base64_d(NULL, 0, encoded);
   void *decoded = malloc(len);
   base64_d(decoded, len, encoded);
   *return_decoded = decoded;
   return len;
 }
isize_t base64_e ( char  buf[],
isize_t  bsiz,
void *  data,
isize_t  dsiz 
)

Encode data with BASE64.

The function base64_e() encodes dsiz bytes of data into buf.

Note:
The function base64_e() uses at most bsiz bytes from buf.

If bsiz is zero, the function just returns the length of BASE64 encoding, excluding the final NUL.

If encoded string is longer than that bsiz, the function terminates string with NUL at buf[bsiz-1], but returns the length of encoding as usual.

Parameters:
buf buffer for encoded data
bsiz size of buffer
data data to be encoded
dsiz size of data
Returns:
The function base64_e() return length of encoded string, excluding the final NUL.
See also:
RFC 2045, "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies", N. Freed, N. Borenstein, November 1996.
 All Data Structures Files Functions Variables Defines

Sofia-SIP 1.12.11 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.