2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "vine-auth.h"
23 unsigned char *alloc_auth_frame(unsigned char ver,
24 unsigned char auth_type, unsigned char op,
25 int data_len, const unsigned char *data, int *size)
28 unsigned char *buf = (unsigned char *)calloc(*size, sizeof(unsigned char));
30 VINE_LOGE("Out of memory");
37 buf[3] = (0xFF00 & data_len) >> 8;
38 buf[4] = (0xFF & data_len);
39 memcpy(&buf[5], data, data_len);
44 void release_auth_frame(unsigned char *buf)
49 bool parse_auth_frame(unsigned char *buf, size_t buf_size,
50 unsigned char *ver, unsigned char *auth_type,
51 unsigned char *op, int *data_len, unsigned char **data)
56 *data_len = (buf[3] << 8) | (buf[4]);
57 *data = (unsigned char *)malloc(*data_len);
59 VINE_LOGE("Out of memory");
62 memcpy(*data, &buf[5], *data_len);
64 // TODO: Need to check if it is an auth frame or not