summaryrefslogtreecommitdiff
path: root/src/core/crypto/key_manager.cpp
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-08-09 20:45:04 -0400
committerGravatar Zach Hilman2018-08-11 22:50:08 -0400
commita27ec24c0f83d346218e0301f80398209d30ffcb (patch)
treef34b27d354247472771d80681255aefc6ac63e17 /src/core/crypto/key_manager.cpp
parentfile_util: Add getter for NAND registration directory (diff)
downloadyuzu-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.cpp35
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
16namespace Core::Crypto { 18namespace Core::Crypto {
17 19
18static 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
28template <size_t Size>
29static 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
39std::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
45std::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
51KeyManager::KeyManager() { 20KeyManager::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();