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 HASH_DATA_VERIFIER_H 17 #define HASH_DATA_VERIFIER_H 18 19 #include "pkg_manager.h" 20 21 struct HashSignedData; 22 23 namespace Hpackage { 24 class Pkcs7SignedData; 25 // class for verification of hash signed data 26 class HashDataVerifier final { 27 public: 28 HashDataVerifier(PkgManager::PkgManagerPtr manager); 29 bool LoadHashDataAndPkcs7(const std::string &pkgPath); 30 bool VerifyHashData(const std::string &preName, const std::string &fileName, PkgManager::StreamPtr stream) const; 31 bool LoadPkcs7FromPackage(const std::string &pkgPath); 32 bool LoadHashDataFromPackage(const std::string &buffer); 33 ~HashDataVerifier(); 34 private: 35 bool LoadHashDataFromPackage(void); 36 PkgManager::PkgManagerPtr manager_ {nullptr}; 37 std::unique_ptr<Pkcs7SignedData> pkcs7_ {nullptr}; 38 const HashSignedData *hsd_ {nullptr}; 39 bool isNeedVerify_ = true; 40 }; 41 } 42 43 #endif