1 /*
2  * Copyright (c) 2020 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #if !(defined(_CUT_STS_) || defined(_CUT_STS_SERVER_))
17 
18 #include "securec.h"
19 #include "log.h"
20 #include "mem_stat.h"
21 #include "jsonutil.h"
22 #include "commonutil.h"
23 #include "parsedata.h"
24 #include "add_auth_info.h"
25 #include "key_agreement_version.h"
26 
27 
free_auth_ack_request(void * obj)28 void free_auth_ack_request(void *obj)
29 {
30     if (obj != NULL) {
31         FREE(obj);
32     }
33 }
34 
make_auth_ack_request(void * data)35 char *make_auth_ack_request(void *data)
36 {
37     struct sts_end_request_data *auth_ack_request = data;
38     /* authdata */
39     uint8_t *tmp_data_hex = raw_byte_to_hex_string(auth_ack_request->auth_data.auth_data,
40                                                    auth_ack_request->auth_data.length);
41     if (tmp_data_hex == NULL) {
42         return NULL;
43     }
44     char *ret_str = (char *)MALLOC(RET_STR_LENGTH);
45     if (ret_str == NULL) {
46         FREE(tmp_data_hex);
47         return NULL;
48     }
49     (void)memset_s(ret_str, RET_STR_LENGTH, 0, RET_STR_LENGTH);
50     if (snprintf_s(ret_str, RET_STR_LENGTH, RET_STR_LENGTH - 1, "{\"%s\":%d,\"%s\":%d,\"%s\":{\"%s\":\"%s\"}}",
51         FIELD_AUTH_FORM, AUTH_FORM, FIELD_MESSAGE, AUTH_ACK_REQUEST, FIELD_PAYLOAD,
52         FIELD_AUTH_DATA, tmp_data_hex) < 0) {
53         LOGE("String generate failed");
54         FREE(ret_str);
55         ret_str = NULL;
56     }
57     FREE(tmp_data_hex);
58     return ret_str;
59 }
60 
61 #else /* _CUT_XXX_ */
62 
63 #include "parsedata.h"
64 DEFINE_EMPTY_STRUCT_FUNC(auth_ack_request)
65 
66 #endif /* _CUT_XXX_ */
67