From 7b22c92ac1265f439f8e2623c4a1d6b45bbb05f2 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 16 Mar 2017 17:37:38 -0700 Subject: Drop the dependency on 'ui' in verify_file(). verify_file() has a dependency on the global variable of 'ui' for posting the verification progress, which requires the users of libverifier to provide a UI instance. This CL adds an optional argument to verify_file() so that it can post the progress through the provided callback function. As a result, we can drop the MockUI class in verifier_test.cpp. Test: recovery_component_test passes. Test: verify_file() posts progress update when installing an OTA. Change-Id: I8b87d0f0d99777ea755d33d6dbbe2b6d44243bf1 (cherry picked from commit 5e535014dd7961fbf812abeaa27f3339775031f1) --- install.cpp | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'install.cpp') diff --git a/install.cpp b/install.cpp index f51bbf05c..68d3f54bc 100644 --- a/install.cpp +++ b/install.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -578,23 +579,24 @@ install_package(const char* path, bool* wipe_cache, const char* install_file, } bool verify_package(const unsigned char* package_data, size_t package_size) { - std::vector loadedKeys; - if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) { - LOG(ERROR) << "Failed to load keys"; - return false; - } - LOG(INFO) << loadedKeys.size() << " key(s) loaded from " << PUBLIC_KEYS_FILE; - - // Verify package. - ui->Print("Verifying update package...\n"); - auto t0 = std::chrono::system_clock::now(); - int err = verify_file(const_cast(package_data), package_size, loadedKeys); - std::chrono::duration duration = std::chrono::system_clock::now() - t0; - ui->Print("Update package verification took %.1f s (result %d).\n", duration.count(), err); - if (err != VERIFY_SUCCESS) { - LOG(ERROR) << "Signature verification failed"; - LOG(ERROR) << "error: " << kZipVerificationFailure; - return false; - } - return true; + std::vector loadedKeys; + if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) { + LOG(ERROR) << "Failed to load keys"; + return false; + } + LOG(INFO) << loadedKeys.size() << " key(s) loaded from " << PUBLIC_KEYS_FILE; + + // Verify package. + ui->Print("Verifying update package...\n"); + auto t0 = std::chrono::system_clock::now(); + int err = verify_file(const_cast(package_data), package_size, loadedKeys, + std::bind(&RecoveryUI::SetProgress, ui, std::placeholders::_1)); + std::chrono::duration duration = std::chrono::system_clock::now() - t0; + ui->Print("Update package verification took %.1f s (result %d).\n", duration.count(), err); + if (err != VERIFY_SUCCESS) { + LOG(ERROR) << "Signature verification failed"; + LOG(ERROR) << "error: " << kZipVerificationFailure; + return false; + } + return true; } -- cgit v1.2.3