summaryrefslogtreecommitdiffstats
path: root/src/core/crypto/key_manager.h
diff options
context:
space:
mode:
authorZach Hilman <zachhilman@gmail.com>2018-08-16 23:10:01 +0200
committerZach Hilman <zachhilman@gmail.com>2018-08-23 17:53:30 +0200
commitcde665c56514c1b701c0fe94fc943c7692be7f32 (patch)
tree70ab7a531c27b88c423f08c3fd84313dad2fe081 /src/core/crypto/key_manager.h
parentgame_list: Add SD registration loading to game list (diff)
downloadyuzu-cde665c56514c1b701c0fe94fc943c7692be7f32.tar
yuzu-cde665c56514c1b701c0fe94fc943c7692be7f32.tar.gz
yuzu-cde665c56514c1b701c0fe94fc943c7692be7f32.tar.bz2
yuzu-cde665c56514c1b701c0fe94fc943c7692be7f32.tar.lz
yuzu-cde665c56514c1b701c0fe94fc943c7692be7f32.tar.xz
yuzu-cde665c56514c1b701c0fe94fc943c7692be7f32.tar.zst
yuzu-cde665c56514c1b701c0fe94fc943c7692be7f32.zip
Diffstat (limited to 'src/core/crypto/key_manager.h')
-rw-r--r--src/core/crypto/key_manager.h41
1 files changed, 11 insertions, 30 deletions
diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h
index 0c62d4421..33b1ad383 100644
--- a/src/core/crypto/key_manager.h
+++ b/src/core/crypto/key_manager.h
@@ -7,10 +7,11 @@
#include <array>
#include <string>
#include <type_traits>
-#include <unordered_map>
#include <vector>
+#include <boost/container/flat_map.hpp>
#include <fmt/format.h>
#include "common/common_types.h"
+#include "core/loader/loader.h"
namespace Core::Crypto {
@@ -59,34 +60,14 @@ struct KeyIndex {
}
};
-// The following two (== and hash) are so KeyIndex can be a key in unordered_map
-
-template <typename KeyType>
-bool operator==(const KeyIndex<KeyType>& lhs, const KeyIndex<KeyType>& rhs) {
- return std::tie(lhs.type, lhs.field1, lhs.field2) == std::tie(rhs.type, rhs.field1, rhs.field2);
-}
-
+// boost flat_map requires operator< for O(log(n)) lookups.
template <typename KeyType>
-bool operator!=(const KeyIndex<KeyType>& lhs, const KeyIndex<KeyType>& rhs) {
- return !operator==(lhs, rhs);
+bool operator<(const KeyIndex<KeyType>& lhs, const KeyIndex<KeyType>& rhs) {
+ return (static_cast<size_t>(lhs.type) < static_cast<size_t>(rhs.type)) ||
+ (lhs.type == rhs.type && lhs.field1 < rhs.field1) ||
+ (lhs.type == rhs.type && lhs.field1 == rhs.field1 && lhs.field2 < rhs.field2);
}
-} // namespace Core::Crypto
-
-namespace std {
-template <typename KeyType>
-struct hash<Core::Crypto::KeyIndex<KeyType>> {
- size_t operator()(const Core::Crypto::KeyIndex<KeyType>& k) const {
- using std::hash;
-
- return ((hash<u64>()(static_cast<u64>(k.type)) ^ (hash<u64>()(k.field1) << 1)) >> 1) ^
- (hash<u64>()(k.field2) << 1);
- }
-};
-} // namespace std
-
-namespace Core::Crypto {
-
class KeyManager {
public:
KeyManager();
@@ -103,15 +84,15 @@ public:
static bool KeyFileExists(bool title);
private:
- std::unordered_map<KeyIndex<S128KeyType>, Key128> s128_keys;
- std::unordered_map<KeyIndex<S256KeyType>, Key256> s256_keys;
+ boost::container::flat_map<KeyIndex<S128KeyType>, Key128> s128_keys;
+ boost::container::flat_map<KeyIndex<S256KeyType>, Key256> s256_keys;
bool dev_mode;
void LoadFromFile(const std::string& filename, bool is_title_keys);
void AttemptLoadKeyFile(const std::string& dir1, const std::string& dir2,
const std::string& filename, bool title);
- static const std::unordered_map<std::string, KeyIndex<S128KeyType>> s128_file_id;
- static const std::unordered_map<std::string, KeyIndex<S256KeyType>> s256_file_id;
+ static const boost::container::flat_map<std::string, KeyIndex<S128KeyType>> s128_file_id;
+ static const boost::container::flat_map<std::string, KeyIndex<S256KeyType>> s256_file_id;
};
} // namespace Core::Crypto