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
parse_auth_ack_response(const char * payload,enum json_object_data_type data_type)27 void *parse_auth_ack_response(const char *payload, enum json_object_data_type data_type)
28 {
29 struct sts_end_response_data *auth_ack_response =
30 (struct sts_end_response_data *)MALLOC(sizeof(struct sts_end_response_data));
31 if (auth_ack_response == NULL) {
32 return NULL;
33 }
34 (void)memset_s(auth_ack_response, sizeof(*auth_ack_response), 0, sizeof(*auth_ack_response));
35 json_handle obj = parse_payload(payload, data_type);
36 if (obj == NULL) {
37 LOGE("Parse Auth ACK Response parse payload failed");
38 goto error;
39 }
40 /* authData */
41 int32_t result = byte_convert(obj, FIELD_AUTH_RETURN, auth_ack_response->auth_return.auth_return,
42 (uint32_t *)&auth_ack_response->auth_return.length, HC_AUTH_DATA_BUFF_LEN);
43 if (result != HC_OK) {
44 LOGE("Parse Auth ACK Request Data failed, field is null in addId");
45 goto error;
46 }
47 free_payload(obj, data_type);
48 return (void *)auth_ack_response;
49 error:
50 free_payload(obj, data_type);
51 FREE(auth_ack_response);
52 return NULL;
53 }
54
free_auth_ack_response(void * obj)55 void free_auth_ack_response(void *obj)
56 {
57 if (obj != NULL) {
58 FREE(obj);
59 }
60 }
61
62 #else /* _CUT_XXX_ */
63
64 #include "parsedata.h"
65 DEFINE_EMPTY_STRUCT_FUNC(auth_ack_response)
66
67 #endif /* _CUT_XXX_ */
68