| 1 |
Base64 Requirements |
| 2 |
================ |
| 3 |
|
| 4 |
## Overview |
| 5 |
|
| 6 |
This module is used to encode a BUFFER using the standard base64 encoding stream. |
| 7 |
|
| 8 |
## References |
| 9 |
[IETF RFC 4648](https://tools.ietf.org/html/rfc4648) |
| 10 |
|
| 11 |
## Exposed API |
| 12 |
|
| 13 |
```c |
| 14 |
extern STRING_HANDLE Azure_Base64_Encode(BUFFER_HANDLE input); |
| 15 |
extern STRING_HANDLE Azure_Base64_Encode_Bytes(const unsigned char* source, size_t size); |
| 16 |
extern BUFFER_HANDLE Azure_Base64_Decode(const char* source); |
| 17 |
``` |
| 18 |
|
| 19 |
### Azure_Base64_Encode |
| 20 |
```c |
| 21 |
extern STRING_HANDLE Azure_Base64_Encode(BUFFER_HANDLE input); |
| 22 |
``` |
| 23 |
|
| 24 |
Azure_Base64_Encode takes as a parameter a pointer to BUFFER, input. |
| 25 |
|
| 26 |
**SRS_BASE64_06_001: [** If input is NULL then Azure_Base64_Encode shall return NULL. **]** |
| 27 |
The size of the BUFFER pointed to by input MAY be zero. |
| 28 |
|
| 29 |
**SRS_BASE64_06_006: [** If when allocating memory to produce the encoding a failure occurs then Azure_Base64_Encode shall return NULL. **]** |
| 30 |
|
| 31 |
**SRS_BASE64_06_007: [** Otherwise Azure_Base64_Encode shall return a pointer to STRING, that string contains the base 64 encoding of input. **]** |
| 32 |
This encoding of input shall NOT contain embedded line feeds. |
| 33 |
|
| 34 |
### Azure_Base64_Encode_Bytes |
| 35 |
```c |
| 36 |
extern STRING_HANDLE Azure_Base64_Encode_Bytes(const unsigned char* source, size_t size); |
| 37 |
``` |
| 38 |
|
| 39 |
Azure_Base64_Encode_Bytes shall produce a STRING_HANDLE containing the base64 encoding of the buffer pointed to by source, having the size as given by parameter size. |
| 40 |
|
| 41 |
**SRS_BASE64_02_001: [** If source is NULL then Azure_Base64_Encode_Bytes shall return NULL. **]** |
| 42 |
|
| 43 |
**SRS_BASE64_02_002: [** If source is not NULL and size is zero, then Azure_Base64_Encode_Bytes shall produce an empty STRING_HANDLE. **]** |
| 44 |
|
| 45 |
**SRS_BASE64_02_003: [** Otherwise, Azure_Base64_Encode_Bytes shall produce a STRING_HANDLE containing the Base64 representation of the buffer. **]** |
| 46 |
|
| 47 |
**SRS_BASE64_02_004: [** In case of any errors, Azure_Base64_Encode_Bytes shall return NULL. **]** |
| 48 |
|
| 49 |
### Azure_Base64_Decode |
| 50 |
```c |
| 51 |
extern BUFFER_HANDLE Azure_Base64_Decode(const char* source); |
| 52 |
``` |
| 53 |
|
| 54 |
**SRS_BASE64_06_008: [** If source is NULL then Azure_Base64_Decode shall return NULL. **]** |
| 55 |
|
| 56 |
**SRS_BASE64_06_009: [** If the string pointed to by source is zero length then the handle returned shall refer to a zero length buffer. **]** |
| 57 |
|
| 58 |
**SRS_BASE64_06_010: [** If there is any memory allocation failure during the decode then Azure_Base64_Decode shall return NULL. **]** |
| 59 |
|
| 60 |
**SRS_BASE64_06_011: [** If the source string has an invalid length for a base 64 encoded string then Azure_Base64_Decode shall return NULL. **]** |