1 /*
2 * This file is part of the openHiTLS project.
3 *
4 * openHiTLS is licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *
8 * http://license.coscl.org.cn/MulanPSL2
9 *
10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13 * See the Mulan PSL v2 for more details.
14 */
15 #include "hitls_build.h"
16 #ifdef HITLS_TLS_FEATURE_SECURITY
17 #include <stdint.h>
18 #include "bsl_err_internal.h"
19 #include "hitls_error.h"
20 #include "hitls_security.h"
21 #include "tls.h"
22
HITLS_CFG_SetSecurityLevel(HITLS_Config * config,int32_t securityLevel)23 int32_t HITLS_CFG_SetSecurityLevel(HITLS_Config *config, int32_t securityLevel)
24 {
25 if (config == NULL) {
26 BSL_ERR_PUSH_ERROR(HITLS_NULL_INPUT);
27 return HITLS_NULL_INPUT;
28 }
29
30 config->securityLevel = securityLevel;
31 return HITLS_SUCCESS;
32 }
33
HITLS_CFG_GetSecurityLevel(const HITLS_Config * config,int32_t * securityLevel)34 int32_t HITLS_CFG_GetSecurityLevel(const HITLS_Config *config, int32_t *securityLevel)
35 {
36 if (config == NULL || securityLevel == NULL) {
37 BSL_ERR_PUSH_ERROR(HITLS_NULL_INPUT);
38 return HITLS_NULL_INPUT;
39 }
40
41 *securityLevel = config->securityLevel;
42 return HITLS_SUCCESS;
43 }
44
HITLS_CFG_SetSecurityCb(HITLS_Config * config,HITLS_SecurityCb securityCb)45 int32_t HITLS_CFG_SetSecurityCb(HITLS_Config *config, HITLS_SecurityCb securityCb)
46 {
47 if (config == NULL) {
48 BSL_ERR_PUSH_ERROR(HITLS_NULL_INPUT);
49 return HITLS_NULL_INPUT;
50 }
51
52 config->securityCb = securityCb;
53 return HITLS_SUCCESS;
54 }
55
HITLS_CFG_GetSecurityCb(const HITLS_Config * config)56 HITLS_SecurityCb HITLS_CFG_GetSecurityCb(const HITLS_Config *config)
57 {
58 if (config == NULL) {
59 return NULL;
60 }
61
62 return config->securityCb;
63 }
64
HITLS_CFG_SetSecurityExData(HITLS_Config * config,void * securityExData)65 int32_t HITLS_CFG_SetSecurityExData(HITLS_Config *config, void *securityExData)
66 {
67 if (config == NULL) {
68 BSL_ERR_PUSH_ERROR(HITLS_NULL_INPUT);
69 return HITLS_NULL_INPUT;
70 }
71
72 config->securityExData = securityExData;
73 return HITLS_SUCCESS;
74 }
75
HITLS_CFG_GetSecurityExData(const HITLS_Config * config)76 void *HITLS_CFG_GetSecurityExData(const HITLS_Config *config)
77 {
78 if (config == NULL) {
79 return NULL;
80 }
81
82 return config->securityExData;
83 }
84
HITLS_SetSecurityLevel(HITLS_Ctx * ctx,int32_t securityLevel)85 int32_t HITLS_SetSecurityLevel(HITLS_Ctx *ctx, int32_t securityLevel)
86 {
87 if (ctx == NULL) {
88 BSL_ERR_PUSH_ERROR(HITLS_NULL_INPUT);
89 return HITLS_NULL_INPUT;
90 }
91
92 return HITLS_CFG_SetSecurityLevel(&(ctx->config.tlsConfig), securityLevel);
93 }
94
HITLS_GetSecurityLevel(const HITLS_Ctx * ctx,int32_t * securityLevel)95 int32_t HITLS_GetSecurityLevel(const HITLS_Ctx *ctx, int32_t *securityLevel)
96 {
97 if (ctx == NULL || securityLevel == NULL) {
98 BSL_ERR_PUSH_ERROR(HITLS_NULL_INPUT);
99 return HITLS_NULL_INPUT;
100 }
101
102 return HITLS_CFG_GetSecurityLevel(&(ctx->config.tlsConfig), securityLevel);
103 }
104
HITLS_SetSecurityCb(HITLS_Ctx * ctx,HITLS_SecurityCb securityCb)105 int32_t HITLS_SetSecurityCb(HITLS_Ctx *ctx, HITLS_SecurityCb securityCb)
106 {
107 if (ctx == NULL) {
108 BSL_ERR_PUSH_ERROR(HITLS_NULL_INPUT);
109 return HITLS_NULL_INPUT;
110 }
111
112 return HITLS_CFG_SetSecurityCb(&(ctx->config.tlsConfig), securityCb);
113 }
114
HITLS_GetSecurityCb(const HITLS_Ctx * ctx)115 HITLS_SecurityCb HITLS_GetSecurityCb(const HITLS_Ctx *ctx)
116 {
117 if (ctx == NULL) {
118 return NULL;
119 }
120
121 return HITLS_CFG_GetSecurityCb(&(ctx->config.tlsConfig));
122 }
123
HITLS_SetSecurityExData(HITLS_Ctx * ctx,void * securityExData)124 int32_t HITLS_SetSecurityExData(HITLS_Ctx *ctx, void *securityExData)
125 {
126 if (ctx == NULL) {
127 BSL_ERR_PUSH_ERROR(HITLS_NULL_INPUT);
128 return HITLS_NULL_INPUT;
129 }
130
131 return HITLS_CFG_SetSecurityExData(&(ctx->config.tlsConfig), securityExData);
132 }
133
HITLS_GetSecurityExData(const HITLS_Ctx * ctx)134 void *HITLS_GetSecurityExData(const HITLS_Ctx *ctx)
135 {
136 if (ctx == NULL) {
137 return NULL;
138 }
139
140 return HITLS_CFG_GetSecurityExData(&(ctx->config.tlsConfig));
141 }
142 #endif /* HITLS_TLS_FEATURE_SECURITY */