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 "pake_server.h"
23 #include "key_agreement_version.h"
24 #include "parsedata.h"
25
free_pake_request(void * obj)26 void free_pake_request(void *obj)
27 {
28 if (obj != NULL) {
29 FREE(obj);
30 }
31 }
32
make_pake_request(void * data)33 char *make_pake_request(void *data)
34 {
35 struct pake_start_request_data *pake_request = data;
36 char *ret_str = (char *)MALLOC(RET_STR_LENGTH);
37 if (ret_str == NULL) {
38 return NULL;
39 }
40 (void)memset_s(ret_str, RET_STR_LENGTH, 0, RET_STR_LENGTH);
41 if (snprintf_s(ret_str, RET_STR_LENGTH, RET_STR_LENGTH - 1,
42 "{\"%s\":%d,\"%s\":{\"%s\":{\"%s\":\"%u.%u.%u\",\"%s\":\"%u.%u.%u\"},\"%s\":true,\"%s\":%d}}",
43 FIELD_MESSAGE, PAKE_REQUEST, FIELD_PAYLOAD, FIELD_VERSION, FIELD_CURRENT_VERSION,
44 pake_request->peer_version.first, pake_request->peer_version.second,
45 pake_request->peer_version.third, FIELD_MIN_VERSION,
46 pake_request->peer_support_version.first, pake_request->peer_support_version.second,
47 pake_request->peer_support_version.third, FIELD_SUPPORT_256_MOD,
48 FIELD_OPERATION_CODE, pake_request->operation_code) < 0) {
49 LOGE("String generate failed");
50 FREE(ret_str);
51 ret_str = NULL;
52 }
53 return ret_str;
54 }
55
56 #else /* _CUT_XXX_ */
57
58 #include "parsedata.h"
59 DEFINE_EMPTY_STRUCT_FUNC(pake_request)
60
61 #endif /* _CUT_XXX_ */
62