2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2008-03-08 14:43:31 +00:00
|
|
|
// Name: base64.h
|
2008-03-10 15:24:38 +00:00
|
|
|
// Purpose: interface of global functions
|
2008-03-08 14:43:31 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-03-15 18:15:46 +00:00
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Global functions/macros
|
|
|
|
// ============================================================================
|
|
|
|
|
2009-01-05 20:48:06 +00:00
|
|
|
/** @addtogroup group_funcmacro_misc */
|
2008-03-08 14:43:31 +00:00
|
|
|
//@{
|
2008-03-15 18:15:46 +00:00
|
|
|
|
2009-06-10 14:44:26 +00:00
|
|
|
/**
|
|
|
|
Elements of this enum specify the possible behaviours of wxBase64Decode
|
|
|
|
when an invalid character is encountered.
|
|
|
|
*/
|
|
|
|
enum wxBase64DecodeMode
|
|
|
|
{
|
|
|
|
wxBase64DecodeMode_Strict, ///< Normal behaviour: stop at any invalid characters.
|
|
|
|
wxBase64DecodeMode_SkipWS, ///< Skip whitespace characters.
|
|
|
|
wxBase64DecodeMode_Relaxed ///< The most lenient behaviour: simply ignore all invalid characters.
|
|
|
|
};
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
2008-03-15 18:15:46 +00:00
|
|
|
This function encodes the given data using base64.
|
|
|
|
|
2008-03-23 18:24:32 +00:00
|
|
|
To allocate the buffer of the correct size, use wxBase64EncodedSize() or
|
|
|
|
call this function with @a dst set to @NULL -- it will then return the
|
|
|
|
necessary buffer size.
|
2008-03-15 18:15:46 +00:00
|
|
|
|
|
|
|
This raw encoding function overload writes the output string into the
|
|
|
|
provided buffer; the other overloads return it as a wxString.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
|
|
|
@param dst
|
2008-03-15 18:15:46 +00:00
|
|
|
The output buffer, may be @NULL to retrieve the needed buffer size.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param dstLen
|
2008-03-09 12:33:59 +00:00
|
|
|
The output buffer size, ignored if dst is @NULL.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param src
|
2008-03-09 12:33:59 +00:00
|
|
|
The input buffer, must not be @NULL.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param srcLen
|
2008-03-09 12:33:59 +00:00
|
|
|
The length of the input data.
|
2008-03-15 18:15:46 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return @c wxCONV_FAILED if the output buffer is too small.
|
2008-03-23 18:24:32 +00:00
|
|
|
|
|
|
|
@header{wx/base64.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
size_t wxBase64Encode(char* dst, size_t dstLen,
|
|
|
|
const void* src,
|
2008-03-08 13:52:38 +00:00
|
|
|
size_t srcLen);
|
2008-03-15 18:15:46 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-23 18:24:32 +00:00
|
|
|
This function encodes the given data using base64 and returns the output as
|
|
|
|
a wxString.
|
2008-03-15 18:15:46 +00:00
|
|
|
|
|
|
|
There is no error return.
|
|
|
|
|
2008-03-23 18:24:32 +00:00
|
|
|
To allocate the buffer of the correct size, use wxBase64EncodedSize() or
|
|
|
|
call this function with @a dst set to @NULL -- it will then return the
|
|
|
|
necessary buffer size.
|
2008-03-15 18:15:46 +00:00
|
|
|
|
|
|
|
@param src
|
|
|
|
The input buffer, must not be @NULL.
|
|
|
|
@param srcLen
|
|
|
|
The length of the input data.
|
2008-03-23 18:24:32 +00:00
|
|
|
|
|
|
|
@header{wx/base64.h}
|
2008-03-15 18:15:46 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxString wxBase64Encode(const void* src, size_t srcLen);
|
2008-03-15 18:15:46 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-23 18:24:32 +00:00
|
|
|
This function encodes the given data using base64 and returns the output as
|
|
|
|
a wxString.
|
2008-03-15 18:15:46 +00:00
|
|
|
|
|
|
|
There is no error return.
|
2008-03-23 18:24:32 +00:00
|
|
|
|
|
|
|
@header{wx/base64.h}
|
2008-03-15 18:15:46 +00:00
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
wxString wxBase64Encode(const wxMemoryBuffer& buf);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
/**
|
2008-03-15 18:15:46 +00:00
|
|
|
Returns the size of the buffer necessary to contain the data encoded in a
|
|
|
|
base64 string of length @e srcLen. This can be useful for allocating a
|
|
|
|
buffer to be passed to wxBase64Decode().
|
2008-03-23 18:24:32 +00:00
|
|
|
|
|
|
|
@header{wx/base64.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
size_t wxBase64DecodedSize(size_t srcLen);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the length of the string with base64 representation of a buffer of
|
|
|
|
specified size @e len. This can be useful for allocating the buffer passed
|
2008-03-10 15:24:38 +00:00
|
|
|
to wxBase64Encode().
|
2008-03-23 18:24:32 +00:00
|
|
|
|
|
|
|
@header{wx/base64.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
size_t wxBase64EncodedSize(size_t len);
|
|
|
|
|
|
|
|
/**
|
2008-03-15 18:15:46 +00:00
|
|
|
This function decodes a Base64-encoded string.
|
|
|
|
|
2008-03-23 18:24:32 +00:00
|
|
|
This overload is a raw decoding function and decodes the data into the
|
|
|
|
provided buffer @a dst of the given size @e dstLen. An error is returned if
|
|
|
|
the buffer is not large enough -- that is not at least
|
2009-08-23 22:25:12 +00:00
|
|
|
wxBase64DecodedSize(srcLen) bytes. Notice that the buffer will @e not be
|
|
|
|
@NULL-terminated.
|
2008-03-15 18:15:46 +00:00
|
|
|
|
|
|
|
This overload returns the number of bytes written to the buffer or the
|
2008-03-23 18:24:32 +00:00
|
|
|
necessary buffer size if @a dst was @NULL or @c wxCONV_FAILED on error,
|
|
|
|
e.g. if the output buffer is too small or invalid characters were
|
2008-03-15 18:15:46 +00:00
|
|
|
encountered in the input string.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
|
|
|
@param dst
|
2008-03-23 18:24:32 +00:00
|
|
|
Pointer to output buffer, may be @NULL to just compute the necessary
|
|
|
|
buffer size.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param dstLen
|
2008-03-15 18:15:46 +00:00
|
|
|
The size of the output buffer, ignored if dst is @NULL.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param src
|
2008-03-23 18:24:32 +00:00
|
|
|
The input string, must not be @NULL. For the version using wxString,
|
|
|
|
the input string should contain only ASCII characters.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param srcLen
|
2008-03-23 18:24:32 +00:00
|
|
|
The length of the input string or special value wxNO_LEN if the string
|
|
|
|
is @NULL-terminated and the length should be computed by this function
|
|
|
|
itself.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param mode
|
2008-03-20 13:45:17 +00:00
|
|
|
This parameter specifies the function behaviour when invalid characters
|
2008-03-15 18:15:46 +00:00
|
|
|
are encountered in input. By default, any such character stops the
|
2008-03-09 12:33:59 +00:00
|
|
|
decoding with error. If the mode is wxBase64DecodeMode_SkipWS, then the
|
2008-03-15 18:15:46 +00:00
|
|
|
white space characters are silently skipped instead. And if it is
|
2008-03-09 12:33:59 +00:00
|
|
|
wxBase64DecodeMode_Relaxed, then all invalid characters are skipped.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param posErr
|
2008-03-23 18:24:32 +00:00
|
|
|
If this pointer is non-@NULL and an error occurs during decoding, it is
|
|
|
|
filled with the index of the invalid character.
|
|
|
|
|
|
|
|
@header{wx/base64.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
size_t wxBase64Decode(void* dst, size_t dstLen,
|
|
|
|
const char* src,
|
2008-03-08 13:52:38 +00:00
|
|
|
size_t srcLen = wxNO_LEN,
|
|
|
|
wxBase64DecodeMode mode = wxBase64DecodeMode_Strict,
|
2009-06-01 13:04:26 +00:00
|
|
|
size_t *posErr = NULL);
|
2008-03-15 18:15:46 +00:00
|
|
|
|
|
|
|
/**
|
2009-11-11 14:38:40 +00:00
|
|
|
Decode a Base64-encoded wxString.
|
|
|
|
|
2009-06-10 14:44:26 +00:00
|
|
|
See the wxBase64Decode(void*,size_t,const char*,size_t,wxBase64DecodeMode,size_t*)
|
2009-11-11 14:38:40 +00:00
|
|
|
overload for more information about the parameters of this function, the
|
|
|
|
only difference between it and this one is that a wxString is used instead
|
|
|
|
of a @c char* pointer and its length.
|
|
|
|
|
|
|
|
@since 2.9.1
|
|
|
|
|
|
|
|
@header{wx/base64.h}
|
|
|
|
*/
|
|
|
|
size_t wxBase64Decode(void* dst, size_t dstLen,
|
|
|
|
const wxString& str,
|
|
|
|
wxBase64DecodeMode mode = wxBase64DecodeMode_Strict,
|
|
|
|
size_t *posErr = NULL);
|
2008-03-15 18:15:46 +00:00
|
|
|
|
2009-11-11 14:38:40 +00:00
|
|
|
/**
|
|
|
|
Decode a Base64-encoded string and return decoded contents in a buffer.
|
2008-03-15 18:15:46 +00:00
|
|
|
|
2009-11-11 14:38:40 +00:00
|
|
|
See the wxBase64Decode(void*,size_t,const char*,size_t,wxBase64DecodeMode,size_t*)
|
|
|
|
overload for more information about the parameters of this function. The
|
|
|
|
difference of this overload is that it allocates a buffer of necessary size
|
|
|
|
on its own and returns it, freeing you from the need to do it manually.
|
|
|
|
Because of this, it is simpler to use and is recommended for normal use.
|
2008-03-23 18:24:32 +00:00
|
|
|
|
|
|
|
@header{wx/base64.h}
|
2008-03-15 18:15:46 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxMemoryBuffer wxBase64Decode(const char* src,
|
2008-03-08 14:43:31 +00:00
|
|
|
size_t srcLen = wxNO_LEN,
|
|
|
|
wxBase64DecodeMode mode = wxBase64DecodeMode_Strict,
|
2009-06-01 13:04:26 +00:00
|
|
|
size_t *posErr = NULL);
|
2008-03-15 18:15:46 +00:00
|
|
|
|
|
|
|
/**
|
2009-11-11 14:38:40 +00:00
|
|
|
Decode a Base64-encoded wxString and return decoded contents in a buffer.
|
|
|
|
|
2009-06-10 14:44:26 +00:00
|
|
|
See the wxBase64Decode(void*,size_t,const char*,size_t,wxBase64DecodeMode,size_t*)
|
2009-11-11 14:38:40 +00:00
|
|
|
overload for more information about the parameters of this function.
|
2008-03-15 18:15:46 +00:00
|
|
|
|
|
|
|
This overload takes as input a wxString and returns the internally-allocated
|
2009-11-11 14:38:40 +00:00
|
|
|
memory as a wxMemoryBuffer, containing the Base64-decoded data.
|
2008-03-23 18:24:32 +00:00
|
|
|
|
|
|
|
@header{wx/base64.h}
|
2008-03-15 18:15:46 +00:00
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
wxMemoryBuffer wxBase64Decode(const wxString& src,
|
|
|
|
wxBase64DecodeMode mode = wxBase64DecodeMode_Strict,
|
2009-06-01 13:04:26 +00:00
|
|
|
size_t *posErr = NULL);
|
2008-03-15 18:15:46 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|