1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
32 * Macro to calculate the size of 'output' buffer required for
33 * a 'input' buffer of length x during Base64 encoding operation.
35 #define B64ENCODE_OUT_SAFESIZE(x) ((((x) + 3 - 1)/3) * 4 + 1)
38 * Macro to calculate the size of 'output' buffer required for
39 * a 'input' buffer of length x during Base64 decoding operation.
41 #define B64DECODE_OUT_SAFESIZE(x) (((x)*3)/4)
44 * Result code of base64 functions.
50 B64_OUTPUT_BUFFER_TOO_SMALL,
55 * Encode the plain message in base64.
57 * @param in is the plain message to be converted.
58 * @param inLen is the byte length of plain message.
59 * @param outBuf is the output buffer containing Base64 encoded message.
60 * @note outBuf adds a NULL to the string configuration.
61 * @param outBufSize is the size of output buffer.
62 * @param outLen is the byte length of encoded message.
64 * @return ::B64_OK for Success, otherwise some error value.
66 B64Result b64Encode(const uint8_t* in, const size_t inLen,
67 char* outBuf, const size_t outBufSize, uint32_t *outLen);
70 * Decode the encoded message in base64.
72 * @param in is the Base64 encoded message to be converted.
73 * @param inLen is the byte length of the encoded message.
74 * @param outBuf is the output buffer containing decoded message.
75 * @note outBuf adds a NULL to the string configuration.
76 * @param outBufSize is the size of output buffer.
77 * @param outLen is the byte length of decoded message.
79 * @return ::B64_OK for Success, otherwise some error value.
81 B64Result b64Decode(const char* in, const size_t inLen,
82 uint8_t* outBuf, size_t outBufSize, uint32_t *outLen);