/*********************************************/
/* scol v 4                                  */
/*                                           */
/* base64.h                                  */
/*                                           */
/* implements base64 encoding and decoding   */
/*                                           */
/* by Loïc Berthelot, CryoNetworks, jul 2001 */
/*********************************************/

// Modification History
//
// $ LB (11 / 07 / 2001) : add _base64_getEncodedSize and _base64_getDecodedSize externalizations
//
// $LB (08/11/2001) : change all (char*) to (unsigned char*)


#ifndef _BASE64_H
#define _BASE64_H

#ifdef __cplusplus
extern "C" {
#endif





#define BASE64_SUCCESS             0x00   // ok
#define BASE64_ERROR               0x01   // error (not enough allocated memory to store the result, ...)
#define BASE64_NOT_A_BASE64_STRING 0x02   // error : the base64 string to decode has a incorrect size. size must be 4*n (<=> size % 4 == 0)




	

/************************************************************************/
/*                                                                      */
/* _base64_getEncodedSize                                               */
/*                                                                      */
/* gives the size of a base64 string in function of the number of       */
/* characters from the source string.                                   */ 
/*                                                                      */
/************************************************************************/
int _base64_getEncodedSize(int n);



/************************************************************************/
/*                                                                      */
/* _base64_getDecodedSize                                               */
/*                                                                      */
/* gives the size needed to decode a base64 string.                     */
/* n is the number of characters from the base64 string                 */ 
/*                                                                      */
/* !! you have to check that (n modulo 4) == 0  !!                      */
/*                                                                      */
/* !! be aware that this size is the needed size to decode. the size of */
/* string once decoded can be size, or size-1, or size-2.               */
/************************************************************************/
int _base64_getDecodedSize(int n);





/*************************************************************************************************/
/*                                                                                               */
/* int base64_encode (unsignedchar* dest, int* destSize, const unsigned char* src, int srcSize)  */
/*                                                                                               */
/* base64 encoding                                                                               */
/*                                                                                               */
/* returns 0 if success, non-zero code if fails                                                  */
/*                                                                                               */
/* destSize is the allocated memory size for result. If it's too small, then                     */
/* the function put the needed size in destSize, and returns a non-zero code.                    */
/*                                                                                               */
/*************************************************************************************************/
int base64_encode (unsigned char* dest, int* destSize, const unsigned char* src, int srcSize);





/***************************************************/
/*                                                 */
/* int SCbase64_encode (mmachine m)                */
/*                                                 */
/* scol interface of _base64_encode function       */
/***************************************************/
int SCbase64_encode (mmachine m);






/************************************************************************************************/
/*                                                                                              */
/* int base64_decode (unsignedchar* dest, int destSize, const unsigned char* src, int srcSize)  */
/*                                                                                              */
/* returns 0 if success, non-zero code if fails                                                 */
/************************************************************************************************/
int base64_decode (unsigned char* dest, int destSize, const unsigned  char* src, int srcSize);





/***************************************************/
/*                                                 */
/* int SCbase64_decode (mmachine m)                */
/*                                                 */
/* scol interface of _base64_decode function       */
/***************************************************/
int SCbase64_decode (mmachine m);


#ifdef __cplusplus
}
#endif


#endif
