/* Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef __COMMON_H__
#define __COMMON_H__

#include "logging.h"
#include "securec.h"
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <openssl/asn1.h>
#include <openssl/types.h>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define RET_OK              0
#define RET_ERR             (-1)
#define RET_ERR_INVALID_CMD (-2)
#define RET_ERR_TIMEOUT     (-3)

#define UINT8_STEP   (8)
#define UINT8_STEP2  (16)
#define BASE64_STEP  (6)
#define BASE64_STEP2 (BASE64_STEP * 2)
#define BASE64_STEP3 (BASE64_STEP * 3)
#define BASE64_BASE  (63)

const static char base64_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

time_t GetAsnDate(const ASN1_TIME* time);

void ConvertStringToBytes(const char* input, size_t input_len, uint8_t* output, size_t output_len);

string ConvertBytesToString(const uint8_t* input, size_t input_len);

string base64Encode(const vector<uint8_t>& data);

#endif // __COMMON_H__