1 /* 2 * Copyright (c) 2022 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 PKG_VERIFY_UTIL_H 17 #define PKG_VERIFY_UTIL_H 18 19 #include <vector> 20 #include "pkcs7_signed_data.h" 21 #include "pkg_stream.h" 22 23 namespace Hpackage { 24 class PkgVerifyUtil { 25 public: PkgVerifyUtil()26 PkgVerifyUtil() {} 27 ~PkgVerifyUtil()28 ~PkgVerifyUtil() {} 29 30 int32_t VerifyPackageSign(const Hpackage::PkgStreamPtr PkgStream) const; 31 32 int32_t GetSignature(const PkgStreamPtr pkgStream, size_t &signatureSize, 33 std::vector<uint8_t> &signature, uint16_t &commentTotalLenAll) const; 34 #ifndef UPDATER_UT 35 private: 36 #else 37 public: 38 #endif 39 40 int32_t ParsePackage(const PkgStreamPtr pkgStream, size_t &signatureStart, 41 size_t &signatureSize, uint16_t &commentTotalLenAll) const; 42 43 int32_t Pkcs7verify(std::vector<uint8_t> &signature, std::vector<uint8_t> &hash) const; 44 45 int32_t HashCheck(const PkgStreamPtr srcData, const size_t dataLen, 46 const std::vector<uint8_t> &hash) const; 47 }; 48 } // namespace Hpackage 49 #endif 50