1 | // Copyright (c) Microsoft. All rights reserved.
|
---|
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
---|
3 |
|
---|
4 | /** @file azure_base64.h
|
---|
5 | * @brief Prototypes for functions related to encoding/decoding
|
---|
6 | * a @c buffer using standard base64 encoding.
|
---|
7 | */
|
---|
8 |
|
---|
9 | #ifndef AZURE_BASE64_H
|
---|
10 | #define AZURE_BASE64_H
|
---|
11 |
|
---|
12 | #ifdef __cplusplus
|
---|
13 | #include <cstddef>
|
---|
14 | #else
|
---|
15 | #include <stddef.h>
|
---|
16 | #endif
|
---|
17 |
|
---|
18 | #include "azure_c_shared_utility/strings.h"
|
---|
19 | #include "azure_c_shared_utility/buffer_.h"
|
---|
20 |
|
---|
21 | #include "umock_c/umock_c_prod.h"
|
---|
22 |
|
---|
23 | #ifdef __cplusplus
|
---|
24 | extern "C" {
|
---|
25 | #endif
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * @brief Base64 encodes a buffer and returns the resulting string.
|
---|
29 | *
|
---|
30 | * @param input The buffer that needs to be base64 encoded.
|
---|
31 | *
|
---|
32 | * Azure_Base64_Encode takes as a parameter a pointer to a BUFFER. If @p input is @c NULL then
|
---|
33 | * @c Azure_Base64_Encode returns @c NULL. The size of the BUFFER pointed to by @p input may
|
---|
34 | * be zero. If when allocating memory to produce the encoding a failure occurs, then @c
|
---|
35 | * Azure_Base64_Encode returns @c NULL. Otherwise
|
---|
36 | * @c Azure_Base64_Encode returns a pointer to a STRING. That string contains the
|
---|
37 | * base 64 encoding of the @p input. This encoding of @p input will not contain embedded
|
---|
38 | * line feeds.
|
---|
39 | *
|
---|
40 | * @return A @c STRING_HANDLE containing the base64 encoding of @p input.
|
---|
41 | */
|
---|
42 | MOCKABLE_FUNCTION(, STRING_HANDLE, Azure_Base64_Encode, BUFFER_HANDLE, input);
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * @brief Base64 encodes the buffer pointed to by @p source and returns the resulting string.
|
---|
46 | *
|
---|
47 | * @param source The buffer that needs to be base64 encoded.
|
---|
48 | * @param size The size.
|
---|
49 | *
|
---|
50 | * This function produces a @c STRING_HANDLE containing the base64 encoding of the
|
---|
51 | * buffer pointed to by @p source, having the size as given by
|
---|
52 | * @p size. If @p source is @c NULL then @c Azure_Base64_Encode_Bytes returns @c NULL
|
---|
53 | * If @p source is not @c NULL and @p size is zero, then @c Azure_Base64_Encode_Bytes produces
|
---|
54 | * an empty @c STRING_HANDLE. Otherwise, @c Azure_Base64_Encode_Bytes produces a
|
---|
55 | * @c STRING_HANDLE containing the Base64 representation of the buffer. In case of
|
---|
56 | * any errors, @c Azure_Base64_Encode_Bytes returns @c NULL.].
|
---|
57 | *
|
---|
58 | * @return @c NULL in case an error occurs or a @c STRING_HANDLE containing the base64 encoding
|
---|
59 | * of @p input.
|
---|
60 | *
|
---|
61 | */
|
---|
62 | MOCKABLE_FUNCTION(, STRING_HANDLE, Azure_Base64_Encode_Bytes, const unsigned char*, source, size_t, size);
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * @brief Base64 decodes the buffer pointed to by @p source and returns the resulting buffer.
|
---|
66 | *
|
---|
67 | * @param source A base64 encoded string buffer.
|
---|
68 | *
|
---|
69 | * This function decodes the string pointed at by @p source using base64 decoding and
|
---|
70 | * returns the resulting buffer. If @p source is @c NULL then
|
---|
71 | * @c Azure_Base64_Decode returns NULL. If the string pointed to by @p source is zero
|
---|
72 | * length then the handle returned refers to a zero length buffer. If there is any
|
---|
73 | * memory allocation failure during the decode or if the source string has an invalid
|
---|
74 | * length for a base 64 encoded string then @c Azure_Base64_Decode returns @c NULL.
|
---|
75 | *
|
---|
76 | * @return A @c BUFFER_HANDLE pointing to a buffer containing the result of base64 decoding @p
|
---|
77 | * source.
|
---|
78 | */
|
---|
79 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, Azure_Base64_Decode, const char*, source);
|
---|
80 |
|
---|
81 | #ifdef __cplusplus
|
---|
82 | }
|
---|
83 | #endif
|
---|
84 |
|
---|
85 | #endif /* AZURE_BASE64_H */
|
---|