implemented configurable checksum algorithm, defaults to sha256, introduces openssl dependency to build module

This commit is contained in:
Chris Punches
2025-03-15 21:27:21 -04:00
parent 1f4f73ff0f
commit aad077a24a
6 changed files with 213 additions and 10 deletions

View File

@@ -0,0 +1,48 @@
/**
* @file checksums.hpp
* @brief Functions for generating cryptographic checksums
*
* Provides functionality for generating checksums of files using
* configurable cryptographic hash algorithms via OpenSSL.
*
* @copyright Copyright (c) 2025 SILO GROUP LLC
* @author Chris Punches <chris.punches@silogroup.org>
*
* Part of the Dark Horse Linux Package Manager (DPM)
*/
#pragma once
#include <string>
#include <filesystem>
/**
* @brief Gets the configured hash algorithm or defaults to SHA-256
*
* Retrieves the hash algorithm configured in the cryptography section
* or defaults to SHA-256 if not specified.
*
* @return String containing the name of the hash algorithm to use
*/
std::string get_configured_hash_algorithm();
/**
* @brief Gets a list of available digest algorithms from OpenSSL
*
* Retrieves a list of supported digest algorithms from OpenSSL's
* internal algorithms list.
*
* @return String containing comma-separated list of available algorithms
*/
std::string get_available_algorithms();
/**
* @brief Generates a file checksum using the configured hashing algorithm
*
* Uses OpenSSL to calculate a cryptographic hash of a file's contents
* based on the algorithm specified in the configuration.
* This method reads the file in chunks to handle large files efficiently.
*
* @param file_path Path to the file to be hashed
* @return String containing the hexadecimal representation of the checksum, or empty string on error
*/
std::string generate_file_checksum(const std::filesystem::path& file_path);

View File

@@ -19,6 +19,7 @@
#include <dpmdk/include/CommonModuleAPI.hpp>
#include <pwd.h>
#include <grp.h>
#include "checksums.hpp"
/**
* @brief Stages a DPM package