summaryrefslogtreecommitdiffstats
path: root/src/core/crypto
diff options
context:
space:
mode:
authorZach Hilman <zachhilman@gmail.com>2018-08-19 03:16:20 +0200
committerZach Hilman <zachhilman@gmail.com>2018-08-23 17:53:30 +0200
commita7e8d10969f280cd5a869b3525c3339357a958a6 (patch)
tree59e34b73d627cffab8cdbdf7e52ffdd6168c54fc /src/core/crypto
parentcrypto: Eliminate magic constants (diff)
downloadyuzu-a7e8d10969f280cd5a869b3525c3339357a958a6.tar
yuzu-a7e8d10969f280cd5a869b3525c3339357a958a6.tar.gz
yuzu-a7e8d10969f280cd5a869b3525c3339357a958a6.tar.bz2
yuzu-a7e8d10969f280cd5a869b3525c3339357a958a6.tar.lz
yuzu-a7e8d10969f280cd5a869b3525c3339357a958a6.tar.xz
yuzu-a7e8d10969f280cd5a869b3525c3339357a958a6.tar.zst
yuzu-a7e8d10969f280cd5a869b3525c3339357a958a6.zip
Diffstat (limited to 'src/core/crypto')
-rw-r--r--src/core/crypto/key_manager.cpp22
-rw-r--r--src/core/crypto/key_manager.h6
2 files changed, 13 insertions, 15 deletions
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp
index acf635a65..1cb3fce00 100644
--- a/src/core/crypto/key_manager.cpp
+++ b/src/core/crypto/key_manager.cpp
@@ -199,7 +199,7 @@ Key256 KeyManager::GetKey(S256KeyType id, u64 field1, u64 field2) const {
template <size_t Size>
void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname,
- std::array<u8, Size> key) {
+ const std::array<u8, Size>& key) {
const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir);
std::string filename = "title.keys_autogenerated";
if (!title_key)
@@ -209,11 +209,10 @@ void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname,
if (!file.is_open())
return;
if (add_info_text) {
- file << "# This file is autogenerated by Yuzu" << std::endl
- << "# It serves to store keys that were automatically generated from the normal keys"
- << std::endl
- << "# If you are experiencing issues involving keys, it may help to delete this file"
- << std::endl;
+ file
+ << "# This file is autogenerated by Yuzu\n"
+ << "# It serves to store keys that were automatically generated from the normal keys\n"
+ << "# If you are experiencing issues involving keys, it may help to delete this file\n";
}
file << std::endl
@@ -263,11 +262,12 @@ bool KeyManager::KeyFileExists(bool title) {
}
void KeyManager::DeriveSDSeedLazy() {
- if (!HasKey(S128KeyType::SDSeed)) {
- const auto res = DeriveSDSeed();
- if (res != boost::none)
- SetKey(S128KeyType::SDSeed, res.get());
- }
+ if (HasKey(S128KeyType::SDSeed))
+ return;
+
+ const auto res = DeriveSDSeed();
+ if (res != boost::none)
+ SetKey(S128KeyType::SDSeed, res.get());
}
const boost::container::flat_map<std::string, KeyIndex<S128KeyType>> KeyManager::s128_file_id = {
diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h
index 78d0b64e0..7a8728f76 100644
--- a/src/core/crypto/key_manager.h
+++ b/src/core/crypto/key_manager.h
@@ -74,9 +74,7 @@ struct KeyIndex {
// boost flat_map requires operator< for O(log(n)) lookups.
template <typename KeyType>
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);
+ return std::tie(lhs.type, lhs.field1, lhs.field2) < std::tie(rhs.type, rhs.field1, rhs.field2);
}
class KeyManager {
@@ -107,7 +105,7 @@ private:
void AttemptLoadKeyFile(const std::string& dir1, const std::string& dir2,
const std::string& filename, bool title);
template <size_t Size>
- void WriteKeyToFile(bool title_key, std::string_view keyname, std::array<u8, Size> key);
+ void WriteKeyToFile(bool title_key, std::string_view keyname, const std::array<u8, Size>& key);
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;