fourdst_plugin 0.0.1a
C++ Plugin Manager
Loading...
Searching...
No Matches
fourdst::crypt::utils Namespace Reference

Functions

std::string get_openssl_error ()
 Retrieves the most recent OpenSSL error messages as a formatted string.
 
std::string calculate_sha256 (const std::filesystem::path &filepath)
 Calculates the SHA-256 hash of a file's contents.
 
std::string calculate_sha256_from_buffer (const std::vector< unsigned char > &data)
 Calculates the SHA-256 hash of a binary buffer.
 

Function Documentation

◆ calculate_sha256()

std::string fourdst::crypt::utils::calculate_sha256 ( const std::filesystem::path & filepath)

Calculates the SHA-256 hash of a file's contents.

This function reads the contents of the specified file and calculates its SHA-256 hash. The hash is returned as a hexadecimal string.

Parameters
[in]filepathThe path to the file to hash.
Returns
std::string The SHA-256 hash of the file contents as a lowercase hexadecimal string.
Exceptions
std::runtime_errorIf the file cannot be opened or read.
std::runtime_errorIf an OpenSSL error occurs during hashing.
Note
The file is read in binary mode.
Example
try {
std::string hash = fourdst::crypt::utils::calculate_sha256("document.txt");
std::cout << "SHA-256 hash: " << hash << std::endl;
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
std::string calculate_sha256(const std::filesystem::path &filepath)
Calculates the SHA-256 hash of a file's contents.
Definition sha256.cpp:10

◆ calculate_sha256_from_buffer()

std::string fourdst::crypt::utils::calculate_sha256_from_buffer ( const std::vector< unsigned char > & data)

Calculates the SHA-256 hash of a binary buffer.

This function calculates the SHA-256 hash of the provided binary data buffer and returns the result as a hexadecimal string.

Parameters
[in]dataThe binary data to hash.
Returns
std::string The SHA-256 hash of the input data as a lowercase hexadecimal string.
Exceptions
std::runtime_errorIf an OpenSSL error occurs during hashing.
Example
std::vector<unsigned char> data = {'h', 'e', 'l', 'l', 'o'};
std::cout << "SHA-256 hash: " << hash << std::endl;
std::string calculate_sha256_from_buffer(const std::vector< unsigned char > &data)
Calculates the SHA-256 hash of a binary buffer.
Definition sha256.cpp:56

◆ get_openssl_error()

std::string fourdst::crypt::utils::get_openssl_error ( )
inline

Retrieves the most recent OpenSSL error messages as a formatted string.

This function retrieves all pending OpenSSL error messages from the error queue and returns them as a single formatted string. Each error is separated by a semicolon.

Returns
std::string A string containing all pending OpenSSL error messages.
Note
This function clears the OpenSSL error queue after retrieving the messages.
Example
if (some_openssl_function() != 1) {
std::cerr << "OpenSSL error: " << fourdst::crypt::utils::get_openssl_error() << std::endl;
}
std::string get_openssl_error()
Retrieves the most recent OpenSSL error messages as a formatted string.
Definition openSSL_utils.h:35