Change name of encoding type
[platform/upstream/iotivity.git] / resource / csdk / security / include / base64.h
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef _IOTVT_B64_H_
22 #define _IOTVT_B64_H_
23
24 #include <stdint.h>
25 #include <stdio.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /**
32  * Macro to calculate the size of 'output' buffer required for
33  * a 'input' buffer of length x during Base64 encoding operation.
34  */
35 #define B64ENCODE_OUT_SAFESIZE(x) ((((x) + 3 - 1)/3) * 4 + 1)
36
37 /**
38  * Macro to calculate the size of 'output' buffer required for
39  * a 'input' buffer of length x during Base64 decoding operation.
40  */
41 #define B64DECODE_OUT_SAFESIZE(x) (((x)*3)/4)
42
43 /**
44  * Result code of base64 functions.
45  */
46 typedef enum
47 {
48     B64_OK = 0,
49     B64_INVALID_PARAM,
50     B64_OUTPUT_BUFFER_TOO_SMALL,
51     B64_ERROR
52 } B64Result;
53
54 /**
55  * Encode the plain message in base64.
56  *
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.
63  *
64  * @return ::B64_OK for Success, otherwise some error value.
65  */
66 B64Result b64Encode(const uint8_t* in, const size_t inLen,
67                char* outBuf, const size_t outBufSize, uint32_t *outLen);
68
69 /**
70  * Decode the encoded message in base64.
71  *
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.
78  *
79  * @return ::B64_OK for Success, otherwise some error value.
80  */
81 B64Result b64Decode(const char* in, const size_t inLen,
82                uint8_t* outBuf, size_t outBufSize, uint32_t *outLen);
83
84 #ifdef __cplusplus
85 }
86 #endif
87
88 #endif  //IOTVT_B64_H