1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
49 B64_OUTPUT_BUFFER_TOO_SMALL,
54 * Encode the plain message in base64.
56 * @param[in] in Plain message
57 * @param[in] inLen Byte length of 'in'
58 * @param[in,out] outBuf Output buffer
59 * Base64 encoded message will be written into 'outBuf'
60 * NOTE : This method adds a NULL to the string configuration
61 * @param[in] outBufSize Size of output buffer
62 * @param[out] outLen 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] in Base64 encoded message
73 * @param[in] inLen Byte lenth of 'in'
74 * @param[in, out] outBuf Output buffer
75 * Base64 decoded message will be written into 'outBuf'
76 * @param[in] outBufSize Size of output buffer
77 * @param[out] outLen 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);