aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.h
diff options
context:
space:
mode:
authorJeffrey Ryan <jeffreyryan@tutanota.com>2022-05-17 22:40:36 +0200
committerselsta <selsta@sent.at>2022-05-18 01:34:16 +0200
commita66a52d14497c3295274e54fb9e0d2d0980004bb (patch)
treef8ecff7fb99c11a1ed0695b0566f429f1c20ecad /src/common/util.h
parentMerge pull request #8315 (diff)
downloadmonero-a66a52d14497c3295274e54fb9e0d2d0980004bb.tar.xz
common: update sha256sum to use OpenSSL 3.0 API
As of OpenSSL 3.0, `SHA256_Init`, `SHA256_Update`, and `SHA256_Final` are deprectaed in favor of the higher-level `EVP_*` class of functions. This causes compiler warnings, and sooner or later, will cause build errors as these functions are excluded from distro headers. Also add some documentation.
Diffstat (limited to '')
-rw-r--r--src/common/util.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/common/util.h b/src/common/util.h
index 25f5ceb47..f489594e8 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -231,7 +231,27 @@ namespace tools
bool is_privacy_preserving_network(const std::string &address);
int vercmp(const char *v0, const char *v1); // returns < 0, 0, > 0, similar to strcmp, but more human friendly than lexical - does not attempt to validate
+ /**
+ * \brief Creates a SHA-256 digest of a data buffer
+ *
+ * \param[in] data pointer to the buffer
+ * \param[in] len size of the buffer in bytes
+ * \param[out] hash where message digest will be written to
+ *
+ * \returns true if successful, false otherwise
+ */
bool sha256sum(const uint8_t *data, size_t len, crypto::hash &hash);
+
+ /**
+ * \brief Creates a SHA-256 digest of a file's contents, equivalent to the sha256sum command in Linux
+ *
+ * \param[in] filename path to target file
+ * \param[out] hash where message digest will be written to
+ *
+ * \returns true if successful, false if the file can not be opened or there is an OpenSSL failure
+ *
+ * \throws ios_base::failure if after the file is successfully opened, an error occurs during reading
+ */
bool sha256sum(const std::string &filename, crypto::hash &hash);
boost::optional<bool> is_hdd(const char *path);