From c4567f4c8c781d9910249fd59fe95bac0c039a02 Mon Sep 17 00:00:00 2001 From: Reece Date: Fri, 17 Sep 2021 20:26:05 +0100 Subject: [PATCH] [*] Amend %x -> {:X} formatting [+] Added source files ready for an LTC ECC implementation [+] Added linux specific HWInfo get threads backend [+] AU_TEMPLATE_ENABLE_WHEN [*] Amend IO::FS::WriteString compilation issue --- Include/Aurora/Crypto/ECC/ECC.hpp | 1 + Include/Aurora/Memory/MemoryView.hpp | 6 +++--- Include/AuroraMacros.hpp | 4 ++++ Include/AuroraUtils.hpp | 10 +++++----- Source/Crypto/ECC/ECC.cpp | 14 ++++++++++++++ Source/Crypto/ECC/ECC.hpp | 13 +++++++++++++ Source/Crypto/ECC/ECCCurves.cpp | 15 +++++++++++++++ Source/Crypto/ECC/ECCCurves.hpp | 13 +++++++++++++ Source/Crypto/ECC/ECCGeneric.cpp | 16 ++++++++++++++++ Source/Crypto/ECC/ECCGeneric.hpp | 13 +++++++++++++ Source/Crypto/ECC/ECCX25519.cpp | 15 +++++++++++++++ Source/Crypto/ECC/ECCX25519.hpp | 13 +++++++++++++ Source/Crypto/ECC/ECCx25519Utils.cpp | 15 +++++++++++++++ Source/Crypto/ECC/ECCx25519Utils.hpp | 13 +++++++++++++ Source/Debug/ExceptionWatcher.Win32.cpp | 2 +- Source/Debug/Panic.cpp | 4 ++-- Source/HWInfo/CpuInfo.cpp | 13 ++++++++++++- Source/IO/FS/FS.cpp | 4 ++-- Source/IO/FS/FileStream.NT.cpp | 4 ++-- 19 files changed, 172 insertions(+), 16 deletions(-) create mode 100644 Source/Crypto/ECC/ECC.cpp create mode 100644 Source/Crypto/ECC/ECC.hpp create mode 100644 Source/Crypto/ECC/ECCCurves.cpp create mode 100644 Source/Crypto/ECC/ECCCurves.hpp create mode 100644 Source/Crypto/ECC/ECCGeneric.cpp create mode 100644 Source/Crypto/ECC/ECCGeneric.hpp create mode 100644 Source/Crypto/ECC/ECCX25519.cpp create mode 100644 Source/Crypto/ECC/ECCX25519.hpp create mode 100644 Source/Crypto/ECC/ECCx25519Utils.cpp create mode 100644 Source/Crypto/ECC/ECCx25519Utils.hpp diff --git a/Include/Aurora/Crypto/ECC/ECC.hpp b/Include/Aurora/Crypto/ECC/ECC.hpp index b8ec6d6a..34b2a111 100644 --- a/Include/Aurora/Crypto/ECC/ECC.hpp +++ b/Include/Aurora/Crypto/ECC/ECC.hpp @@ -37,6 +37,7 @@ namespace Aurora::Crypto::ECC { eCurve256, eCurve384, + eCurve521, eCurveX25519, eCurveEd25519 }; diff --git a/Include/Aurora/Memory/MemoryView.hpp b/Include/Aurora/Memory/MemoryView.hpp index f232a1e9..cb5bfced 100644 --- a/Include/Aurora/Memory/MemoryView.hpp +++ b/Include/Aurora/Memory/MemoryView.hpp @@ -31,12 +31,12 @@ namespace Aurora::Memory this->ptr = nullptr; this->length = 0; } - - template::value>::type* = nullptr> + + template::value)> MemoryView(T &list) { this->ptr = list.data(); - this->length = list.size() * sizeof(T); + this->length = list.size() * sizeof(T::value_type); } MemoryView(const AuString &str) diff --git a/Include/AuroraMacros.hpp b/Include/AuroraMacros.hpp index 3d27fabb..01036c49 100644 --- a/Include/AuroraMacros.hpp +++ b/Include/AuroraMacros.hpp @@ -14,6 +14,10 @@ #define AU_SHARED_FROM_THIS (std::static_pointer_cast>(this->shared_from_this())) #define AU_WEAK_FROM_THIS (AuWPtr>(std::static_pointer_cast>(this->shared_from_this()))) +#define AU_BRACKET_SCOPE(...) __VA_ARGS__ + +#define AU_TEMPLATE_ENABLE_WHEN(...) typename std::enable_if<__VA_ARGS__>::type* = nullptr + /// @hideinitializer #define AU_STRINGIFY_(in) #in #define AU_STRINGIFY(in) AU_STRINGIFY_(in) diff --git a/Include/AuroraUtils.hpp b/Include/AuroraUtils.hpp index b2ee0a44..6d8e57ff 100644 --- a/Include/AuroraUtils.hpp +++ b/Include/AuroraUtils.hpp @@ -34,7 +34,7 @@ static inline auto AuMakePair(Args... args) return AURORA_RUNTIME_MAKE_PAIR(args...); } -#if defined(AURORA_IS_MODERNNT_DERIVED) && defined(_WINDOWS_) +#if defined(AURORA_IS_MODERNNT_DERIVED) && (defined(_WINDOWS_) || defined(_OTHER_MS_MAIN_HEADER_GUARDS_HERE)) static inline void AuWin32CloseHandle(HANDLE &handle) { HANDLE local; @@ -164,13 +164,13 @@ static inline AuOptional> AuOptionalSharedStaticCast(AuOptional(in.value()); } -static inline bool AuEndsWith(std::string const &value, std::string const &ending) +static inline bool AuEndsWith(AuString const &value, AuString const &ending) { if (ending.size() > value.size()) return false; return std::equal(ending.rbegin(), ending.rend(), value.rbegin()); } -static inline bool AuStartsWith(std::string const &value, std::string const &starting) +static inline bool AuStartsWith(AuString const &value, AuString const &starting) { return value.rfind(starting, 0) == 0; } @@ -448,7 +448,7 @@ static inline bool AuTryResize(T &list, AuUInt length) } } -static inline std::string AuReplaceAll(std::string &str, const std::string &from, const std::string &to) +static inline AuString AuReplaceAll(AuString &str, const AuString &from, const AuString &to) { size_t start_pos = 0; while ((start_pos = str.find(from, start_pos)) != std::string::npos) @@ -456,7 +456,7 @@ static inline std::string AuReplaceAll(std::string &str, const std::string &from str.replace(start_pos, from.length(), to); start_pos += to.length(); // Handles case where 'to' is a substring of 'from' } - return str; + return str; // :( } // i told myself not to copy this, required a split function twice, now here we are :D diff --git a/Source/Crypto/ECC/ECC.cpp b/Source/Crypto/ECC/ECC.cpp new file mode 100644 index 00000000..21bdd5ac --- /dev/null +++ b/Source/Crypto/ECC/ECC.cpp @@ -0,0 +1,14 @@ +/*** + Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: ECC.cpp + Date: 2021-9-17 + Author: Reece +***/ +#include +#include "ECC.hpp" + +namespace Aurora::Crypto::ECC +{ + +} \ No newline at end of file diff --git a/Source/Crypto/ECC/ECC.hpp b/Source/Crypto/ECC/ECC.hpp new file mode 100644 index 00000000..f233ade4 --- /dev/null +++ b/Source/Crypto/ECC/ECC.hpp @@ -0,0 +1,13 @@ +/*** + Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: ECC.hpp + Date: 2021-9-17 + Author: Reece +***/ +#pragma once + +namespace Aurora::Crypto::ECC +{ + +} \ No newline at end of file diff --git a/Source/Crypto/ECC/ECCCurves.cpp b/Source/Crypto/ECC/ECCCurves.cpp new file mode 100644 index 00000000..95fe8a25 --- /dev/null +++ b/Source/Crypto/ECC/ECCCurves.cpp @@ -0,0 +1,15 @@ +/*** + Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: ECCCurves.cpp + Date: 2021-9-17 + Author: Reece +***/ +#include +#include "ECC.hpp" +#include "ECCCurves.hpp" + +namespace Aurora::Crypto::ECC +{ + +} \ No newline at end of file diff --git a/Source/Crypto/ECC/ECCCurves.hpp b/Source/Crypto/ECC/ECCCurves.hpp new file mode 100644 index 00000000..d14ecc59 --- /dev/null +++ b/Source/Crypto/ECC/ECCCurves.hpp @@ -0,0 +1,13 @@ +/*** + Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: ECCCurves.hpp + Date: 2021-9-17 + Author: Reece +***/ +#pragma once + +namespace Aurora::Crypto::ECC +{ + +} \ No newline at end of file diff --git a/Source/Crypto/ECC/ECCGeneric.cpp b/Source/Crypto/ECC/ECCGeneric.cpp new file mode 100644 index 00000000..8c963268 --- /dev/null +++ b/Source/Crypto/ECC/ECCGeneric.cpp @@ -0,0 +1,16 @@ +/*** + Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: ECCGeneric.cpp + Date: 2021-9-17 + Author: Reece +***/ +#include +#include "ECC.hpp" +#include "ECCGeneric.hpp" +#include "ECCCurves.hpp" + +namespace Aurora::Crypto::ECC +{ + +} \ No newline at end of file diff --git a/Source/Crypto/ECC/ECCGeneric.hpp b/Source/Crypto/ECC/ECCGeneric.hpp new file mode 100644 index 00000000..69c5cb7b --- /dev/null +++ b/Source/Crypto/ECC/ECCGeneric.hpp @@ -0,0 +1,13 @@ +/*** + Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: ECCGeneric.hpp + Date: 2021-9-17 + Author: Reece +***/ +#pragma once + +namespace Aurora::Crypto::ECC +{ + +} \ No newline at end of file diff --git a/Source/Crypto/ECC/ECCX25519.cpp b/Source/Crypto/ECC/ECCX25519.cpp new file mode 100644 index 00000000..2d596a2f --- /dev/null +++ b/Source/Crypto/ECC/ECCX25519.cpp @@ -0,0 +1,15 @@ +/*** + Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: ECCX25519.cpp + Date: 2021-9-17 + Author: Reece +***/ +#include +#include "ECC.hpp" +#include "ECCx25519.hpp" + +namespace Aurora::Crypto::ECC +{ + +} \ No newline at end of file diff --git a/Source/Crypto/ECC/ECCX25519.hpp b/Source/Crypto/ECC/ECCX25519.hpp new file mode 100644 index 00000000..b01afbcc --- /dev/null +++ b/Source/Crypto/ECC/ECCX25519.hpp @@ -0,0 +1,13 @@ +/*** + Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: ECCX25519.hpp + Date: 2021-9-17 + Author: Reece +***/ +#pragma once + +namespace Aurora::Crypto::ECC +{ + +} \ No newline at end of file diff --git a/Source/Crypto/ECC/ECCx25519Utils.cpp b/Source/Crypto/ECC/ECCx25519Utils.cpp new file mode 100644 index 00000000..93192abb --- /dev/null +++ b/Source/Crypto/ECC/ECCx25519Utils.cpp @@ -0,0 +1,15 @@ +/*** + Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: ECCx25519Utils.cpp + Date: 2021-9-17 + Author: Reece +***/ +#include +#include "ECC.hpp" +#include "ECCx25519Utils.hpp" + +namespace Aurora::Crypto::ECC +{ + +} \ No newline at end of file diff --git a/Source/Crypto/ECC/ECCx25519Utils.hpp b/Source/Crypto/ECC/ECCx25519Utils.hpp new file mode 100644 index 00000000..c16e039a --- /dev/null +++ b/Source/Crypto/ECC/ECCx25519Utils.hpp @@ -0,0 +1,13 @@ +/*** + Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: ECCx25519Utils.hpp + Date: 2021-9-17 + Author: Reece +***/ +#pragma once + +namespace Aurora::Crypto::ECC +{ + +} \ No newline at end of file diff --git a/Source/Debug/ExceptionWatcher.Win32.cpp b/Source/Debug/ExceptionWatcher.Win32.cpp index aef5d941..367707c4 100644 --- a/Source/Debug/ExceptionWatcher.Win32.cpp +++ b/Source/Debug/ExceptionWatcher.Win32.cpp @@ -190,7 +190,7 @@ namespace Aurora::Debug #endif AddVectoredExceptionHandler(1, - [](_EXCEPTION_POINTERS *ExceptionInfo) -> LONG + [](_EXCEPTION_POINTERS *ExceptionInfo) -> LONG { Telemetry::NewBlockboxEntry entry; entry.type = Telemetry::ENewBlackBoxEntry::eWinCxxException; diff --git a/Source/Debug/Panic.cpp b/Source/Debug/Panic.cpp index 589275d4..281bc694 100644 --- a/Source/Debug/Panic.cpp +++ b/Source/Debug/Panic.cpp @@ -15,9 +15,9 @@ namespace Aurora::Debug { AUKN_SYM void DebugBreak() { - #if defined(DEBUG) || defined(INTERNAL) + #if defined(DEBUG) || defined(STAGING) #if defined(AURORA_PLATFORM_WIN32) - #if defined(INTERNAL) + #if defined(STAGING) if (IsDebuggerPresent()) #endif { diff --git a/Source/HWInfo/CpuInfo.cpp b/Source/HWInfo/CpuInfo.cpp index 32e5685d..b115f398 100644 --- a/Source/HWInfo/CpuInfo.cpp +++ b/Source/HWInfo/CpuInfo.cpp @@ -14,6 +14,11 @@ #include #endif +#if defined(AURORA_IS_POSIX_DERIVED) + #include + #include +#endif + namespace Aurora::HWInfo { static CpuInfo gCpuInfo; @@ -448,7 +453,13 @@ namespace Aurora::HWInfo gCpuInfo.socket = 1; gCpuInfo.cores = 1; - gCpuInfo.threads = opt.value_or(1) + gCpuInfo.threads = opt.value_or(1); + + #elif defined(AURORA_IS_LINUX_DERIVED) + + gCpuInfo.socket = 1; + gCpuInfo.cores = 1; + gCpuInfo.threads = get_nprocs(void); #elif defined(AURORA_IS_POSIX_DERIVED) diff --git a/Source/IO/FS/FS.cpp b/Source/IO/FS/FS.cpp index 82b4461a..e75c1039 100644 --- a/Source/IO/FS/FS.cpp +++ b/Source/IO/FS/FS.cpp @@ -230,8 +230,8 @@ namespace Aurora::IO::FS } bool ok {}; - ok = stream->Write(const Memory::MemoryViewStreamRead &{bom}); - ok &= stream->Write(const Memory::MemoryViewStreamRead &{str}); + ok = stream->Write(Memory::MemoryViewStreamRead{bom}); + ok &= stream->Write(Memory::MemoryViewStreamRead{str}); stream->Flush(); return ok; diff --git a/Source/IO/FS/FileStream.NT.cpp b/Source/IO/FS/FileStream.NT.cpp index 70d0f811..22f2bcbe 100644 --- a/Source/IO/FS/FileStream.NT.cpp +++ b/Source/IO/FS/FileStream.NT.cpp @@ -107,7 +107,7 @@ namespace Aurora::IO::FS if (!::ReadFile(handle_, &reinterpret_cast(parameters.ptr)[offset], blockSize, &read, NULL)) { - LogWarn("ReadFile IO Error: 0x%x, {}", GetLastError(), path_); + LogWarn("ReadFile IO Error: 0x{:x}, {}", GetLastError(), path_); SysPushErrorIO(); return false; } @@ -148,7 +148,7 @@ namespace Aurora::IO::FS if (!::WriteFile(handle_, &reinterpret_cast(parameters.ptr)[offset], blockSize, &written, NULL)) { - LogWarn("WriteFileEx IO Error: 0x%x, {}", GetLastError(), path_); + LogWarn("WriteFileEx IO Error: 0x{:x}, {}", GetLastError(), path_); SysPushErrorIO(); return false; }