replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / include / internal / crlresource.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_SRM_CRLR_H
22 #define IOTVT_SRM_CRLR_H
23
24 #include "ocpayload.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 /**
31  * This function stores CRL in SRM.
32  *
33  * @param crl to be stored in SRM.
34  *
35  * @return ::OC_STACK_OK for Success, otherwise some error value.
36  */
37 OCStackResult UpdateCRLResource(OicSecCrl_t *crl);
38
39 /**
40  * This function get encoded with base64 CRL from SRM.
41  *
42  * @note Caller responsible for resulting string memory (use OICFree to remove it).
43  *
44  * @return NULL if error occured (e.g. CRL did not set).
45  */
46 uint8_t* GetCrl();
47
48 /**
49  * This function get encoded with DER CRL from SRM.
50  *
51  * @return encoded CRL with DER format. array len is 0 if error occured (e.g. CRL did not set).
52  */
53 void  GetDerCrl(ByteArray_t* crlArray);
54
55 /**
56  * This function converts CRL to CBOR
57  *
58  * @param crl is a pointer to buffer that contains crl. Shoul be not NULL. Buffer
59  * will be allocated by the function and content of *crl will be ignored.
60  * @param payload is the converted cbor value.
61  * @param size is a pointer to length of the CRL buffer. Should be not NULL.
62  * @param lastUpdate optional field contains CRL last update time
63  *
64  * @note Caller responsible for crl buffer memory (use OICFree to free it).
65  *
66  * @return ::OC_STACK_OK if success, otherwise some error value.
67  */
68 OCStackResult CrlToCBORPayload(const OicSecCrl_t *crl, uint8_t **payload, size_t *size,
69                                char *lastUpdate);
70
71 /**
72  * This function converts CBOR to CRL
73  *
74  * will be allocated by the function and content of *crl will be ignored.
75  * @param cborPayload is the cbor vlaue
76  * @param size is a pointer to length of the CRL buffer. Should be not NULL.
77  * @param crl is a pointer to buffer that contains crl. Shoul be not NULL. Buffer
78  *
79  * @note Caller responsible for crl buffer memory (use OICFree to free it).
80  *
81  * @return ::OC_STACK_OK if success, otherwise some error value.
82  */
83 OCStackResult CBORPayloadToCrl(const uint8_t *cborPayload, const size_t size,
84                                OicSecCrl_t **secCrl);
85 /**
86  * Initialize CRL resource by loading data from persistent storage.
87  *
88  * @return ::OC_STACK_OK for Success, otherwise some error value.
89  */
90 OCStackResult InitCRLResource();
91
92 /**
93  * Perform cleanup for CRL resources.
94  *
95  * @return ::OC_STACK_OK for Success, otherwise some error value.
96  */
97 OCStackResult DeInitCRLResource();
98
99 /**
100  * Get an instance of CRL resource.
101  *
102  * @return reference to the @ref OicSecCrl_t, holding reference to CRL resource.
103  */
104 OicSecCrl_t *GetCRLResource();
105
106 /**
107  * This function frees resources inside given OicSecCrl_t object
108  *
109  * @param crl  crl object
110  */
111 void DeleteCrl(OicSecCrl_t *crl);
112
113 /**
114  * This function gets time when CRL was last updated in database
115  * Function allocates memory for lastUpdate and
116  * Caller is responsible to free that memory
117  *
118  * @param lastUpdate    pointer to last update string.
119  * @return ::OC_STACK_OK for Success, otherwise some error value.
120  */
121 OCStackResult getLastUpdateFromDB(char **lastUpdate);
122
123 /**
124  * This function prints OicSecCrl_t object
125  *
126  * @param crl  crl object
127  */
128 void printCrl(const OicSecCrl_t *crl);
129
130 #ifdef __cplusplus
131 }
132 #endif
133
134 #endif //IOTVT_SRM_CRLR_H