добавил sha256 для файла обновления

This commit is contained in:
2024-11-14 11:34:28 +03:00
parent 0dcc562b7d
commit eda26319c4
5 changed files with 15 additions and 6 deletions

View File

@@ -9,9 +9,12 @@
std::string http::utils::sha256(const std::string &payload) {
// Вычисляем SHA256 хеш
return sha256(payload.c_str(), payload.size());
}
std::string http::utils::sha256(const char* data, size_t size) {
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256(reinterpret_cast<const unsigned char *>(payload.c_str()), payload.length(), hash);
SHA256(reinterpret_cast<const unsigned char *>(data), size, hash);
// Преобразуем хеш в шестнадцатеричную строку
std::stringstream ss;

View File

@@ -6,6 +6,7 @@
namespace http::utils {
std::string sha256(const std::string& payload);
std::string sha256(const char* data, size_t size);
std::string sha256AsB64(const std::string& payload);
std::string b64Encode(const char* data, size_t size);

View File

@@ -19,6 +19,7 @@
#include "terminal_api_driver.h"
#include "auth/resources.h"
#include "auth/jwt.h"
#include "auth/utils.h"
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
@@ -347,7 +348,9 @@ public:
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
std::string result = R"({"status":"ok","fwsize":)";
result += std::to_string(req.payload.size());
result += "}";
result += ",\"sha256\":\"";
result += http::utils::sha256(req.payload.data(), req.payload.size());
result += "\"}";
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
}));
}

View File

@@ -3,8 +3,6 @@
#include <fstream>
#include <utility>
#include "../../dependencies/control_system/common/protocol_commands.h"
static void loadFile(const std::string& path, std::vector<char>& content) {
std::ifstream is(path, std::ios::in | std::ios::binary);
if (!is) {