fixed available algo enumeration
parent
aad077a24a
commit
5ec3c0ca83
|
@ -31,28 +31,23 @@ std::string get_configured_hash_algorithm()
|
||||||
std::string get_available_algorithms()
|
std::string get_available_algorithms()
|
||||||
{
|
{
|
||||||
std::stringstream algorithms;
|
std::stringstream algorithms;
|
||||||
|
bool first = true;
|
||||||
|
|
||||||
// The OBJ_NAME_do_all_sorted will call the supplied callback function
|
// Only list algorithms that are actually usable for file checksums
|
||||||
// for each algorithm
|
const char* usable_digests[] = {
|
||||||
struct AlgorithmCollector {
|
"md5", "sha1", "sha224", "sha256", "sha384", "sha512"
|
||||||
static void callback(const OBJ_NAME* obj, void* arg) {
|
|
||||||
if (obj->type == OBJ_NAME_TYPE_MD_METH) {
|
|
||||||
std::stringstream* ss = static_cast<std::stringstream*>(arg);
|
|
||||||
if (!ss->str().empty()) {
|
|
||||||
*ss << ", ";
|
|
||||||
}
|
|
||||||
*ss << obj->name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize OpenSSL objects
|
for (const char* digest : usable_digests) {
|
||||||
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS, NULL);
|
// Verify the algorithm is actually available in this OpenSSL build
|
||||||
|
if (EVP_get_digestbyname(digest) != nullptr) {
|
||||||
// Collect all digest algorithm names
|
if (!first) {
|
||||||
OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_MD_METH,
|
algorithms << ", ";
|
||||||
reinterpret_cast<void (*)(const OBJ_NAME*, void*)>(AlgorithmCollector::callback),
|
}
|
||||||
&algorithms);
|
algorithms << digest;
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return algorithms.str();
|
return algorithms.str();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue