1/*
2 * Copyright (c) 2024-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#ifndef SIGNATURETOOLS_FS_DIGEST_UTILS_H
16#define SIGNATURETOOLS_FS_DIGEST_UTILS_H
17
18#include <string>
19#include <openssl/evp.h>
20#include <openssl/sha.h>
21#include <openssl/ssl.h>
22#include <openssl/bio.h>
23#include <openssl/err.h>
24#include <openssl/pem.h>
25#include <openssl/x509v3.h>
26#include <openssl/ec.h>
27#include <openssl/pkcs12.h>
28#include <memory>
29#include <map>
30
31#include "signature_tools_log.h"
32
33namespace OHOS {
34namespace SignatureTools {
35
36using hashFunc = const EVP_MD* (*)(void);
37
38enum HashType {
39    HASH_SHA256,
40    HASH_SHA384
41};
42
43class DigestUtils {
44public:
45    enum class Type :char {
46        BINARY, HEX
47    };
48    explicit DigestUtils(HashType type);
49    ~DigestUtils();
50    void AddData(const std::string &data);
51    void AddData(const char* data, int length);
52    std::string Result(Type type = Type::HEX);
53
54private:
55    EVP_MD_CTX* m_ctx = NULL;
56    HashType m_type;
57};
58} // namespace SignatureTools
59} // namespace OHOS
60#endif // SIGNATURETOOLS_FS_DIGEST_UTILS_H
61