1/*
2 * Copyright (c) 2023-2024 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#ifndef CODE_SIGN_OPENSSL_UTILS_H
17#define CODE_SIGN_OPENSSL_UTILS_H
18
19#include <string>
20#include <vector>
21#include <openssl/x509.h>
22#include <openssl/err.h>
23
24#include "byte_buffer.h"
25#include "log.h"
26
27namespace OHOS {
28namespace Security {
29namespace CodeSign {
30constexpr int OPENSSL_ERR_MESSAGE_MAX_LEN = 1024;
31
32void GetOpensslErrorMessage();
33
34#define ERR_LOG_WITH_OPEN_SSL_MSG(msg) do { \
35    LOG_ERROR("%{public}s", msg); \
36    GetOpensslErrorMessage(); \
37} while (0)
38
39X509 *LoadCertFromBuffer(const uint8_t *buffer, const uint32_t size);
40STACK_OF(X509) *MakeStackOfCerts(const std::vector<ByteBuffer> &certChain);
41int CreateNIDFromOID(const std::string &oid, const std::string &shortName,
42    const std::string &longName);
43bool ConvertCertToPEMString(const ByteBuffer &cert, std::string &pemString);
44}
45}
46}
47#endif