Qsmtp  0.30dev
Macros | Functions | Variables
base64.c File Reference

Base64 encoding and decoding functions. More...

#include <base64.h>
#include <sstring.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

Macros

#define B64PAD   ((char) '=')
 

Functions

int b64decode (const char *in, size_t l, string *out)
 
int b64encode (const string *in, string *out, const unsigned int wraplimit)
 

Variables

static const char * b64alpha
 

Detailed Description

Base64 encoding and decoding functions.

Function Documentation

int b64decode ( const char *  in,
size_t  l,
string out 
)

decode base64 string to plain text

Parameters
inbase64 text
llength of in
outstring to store decoded string (memory will be malloced)
Return values
<0negative error code
0on success
1on parse error

The contents of out are undefined as long as something else than 0 is returned, i.e. the memory is freed but the freed pointer may still be recorded in out.

A final 0-byte will always be added to out->s, which is not counted in out->len.

int b64encode ( const string in,
string out,
const unsigned int  wraplimit 
)

encode plain text string to Base64

Parameters
inplain text string
outstring to store Base64 string (memory will be malloced)
wraplimitthe number of characters after which a CRLF pair should be inserted
Return values
0on success
<0negative error code

Variable Documentation

const char* b64alpha
static
Initial value:
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"