1 /* 2 * Copyright (c) 2023 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 SHA256_UTILS_H 17 #define SHA256_UTILS_H 18 19 #include <string> 20 21 #include "securec.h" 22 23 #include "update_log.h" 24 25 namespace OHOS { 26 namespace UpdateEngine { 27 class Sha256Utils { 28 public: 29 static std::string CalculateHashCode(std::string inputStr); 30 static bool CheckFileSha256String(const std::string &fileName, const std::string &sha256String); 31 32 private: 33 static bool GetFileSha256Str(const std::string &fileName, char *sha256Result, uint32_t len); 34 static bool GetDigestFromFile(const char *fileName, unsigned char digest[]); 35 static bool Sha256Calculate(const unsigned char *input, int len, char *componentId, int componentIdLen); 36 static bool TransDigestToSha256Result(char *sha256Result, uint32_t componentIdLen, const unsigned char *digest); 37 }; 38 } // namespace UpdateEngine 39 } // namespace OHOS 40 #endif // SHA256_UTILS_H