#include <stdint.h>
Go to the source code of this file.
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| static size_t | base64_encoded_len (size_t raw_len) |
| Calculate length of base64-encoded string. | |
| void | base64_encode (const char *raw, char *encoded) |
| Base64-encode a string. | |
Definition in file base64.h.
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
Calculate length of base64-encoded string.
| raw_len | Raw string length (excluding NUL) |
| encoded_len | Encoded string length (excluding NUL) |
Definition at line 20 of file base64.h.
Referenced by base64_encode(), and http_step().
| void base64_encode | ( | const char * | raw, | |
| char * | encoded | |||
| ) |
Base64-encode a string.
| raw | Raw string | |
| encoded | Buffer for encoded string |
char buf[ base64_encoded_len ( strlen ( raw ) ) + 1 ];
(the +1 is for the terminating NUL) to provide a buffer of the correct size.
Definition at line 49 of file base64.c.
References assert, base64, base64_encoded_len(), DBG, and strlen().
Referenced by http_step().
00049 { 00050 const uint8_t *raw_bytes = ( ( const uint8_t * ) raw ); 00051 uint8_t *encoded_bytes = ( ( uint8_t * ) encoded ); 00052 size_t raw_bit_len = ( 8 * strlen ( raw ) ); 00053 unsigned int bit; 00054 unsigned int tmp; 00055 00056 for ( bit = 0 ; bit < raw_bit_len ; bit += 6 ) { 00057 tmp = ( ( raw_bytes[ bit / 8 ] << ( bit % 8 ) ) | 00058 ( raw_bytes[ bit / 8 + 1 ] >> ( 8 - ( bit % 8 ) ) ) ); 00059 tmp = ( ( tmp >> 2 ) & 0x3f ); 00060 *(encoded_bytes++) = base64[tmp]; 00061 } 00062 for ( ; ( bit % 8 ) != 0 ; bit += 6 ) 00063 *(encoded_bytes++) = '='; 00064 *(encoded_bytes++) = '\0'; 00065 00066 DBG ( "Base64-encoded \"%s\" as \"%s\"\n", raw, encoded ); 00067 assert ( strlen ( encoded ) == base64_encoded_len ( strlen ( raw ) ) ); 00068 }
1.5.7.1