2013-12-10 13:08:35 +00:00
|
|
|
#ifndef BASE64_H
|
|
|
|
#define BASE64_H
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
2015-07-28 17:27:27 +00:00
|
|
|
namespace util
|
2013-12-10 13:08:35 +00:00
|
|
|
{
|
|
|
|
|
2015-07-22 14:43:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Base64 encodes an array of bytes.
|
2015-07-23 12:46:35 +00:00
|
|
|
* @return the number of characters written to the output buffer
|
2015-07-22 14:43:11 +00:00
|
|
|
* @param InBuffer array of input bytes to be encoded
|
|
|
|
* @param InCount length of the input array
|
2015-07-23 12:46:35 +00:00
|
|
|
* @param OutBuffer array to store output characters
|
2015-07-22 14:43:11 +00:00
|
|
|
* @param len length of the output buffer
|
2015-07-24 13:13:09 +00:00
|
|
|
* @note zero is returned when the output buffer is too small
|
2015-07-22 14:43:11 +00:00
|
|
|
*/
|
2015-07-16 21:29:52 +00:00
|
|
|
size_t ByteStreamToBase64 (const uint8_t * InBuffer, size_t InCount, char * OutBuffer, size_t len);
|
2015-07-22 14:43:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decodes base 64 encoded data to an array of bytes.
|
2015-07-23 12:46:35 +00:00
|
|
|
* @return the number of bytes written to the output buffer
|
2015-07-22 14:43:11 +00:00
|
|
|
* @param InBuffer array of input characters to be decoded
|
|
|
|
* @param InCount length of the input array
|
2015-07-23 12:46:35 +00:00
|
|
|
* @param OutBuffer array to store output bytes
|
2015-07-22 14:43:11 +00:00
|
|
|
* @param len length of the output buffer
|
|
|
|
* @todo Do not return a negative value on failure, size_t could be unsigned.
|
2015-07-24 13:13:09 +00:00
|
|
|
* @note zero is returned when the output buffer is too small
|
2015-07-22 14:43:11 +00:00
|
|
|
*/
|
2015-07-16 21:29:52 +00:00
|
|
|
size_t Base64ToByteStream (const char * InBuffer, size_t InCount, uint8_t * OutBuffer, size_t len );
|
2015-07-23 12:46:35 +00:00
|
|
|
|
2015-07-16 21:29:52 +00:00
|
|
|
const char * GetBase64SubstitutionTable ();
|
|
|
|
|
2015-07-23 12:46:35 +00:00
|
|
|
/**
|
|
|
|
* Decodes base 32 encoded data to an array of bytes.
|
|
|
|
* @return the number of bytes written to the output buffer
|
|
|
|
* @param inBuf array of input characters to be decoded
|
|
|
|
* @param len length of the input buffer
|
|
|
|
* @param outBuf array to store output bytes
|
|
|
|
* @param outLen length of the output array
|
2015-07-24 13:13:09 +00:00
|
|
|
* @note zero is returned when the output buffer is too small
|
2015-07-23 12:46:35 +00:00
|
|
|
*/
|
2015-07-16 21:29:52 +00:00
|
|
|
size_t Base32ToByteStream (const char * inBuf, size_t len, uint8_t * outBuf, size_t outLen);
|
2015-07-23 12:46:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Base 32 encodes an array of bytes.
|
|
|
|
* @return the number of bytes written to the output buffer
|
|
|
|
* @param inBuf array of input bytes to be encoded
|
|
|
|
* @param len length of the input buffer
|
|
|
|
* @param outBuf array to store output characters
|
|
|
|
* @param outLen length of the output array
|
2015-07-24 13:13:09 +00:00
|
|
|
* @note zero is returned when the output buffer is too small
|
2015-07-23 12:46:35 +00:00
|
|
|
*/
|
|
|
|
size_t ByteStreamToBase32 (const uint8_t * inBuf, size_t len, char * outBuf, size_t outLen);
|
2013-12-10 13:08:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|