diff options
| author | 2018-08-09 20:45:04 -0400 | |
|---|---|---|
| committer | 2018-08-11 22:50:08 -0400 | |
| commit | a27ec24c0f83d346218e0301f80398209d30ffcb (patch) | |
| tree | f34b27d354247472771d80681255aefc6ac63e17 /src/core/crypto/key_manager.cpp | |
| parent | file_util: Add getter for NAND registration directory (diff) | |
| download | yuzu-a27ec24c0f83d346218e0301f80398209d30ffcb.tar.gz yuzu-a27ec24c0f83d346218e0301f80398209d30ffcb.tar.xz yuzu-a27ec24c0f83d346218e0301f80398209d30ffcb.zip | |
crypto: Remove hex utilities from key_manager
Move to hex_util.h in common
Diffstat (limited to 'src/core/crypto/key_manager.cpp')
| -rw-r--r-- | src/core/crypto/key_manager.cpp | 35 |
1 files changed, 2 insertions, 33 deletions
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index fc45e7ab5..94d92579f 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp | |||
| @@ -10,44 +10,13 @@ | |||
| 10 | #include <string_view> | 10 | #include <string_view> |
| 11 | #include "common/common_paths.h" | 11 | #include "common/common_paths.h" |
| 12 | #include "common/file_util.h" | 12 | #include "common/file_util.h" |
| 13 | #include "common/hex_util.h" | ||
| 14 | #include "common/logging/log.h" | ||
| 13 | #include "core/crypto/key_manager.h" | 15 | #include "core/crypto/key_manager.h" |
| 14 | #include "core/settings.h" | 16 | #include "core/settings.h" |
| 15 | 17 | ||
| 16 | namespace Core::Crypto { | 18 | namespace Core::Crypto { |
| 17 | 19 | ||
| 18 | static u8 ToHexNibble(char c1) { | ||
| 19 | if (c1 >= 65 && c1 <= 70) | ||
| 20 | return c1 - 55; | ||
| 21 | if (c1 >= 97 && c1 <= 102) | ||
| 22 | return c1 - 87; | ||
| 23 | if (c1 >= 48 && c1 <= 57) | ||
| 24 | return c1 - 48; | ||
| 25 | throw std::logic_error("Invalid hex digit"); | ||
| 26 | } | ||
| 27 | |||
| 28 | template <size_t Size> | ||
| 29 | static std::array<u8, Size> HexStringToArray(std::string_view str) { | ||
| 30 | std::array<u8, Size> out{}; | ||
| 31 | for (size_t i = 0; i < 2 * Size; i += 2) { | ||
| 32 | auto d1 = str[i]; | ||
| 33 | auto d2 = str[i + 1]; | ||
| 34 | out[i / 2] = (ToHexNibble(d1) << 4) | ToHexNibble(d2); | ||
| 35 | } | ||
| 36 | return out; | ||
| 37 | } | ||
| 38 | |||
| 39 | std::array<u8, 16> operator""_array16(const char* str, size_t len) { | ||
| 40 | if (len != 32) | ||
| 41 | throw std::logic_error("Not of correct size."); | ||
| 42 | return HexStringToArray<16>(str); | ||
| 43 | } | ||
| 44 | |||
| 45 | std::array<u8, 32> operator""_array32(const char* str, size_t len) { | ||
| 46 | if (len != 64) | ||
| 47 | throw std::logic_error("Not of correct size."); | ||
| 48 | return HexStringToArray<32>(str); | ||
| 49 | } | ||
| 50 | |||
| 51 | KeyManager::KeyManager() { | 20 | KeyManager::KeyManager() { |
| 52 | // Initialize keys | 21 | // Initialize keys |
| 53 | const std::string hactool_keys_dir = FileUtil::GetHactoolConfigurationPath(); | 22 | const std::string hactool_keys_dir = FileUtil::GetHactoolConfigurationPath(); |