/* * Copyright (C) 2026 oxmc / PawletOS * SPDX-License-Identifier: Apache-2.0 */ #include "util.h" #include #include #include #include #include namespace pawlet::hwupdate::util { std::string Sha256File(const std::string& path) { FILE* f = fopen(path.c_str(), "rb"); if (!f) return {}; SHA256_CTX ctx; SHA256_Init(&ctx); std::array buf; size_t n; while ((n = fread(buf.data(), 1, buf.size(), f)) > 0) { SHA256_Update(&ctx, buf.data(), n); } bool ok = feof(f) != 0; fclose(f); if (!ok) return {}; unsigned char digest[SHA256_DIGEST_LENGTH]; SHA256_Final(digest, &ctx); static const char* hex = "0123456789abcdef"; std::string out; out.reserve(SHA256_DIGEST_LENGTH * 2); for (unsigned char c : digest) { out.push_back(hex[c >> 4]); out.push_back(hex[c & 0xf]); } return out; } bool IEquals(const std::string& a, const std::string& b) { if (a.size() != b.size()) return false; for (size_t i = 0; i < a.size(); ++i) { if (std::tolower(static_cast(a[i])) != std::tolower(static_cast(b[i]))) { return false; } } return true; } std::string Prop(const std::string& key, const std::string& def) { return android::base::GetProperty(key, def); } } // namespace pawlet::hwupdate::util