Decodes Base64. This class supports various variants of Base64.
More...
#include "nn/nlib/Base64.h"
|
| Base64Decoder () noexcept |
| Instantiates the object with default parameters (default constructor).
|
|
| ~Base64Decoder () noexcept |
| Destructor.
|
|
errno_t | Init (CharOption char_option=BASE64_DEFAULT) noexcept |
| Initializes the object by specifying the 62nd and 63rd characters. More...
|
|
errno_t | StepDecode (size_t *written, void *dst, size_t dstsize, const char *src, size_t srcsize) noexcept |
| Runs split decoding of Base64. More...
|
|
template<size_t N> |
errno_t | StepDecode (size_t *written, uint8_t(&dst)[N], const char *src, size_t srcsize) noexcept |
| Runs StepDecode(written, dst, N, src, srcsize) .
|
|
errno_t | Close (size_t *written, void *dst, size_t dstsize) noexcept |
| Finishes split decoding of Base64. More...
|
|
| operator bool () const |
| Returns true if the initialization has completed and no error has occurred.
|
|
|
static size_t | GetRequiredSize (size_t srcsize) noexcept |
| Calculates the size of the memory space required for decoding the data. More...
|
|
static errno_t | Decode (size_t *written, uint8_t *dst, size_t dstsize, const char *src, CharOption char_option=BASE64_DEFAULT) noexcept |
| Decodes data in batch. More...
|
|
template<size_t N> |
static errno_t | Decode (size_t *written, uint8_t(&dst)[N], const char *src, CharOption char_option=BASE64_DEFAULT) noexcept |
| Runs Decode(written, dst, N, src, srcsize, char_option) .
|
|
static errno_t | Decode (UniquePtr< uint8_t[]> &dst, size_t *dstsize, const char *src, CharOption char_option=BASE64_DEFAULT) noexcept |
| Decodes data in batch. More...
|
|
static errno_t | DecodeInplace (size_t *written, char *src, CharOption char_option=BASE64_DEFAULT) noexcept |
| Decodes data immediately. More...
|
|
Decodes Base64. This class supports various variants of Base64.
- Description
- This class supports batch decoding, split decoding and in-place batch decoding of Base64. Various variants of Base64 can be supported by specifying CharOption type values. Data containing newline and/or padding characters can also be decoded.
- Batch decoding is available with the following code.
UniquePtr<uint8_t[]> dst;
size_t dstsize;
Split decoding can be performed with the following code. ....
errno_t MyStepDecode(uint8_t** dst,
size_t* dstsize,
const char* src,
size_t srcsize) {
size_t written;
errno_t e = decoder.StepDecode(&written, *dst, *dstsize, src, srcsize);
*dst += written;
*dstsize -= written;
return 0;
}
errno_t MyCloseDecode(
char** dst,
size_t* dstsize) {
size_t written;
errno_t e = decoder.Close(&written, *dst, *dstsize);
*dst += written;
*dstsize -= written;
return 0;
}
- See also
- https://www.ietf.org/rfc/rfc2045.txt
- The transition of the object state.
- The overview of the object state transitions is described below:
Definition at line 106 of file Base64.h.
§ Close()
nn::nlib::Base64Decoder::Close |
( |
size_t * |
written, |
|
|
void * |
dst, |
|
|
size_t |
dstsize |
|
) |
| |
|
noexcept |
Finishes split decoding of Base64.
- Parameters
-
[out] | written | The number of bytes written to dst. |
[out] | dst | The buffer that stores the decoded data. |
[in] | dstsize | Size of the buffer specified by dst. |
- Return values
-
0 | Success. |
EINVAL | written or dst was NULL . |
EINVAL | Indicates that an error has previously occurred. |
ERANGE | dstsize was smaller than the necessary size. |
- Description
- dst requires a space of at least 2 bytes.
§ Decode() [1/2]
nn::nlib::Base64Decoder::Decode |
( |
size_t * |
written, |
|
|
uint8_t * |
dst, |
|
|
size_t |
dstsize, |
|
|
const char * |
src, |
|
|
CharOption |
char_option = BASE64_DEFAULT |
|
) |
| |
|
inlinestaticnoexcept |
Decodes data in batch.
- Parameters
-
[out] | written | Size of the data output to dst. |
[out] | dst | The buffer that the decoded data is output to. |
[in] | dstsize | Size of the buffer specified by dst. |
[in] | src | Encoded string. |
[in] | char_option | Specifies the 62nd and 63rd characters. |
- Returns
- Returns
0
on success.
Definition at line 126 of file Base64.h.
§ Decode() [2/2]
nn::nlib::Base64Decoder::Decode |
( |
UniquePtr< uint8_t[]> & |
dst, |
|
|
size_t * |
dstsize, |
|
|
const char * |
src, |
|
|
CharOption |
char_option = BASE64_DEFAULT |
|
) |
| |
|
inlinestaticnoexcept |
Decodes data in batch.
- Parameters
-
[out] | dst | Decoded data. |
[out] | dstsize | Size of the data specified by dst. |
[in] | src | Encoded string. |
[in] | char_option | Specifies the 62nd and 63rd characters. |
- Return values
-
0 | Success. |
EINVAL | dstsize or src was NULL . |
ENOMEM | Memory allocation has failed. |
EILSEQ | One or more invalid characters were found. |
Definition at line 143 of file Base64.h.
§ DecodeInplace()
nn::nlib::Base64Decoder::DecodeInplace |
( |
size_t * |
written, |
|
|
char * |
src, |
|
|
CharOption |
char_option = BASE64_DEFAULT |
|
) |
| |
|
staticnoexcept |
Decodes data immediately.
- Parameters
-
[out] | written | The size of data written to src. |
[in,out] | src | Encoded string and its decoded data. |
[in] | char_option | Specifies the 62nd and 63rd characters. |
- Return values
-
0 | Success. |
EINVAL | written or src was NULL . |
EILSEQ | One or more invalid characters were found. |
- Description
- If
EILSEQ
is returned, zero is written to written even if the decoding has partially completed.
§ GetRequiredSize()
nn::nlib::Base64Decoder::GetRequiredSize |
( |
size_t |
srcsize | ) |
|
|
inlinestaticnoexcept |
Calculates the size of the memory space required for decoding the data.
- Parameters
-
[in] | srcsize | Size of the data to be decoded. |
- Returns
- Returns the value of ((srcsize + 3) / 4) * 3.
Definition at line 123 of file Base64.h.
§ Init()
nn::nlib::Base64Decoder::Init |
( |
CharOption |
char_option = BASE64_DEFAULT | ) |
|
|
noexcept |
Initializes the object by specifying the 62nd and 63rd characters.
- Parameters
-
[in] | char_option | Specifies the 62nd and 63rd characters. |
- Return values
-
0 | Success. |
EALREADY | Indicates that the initialization has already completed and no error has occurred. |
§ StepDecode()
nn::nlib::Base64Decoder::StepDecode |
( |
size_t * |
written, |
|
|
void * |
dst, |
|
|
size_t |
dstsize, |
|
|
const char * |
src, |
|
|
size_t |
srcsize |
|
) |
| |
|
noexcept |
Runs split decoding of Base64.
- Parameters
-
[out] | written | The number of bytes written to dst. |
[out] | dst | The buffer that stores the decoded data. |
[in] | dstsize | Size of the buffer specified by dst. |
[in] | src | Data to be decoded. |
[in] | srcsize | Size of the data specified by src. |
- Return values
-
0 | Success. |
EINVAL | written, dst or src was NULL . |
EINVAL | Indicates that an error has previously occurred. |
ERANGE | dstsize was smaller than the necessary size. |
EILSEQ | One or more invalid characters were found. |
- Description
- The buffer size necessary for dst can be calculated with
GetRequiredSize(srcsize)
. If EILSEQ
is returned, zero is written to written even if the decoding has partially completed.
The documentation for this class was generated from the following files: