Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to prepare for ubuntu 22.04 CI #6635

Merged
merged 8 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/config_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void config_cache::read_cache(const std::string& file_path, config& cfg, abstrac
// Use a hash for a shorter display of the defines.
const std::string fname = cache_path + "/" +
cache_file_prefix_ +
utils::sha1(defines_string.str()).hex_digest();
utils::md5(defines_string.str()).hex_digest();
const std::string fname_checksum = fname + ".checksum" + extension;

filesystem::file_tree_checksum dir_checksum;
Expand Down
5 changes: 3 additions & 2 deletions src/generators/lua_map_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ lua_map_generator::lua_map_generator(const config & cfg, const config* vars)
, generator_data_(cfg)
{
lk_.load_core();
const std::array required {"id", "config_name", "create_map"};
for(const std::string& req : required) {
using namespace std::string_literals;
const std::array required {"id"s, "config_name"s, "create_map"s};
for(const auto& req : required) {
if (!cfg.has_attribute(req)) {
if(req == "create_map" && cfg.has_attribute("create_scenario")) {
// One of these is required, but not both
Expand Down
3 changes: 2 additions & 1 deletion src/gui/core/event/dispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,8 @@ class dispatcher
} else if constexpr(cat == event_category::text_input) {
return signal_text_input_queue_;
} else {
static_assert(utils::dependent_false_v<cat>, "No matching signal queue for category");
// "No matching signal queue for category"
utils::static_assert_false();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a negative change, as it loses the error message…

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was either this or remove it entirely, since Clang was rejecting the version that allowed an error message.

Copy link
Member

@Vultraz Vultraz Apr 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a clang bug. You're supposed to be able to use a message. Or did it have a problem with dependent_false_v?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like it could have been solved with decltype(cat).

}
}
};
Expand Down
46 changes: 14 additions & 32 deletions src/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,13 @@ extern "C" {

#ifndef __APPLE__

#include <openssl/sha.h>
#include <openssl/md5.h>

static_assert(utils::md5::DIGEST_SIZE == MD5_DIGEST_LENGTH, "Constants mismatch");
static_assert(utils::sha1::DIGEST_SIZE == SHA_DIGEST_LENGTH, "Constants mismatch");
#include <openssl/evp.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the MD5 static_assert here but not in the Apple section? You should probably remove either both or neither.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the new evp header doesn't have the constant to compare against anymore, and the evp header isn't used on Apple systems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well… how does it even know what the size is? Is it just hard-coded and will break if we ever change hash type?

Although, I guess if we change hash type we'd at least make a separate hashing class, so maybe that doesn't matter…

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow? Are there multiple types of MD5 hashes?


#else

#include <CommonCrypto/CommonDigest.h>

static_assert(utils::md5::DIGEST_SIZE == CC_MD5_DIGEST_LENGTH, "Constants mismatch");
static_assert(utils::sha1::DIGEST_SIZE == CC_SHA1_DIGEST_LENGTH, "Constants mismatch");

#endif

Expand Down Expand Up @@ -71,10 +66,19 @@ namespace utils {
md5::md5(const std::string& input) {

#ifndef __APPLE__
MD5_CTX md5_worker;
MD5_Init(&md5_worker);
MD5_Update(&md5_worker, input.data(), input.size());
MD5_Final(hash.data(), &md5_worker);
EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
unsigned int md5_digest_len = EVP_MD_size(EVP_md5());
assert(utils::md5::DIGEST_SIZE == md5_digest_len);

// MD5_Init
EVP_DigestInit_ex(mdctx, EVP_md5(), NULL);

// MD5_Update
EVP_DigestUpdate(mdctx, input.c_str(), input.size());

// MD5_Final
EVP_DigestFinal_ex(mdctx, hash.data(), &md5_digest_len);
EVP_MD_CTX_free(mdctx);
#else
CC_MD5(input.data(), static_cast<CC_LONG>(input.size()), hash.data());
#endif
Expand Down Expand Up @@ -124,28 +128,6 @@ std::string md5::base64_digest() const
return encode_hash<DIGEST_SIZE>(hash);
}

sha1::sha1(const std::string& str)
{
#ifndef __APPLE__
SHA_CTX hasher;
SHA1_Init(&hasher);
SHA1_Update(&hasher, str.data(), str.size());
SHA1_Final(hash.data(), &hasher);
#else
CC_MD5(str.data(), static_cast<CC_LONG>(str.size()), hash.data());
#endif
}

std::string sha1::hex_digest() const
{
return hexencode_hash<DIGEST_SIZE>(hash);
}

std::string sha1::base64_digest() const
{
return encode_hash<DIGEST_SIZE>(hash);
}

bcrypt::bcrypt(const std::string& input)
{
assert(is_valid_prefix(input));
Expand Down
10 changes: 1 addition & 9 deletions src/hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class hash_digest : public hash_base
protected:
std::array<T, sz> hash;
public:
static const int DIGEST_SIZE = sz;
static const unsigned int DIGEST_SIZE = sz;
std::array<T, sz> raw_digest() const {return hash;}
};

Expand All @@ -62,14 +62,6 @@ class md5 : public hash_digest<16>
virtual std::string hex_digest() const override;
};

class sha1 : public hash_digest<20>
{
public:
explicit sha1(const std::string& input);
virtual std::string base64_digest() const override;
virtual std::string hex_digest() const override;
};

class bcrypt : public hash_digest<BCRYPT_HASHSIZE, char>
{
bcrypt() {}
Expand Down
5 changes: 2 additions & 3 deletions src/utils/general.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ inline constexpr bool decayed_is_same = std::is_same_v<std::decay_t<T1>, std::de

/**
* Workaround for the fact that static_assert(false) is invalid.
* See https://devblogs.microsoft.com/oldnewthing/20200311-00/?p=103553
*/
template<typename>
inline constexpr bool dependent_false_v = false;
template<bool flag = false>
void static_assert_false() { static_assert(flag); }

namespace detail
{
Expand Down