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 33 using hashFunc = const EVP_MD* (*)(void); 34 35 enum HashType { 36 HASH_SHA256, 37 HASH_SHA384 38 }; 39 40 class DigestUtils { 41 public: 42 enum class Type :char { 43 BINARY, HEX 44 }; 45 explicit DigestUtils(HashType type); 46 ~DigestUtils(); 47 void AddData(const std::string &data); 48 void AddData(const char* data, int length); 49 std::string Result(Type type = Type::HEX); 50 51 private: 52 EVP_MD_CTX* m_ctx = NULL; 53 HashType m_type; 54 }; 55 #endif // SIGNATURETOOLS_FS_DIGEST_UTILS_H 56