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_PAKE_) || defined(_CUT_PAKE_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 "pake_server.h"
24 #include "key_agreement_version.h"
25 #include "parsedata.h"
26 
parse_pake_server_confirm(const char * payload,enum json_object_data_type data_type)27 void *parse_pake_server_confirm(const char *payload, enum json_object_data_type data_type)
28 {
29     struct pake_end_response_data *pake_server_confirm =
30         (struct pake_end_response_data *)MALLOC(sizeof(struct pake_end_response_data));
31     if (pake_server_confirm == NULL) {
32         return NULL;
33     }
34     (void)memset_s(pake_server_confirm, sizeof(*pake_server_confirm), 0, sizeof(*pake_server_confirm));
35     json_handle obj = parse_payload(payload, data_type);
36     if (obj == NULL) {
37         LOGE("Parse Pake Server Confirm parse payload failed");
38         goto error;
39     }
40     /* kcfData */
41     int32_t result = byte_convert(obj, FIELD_KCF_DATA, pake_server_confirm->kcf_data.hmac,
42                                   (uint32_t *)&pake_server_confirm->kcf_data.length, HC_HMAC_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 *)pake_server_confirm;
49 error:
50     free_payload(obj, data_type);
51     FREE(pake_server_confirm);
52     return NULL;
53 }
54 
free_pake_server_confirm(void * obj)55 void free_pake_server_confirm(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(pake_server_confirm)
66 
67 #endif /* _CUT_XXX_ */
68