Initial Commit

master
Reece Wilson 2021-06-27 22:25:29 +01:00
parent 9b575eb021
commit eb4a495199
333 changed files with 19626 additions and 0 deletions

18
.gitignore vendored 100644
View File

@ -0,0 +1,18 @@
Build_CompilerWorkingDirectory/*
Build_Developers/*
Build_Ship/*
Build_Internal/*
*.vcxproj
*.vcxproj.filters
*.vcxproj.user
*.licenseheader
*.dll
*.exe
*.obj
*.so
*.dynlib
*.lib
*.d
*.o
*.out
.vs

20
Aurora.json 100644
View File

@ -0,0 +1,20 @@
{
"type": "aurora",
"name": "AuroraRuntime",
"dllexport": ["AURORA_ENGINE_KERNEL_EXPORT"],
"dllimport": [],
"impDefines": ["AURORA_ENGINE_KERNEL"],
"staticImpDefines": "AURORA_ENGINE_KERNEL_STATIC",
"defines": [],
"soft-depends": ["wxwidgets"],
"depends": ["glm", "asio", "mimalloc", "uuid", "fmt", "json", "bzip2", "ltc", "o1heap", "zstd", "zlib", "lz4", "mbedtls"],
"features": ["remove-platform-code", "guess-platform-code"],
"actions": [
{
"if": "win32",
"then": {
"links": "Bcrypt.lib"
}
}
]
}

View File

@ -0,0 +1,319 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Async.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::Async
{
class IWorkItem;
class IAsyncApp;
using AVoid = AuUInt8;
AUKN_SYM IAsyncApp *GetAsyncApp();
using ThreadGroup_t = AuUInt8;
using ThreadId_t = AuUInt16;
using WorkerId_t = std::pair<ThreadGroup_t, ThreadId_t>;
using DispatchTarget_t = std::pair<ThreadGroup_t, std::optional<ThreadId_t>>;
struct IWorkItemHandler
{
enum class EProcessNext
{
eInvalid = -1,
eFinished = 0,
eRerun,
eSchedule,
eFailed
};
struct ProcessInfo
{
ProcessInfo(bool finished) : type(finished ? EProcessNext::eFinished : EProcessNext::eFailed) {}
ProcessInfo(EProcessNext type) : type(type) {}
ProcessInfo(const AuList<AuSPtr<IWorkItem>> &blockedBy) : type(EProcessNext::eSchedule), waitFor(blockedBy) {}
// ...
EProcessNext type;
AuList<AuSPtr<IWorkItem>> waitFor;
AuUInt32 reschedMs;
//AuUInt64 reschedNs;
};
virtual void DispatchFrame(ProcessInfo &info) = 0;
virtual void Shutdown() = 0;
};
template<typename Info_t = AVoid, typename Result_t = AVoid>
struct FJob
{
std::function<void(const Info_t &, const Result_t &)> onSuccess = 0;
std::function<void(const Info_t &, bool)> onFailure = 0;
};
template<typename Info_t = AVoid, typename Result_t = AVoid>
struct CJob
{
void(* onSuccess)(const Info_t &, const Result_t &); //
void(* onFailure)(const Info_t &, bool taskNeverDispatched); // called from caller thread if taskNeverDispatched
};
template<typename Info_t = AVoid, typename Result_t = AVoid>
struct FTask
{
std::function<std::optional<Result_t>(const Info_t &)> onFrame = 0;
};
template<typename Info_t = AVoid, typename Result_t = AVoid>
struct CTask
{
std::optional<Result_t>(* onFrame)(const Info_t &);
};
class IWorkItem
{
public:
virtual void WaitFor(const AuSPtr<IWorkItem> &workItem) = 0;
virtual void WaitFor(const AuList<AuSPtr<IWorkItem>> &workItem) = 0;
virtual void SetSchedTime(AuUInt32 ms) = 0;
virtual void Dispatch() = 0;
virtual bool BlockUntilComplete() = 0;
virtual bool HasFinished() = 0;
virtual bool HasFailed() = 0;
};
AUKN_SYM AuSPtr<IWorkItem> NewWorkItem(const DispatchTarget_t &worker, const AuSPtr<IWorkItemHandler> &task, bool supportsBlocking = false);
struct BasicWorkStdFunc : IWorkItemHandler
{
std::function<void()> callback;
std::function<void()> error;
BasicWorkStdFunc(std::function<void()> &&callback, std::function<void()> &&error) : callback(std::move(callback)), error(std::move(error))
{}
BasicWorkStdFunc(std::function<void()> &&callback) : callback(std::move(callback))
{}
BasicWorkStdFunc(const std::function<void()> &callback) : callback(callback)
{}
BasicWorkStdFunc(const std::function<void()> &callback, const std::function<void()> &error) : callback(callback), error(error)
{}
private:
void DispatchFrame(ProcessInfo &info) override
{
try
{
callback();
}
catch (...)
{
Debug::PrintError();
}
}
void Shutdown() override
{
try
{
error();
}
catch (...)
{
Debug::PrintError();
}
}
};
template<typename Info_t, typename Result_t, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>>
struct BasicWorkCallback : IWorkItemHandler, std::enable_shared_from_this<IWorkItemHandler>
{
BasicWorkCallback()
{
caller = GetAsyncApp()->GetCurrentThread();
}
Task_t task;
Job_t callback;
Info_t input;
private:
static constexpr bool IsCallbackPtr = std::is_pointer_v<Job_t> || is_base_of_template<AuSPtr, Job_t>;
static constexpr bool IsTaskPtr = std::is_pointer_v<Task_t> || is_base_of_template<AuSPtr, Task_t>;
WorkerId_t caller;
void DispatchFrame(ProcessInfo &info) override
{
std::optional<Result_t> ret;
if constexpr (IsTaskPtr)
{
ret = task->onFrame(input);
}
else
{
ret = task.onFrame(input);
}
auto pin = this->shared_from_this();
std::function<void()> func = [ret, &callback, &input, pin]()
{
try
{
if (ret.has_value())
{
if constexpr (IsCallbackPtr)
{
callback->onSuccess(input, *ret);
}
else
{
callback.onSuccess(input, *ret);
}
}
else
{
if constexpr (IsCallbackPtr)
{
callback->onFailure(input, false);
}
else
{
callback.onFailure(input, false);
}
}
}
catch (...)
{
Debug::PrintError();
}
};
try
{
if (caller == GetAsyncApp()->GetCurrentThread())
{
func();
}
else
{
std::function<void()> err = [&callback, &input, pin]()
{
// TODO: we shold probably pass: is caller thread: false, has finished: true
if constexpr (IsCallbackPtr)
{
callback->onFailure(input, false);
}
else
{
callback.onFailure(input, false);
}
};
// TODO: this is somewhat evil. double alloc when we could reuse this
WorkItemShared(caller, std::make_shared<BasicWorkStdFunc>(func, err))->Dispatch();
}
}
catch (...)
{
Debug::PrintError();
Shutdown();
}
}
void Shutdown() override
{
try
{
if constexpr (IsCallbackPtr)
{
callback->onFailure(true);
}
else
{
callback.onFailure(true);
}
}
catch (...)
{
Debug::PrintError();
}
}
};
template<typename Frame_t = std::function<void()>, typename Cleanup_t = std::function<void()>>
struct WorkItemCallabale : IWorkItemHandler
{
Frame_t frame;
Cleanup_t cleanup;
private:
void DispatchFrame(ProcessInfo &info) override
{
frame();
info.type = IWorkItemHandler::EProcessNext::eFinished;
}
void Shutdown() override
{
cleanup();
}
};
template<typename B, typename... Args>
static void TranslateAsyncFunctionToDispatcher()
{
}
class IAsyncApp
{
public:
// Main thread logic
virtual void Main() = 0;
virtual void Shutdown() = 0;
virtual bool Exiting() = 0;
// Spawning
virtual bool Spawn(WorkerId_t) = 0;
virtual Threading::Threads::ThreadShared_t ResolveHandle(WorkerId_t) = 0;
virtual AuBST<ThreadGroup_t, AuList<AuUInt8>> GetThreads() = 0;
virtual WorkerId_t GetCurrentThread() = 0;
// Synchronization
virtual bool Sync(ThreadGroup_t group, bool requireSignal = false, AuUInt32 timeout = 0) = 0;
virtual void Signal(ThreadGroup_t group) = 0;
virtual bool WaitFor(DispatchTarget_t unlocker, Threading::IWaitable *primitive, int ms) = 0; // when unlocker = this, pump event loop
virtual bool SyncTimeout(ThreadGroup_t group, AuUInt32 ms) = 0;
virtual void SyncAllSafe() = 0;
// Features
virtual void AddFeature(WorkerId_t id, AuSPtr<Threading::Threads::IThreadFeature> feature, bool async = false) = 0;
// Debug
virtual void AssertInThreadGroup(ThreadGroup_t thread) = 0;
virtual void AssertWorker(WorkerId_t id) = 0;
};
}

View File

@ -0,0 +1,31 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: BasicCompression.hpp
Date: 2021-6-9
Author: Reece
***/
#pragma once
namespace Aurora::Compression
{
/**
Compresses an in memory blob with zstandard
*/
AUKN_SYM bool Compress(const void *buffer, AuUInt32 length, AuList<AuUInt8> &out, int compressionLevel = 3);
/**
Compresses an in memory blob with zstandard
*/
AUKN_SYM bool Compress(const AuList<AuUInt8> &in, AuList<AuUInt8> &out, int compressionLevel = 3);
/**
Decompresses an in memory blob with zstandard
*/
AUKN_SYM bool Decompress(const void *buffer, AuUInt32 length, AuList<AuUInt8> &out);
/**
Decompresses an in memory blob with zstandard
*/
AUKN_SYM bool Decompress(const AuList<AuUInt8> &in, AuList<AuUInt8> &out);
}

View File

@ -0,0 +1,36 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Compression.hpp
Date: 2021-6-9
Author: Reece
***/
#pragma once
/*
Ballpark figures of real world performance:
https://www.gaia-gis.it/fossil/librasterlite2/wiki?name=benchmarks+(2019+update)
RELATIVE
Useful for compression ratio variation and realistic igors lzma decompression perf values
9th gen intel benchmark figures in MB/s:
https://github.com/lz4/lz4
Similar to above, i7 bin:
https://facebook.github.io/zstd/
LZMA -> Large packages. Sony conures. (Reliable 2.3 - 2.5. Scales all the way up to 20+. Extremely slow but scalable)
LZ4 -> Network compression and other large data streams (~4.5GB/s, 2.884 compression ratio)
ZSTD -> Standard use (~1.5GB/s to 2.5GB/s, respective compression ratios 2.4 and 2.1. Can be pushed to ~10 at around 750MB/s. Great general use. )
ZIP -> Zlib has a disgusting decompression upper limit of around 450MB/s for 2.7
*/
#include "BasicCompression.hpp"
#include "ECompresionType.hpp"
#include "CompressionInfo.hpp"
#include "StreamPipeProcessor.hpp"
#include "ICompressionStream.hpp"
#include "StreamProcessor.hpp"

View File

@ -0,0 +1,34 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: CompressionInfo.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::Compression
{
struct CompressionInfo
{
ECompresionType type;
/// ZSTD: -5 <= level <= 22
/// recommended: ZSTD_CLEVEL_DEFAULT
/// LZMA: 0 <= level <= 9
/// LZ4 : N/A
/// ZLIB: 0 <= x >= 9
/// recommended: 6
/// BZIP: 0 <= x >= 9
AuInt8 compressionLevel{};
/// LZMA: 5 <= fb <= 273, default = 32
AuUInt32 fbWordSize{};
/// LZMA only
/// (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
/// (1 << 12) <= dictSize <= (3 << 29) for 64-bit version
/// default = (1 << 24)
AuUInt32 dictSize{};
};
}

View File

@ -0,0 +1,20 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ECompresionType.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::Compression
{
enum class ECompresionType
{
eLZMA,
eZSTD,
eDeflate,
eLZ4,
eBZIP2
};
}

View File

@ -0,0 +1,24 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ICompressionStream.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::Compression
{
class ICompressionStream
{
public:
virtual bool Ingest(AuUInt32 minimum, AuUInt32 request) = 0;
virtual bool Read(void * /*opt*/, AuUInt32 &len, bool ingestUntilEOS = true) = 0;
};
class ICompressionStreamEx : public ICompressionStream
{
public:
virtual void Flush() = 0;
};
}

View File

@ -0,0 +1,32 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: StreamPipeProcessor.hpp
Date: 2021-6-9
Author: Reece
***/
#pragma once
namespace Aurora::Compression
{
struct CompressionPipe
{
/// algorithm
ECompresionType type;
/// LZMA decompression + compression, and ZSTD compression only
AuUInt32 threads;
/// consume from stream callback
std::function<AuUInt(void *, AuUInt)> inPipe;
/// write to stream callback
std::function<void(const void *, AuUInt)> writePipe;
/// preemption and reporting
std::function<bool(AuUInt, AuUInt)> reportProgress;
};
AUKN_SYM bool Decompress(const CompressionPipe &stream);
AUKN_SYM bool Compress(const CompressionPipe &stream, const CompressionInfo &info);
}

View File

@ -0,0 +1,16 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: StreamProcessor.hpp
Date: 2021-6-9
Author: Reece
***/
#pragma once
#include <Aurora/IO/IO.hpp>
namespace Aurora::Compression
{
AUKN_SHARED_API(Decompressor, ICompressionStream, Aurora::IO::IStreamReader *reader, ECompresionType type);
AUKN_SHARED_API(Compressor, ICompressionStreamEx, Aurora::IO::IStreamReader *reader, const CompressionInfo &info);
}

View File

@ -0,0 +1,18 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Commands.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
#include <Aurora/Parse/Parse.hpp>
namespace Aurora::Console::Commands
{
using CommandCallback_cb = std::function<void(const Parse::ParsedObject &)>;
AUKN_SYM void AddCommand(const AuString &tag, const Parse::ParseObject &commandStructure, const CommandCallback_cb &callback);
AUKN_SYM bool DispatchCommand(const AuString &string);
}

View File

@ -0,0 +1,20 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Console.hpp
Date: 2021-6-9
Author: Reece
***/
#pragma once
#include "EAnsiColor.hpp"
#include "ConsoleMessage.hpp"
namespace Aurora::Console
{
AUKN_SYM void WriteLine(const ConsoleMessage &msg);
}
#include "Commands/Commands.hpp"
#include "Hooks/Hooks.hpp"
#include "Logging/Logging.hpp"

View File

@ -0,0 +1,55 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ConsoleMessage.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
//#include <Aurora/Time/Time.hpp>
namespace Aurora::Threading::Threads
{
AUKN_SYM AuThreadId_t GetThreadId();
}
namespace Aurora::Time
{
AUKN_SYM AuUInt64 CurrentClockMS();
}
namespace Aurora::Console
{
class AUKN_SYM ConsoleMessage
{
public:
EAnsiColor color;
AuString prefix;
AuString line;
AuUInt64 time;
AuThreadId_t tid;
ConsoleMessage()
{
color = EAnsiColor::eReset;
}
ConsoleMessage(const AuString &prefix, const AuString &line) : prefix(prefix), line(line), color(EAnsiColor::eReset)
{
time = Time::CurrentClockMS();
tid = Threading::Threads::GetThreadId();
}
ConsoleMessage(const EAnsiColor color, const AuString &prefix, const AuString &line) : prefix(prefix), line(line), color(color)
{
time = Time::CurrentClockMS();
tid = Threading::Threads::GetThreadId();
}
AuString StringifyTime(bool simple = false) const;
AuString GetWrappedTag() const;
AuString ToConsole() const;
AuString ToSimplified() const;
};
}

View File

@ -0,0 +1,29 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: EAnsiColor.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::Console
{
enum class EAnsiColor
{
eRed,
eBoldRed,
eGreen,
eBoldGreen,
eYellow,
eBoldYellow,
eBlue,
eBoldBlue,
eMagenta,
eBoldMagenta,
eCyan,
eBoldCyan,
eReset,
eCount
};
}

View File

@ -0,0 +1,15 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Hooks.hpp
Date: 2021-6-9
Author: Reece
***/
#pragma once
namespace Aurora::Console::Hooks
{
using LineHook_cb = std::function<void(const ConsoleMessage &string)>;
AUKN_SYM void AddHook(LineHook_cb hook);
}

View File

@ -0,0 +1,47 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Logging.hpp
Date: 2021-6-9
Author: Reece
***/
#pragma once
namespace Aurora::Console::Logging
{
template<typename ... T>
static inline void WriteLinef(const AuString &tag, const AuString &msg, T... args)
{
Aurora::Console::WriteLine(ConsoleMessage(EAnsiColor::eReset, tag, fmt::format(msg, args...)));
}
template<typename ... T>
static inline void WriteLinef(EAnsiColor color, const AuString &tag, const AuString &msg, T... args)
{
Aurora::Console::WriteLine(ConsoleMessage(color, tag, fmt::format(msg, args...)));
}
template<typename ... T>
static inline void LogInfo(const AuString &line, T... args)
{
Aurora::Console::Logging::WriteLinef(EAnsiColor::eGreen, "Info", line, args...);
}
template<typename ... T>
static inline void LogDbg(const AuString &line, T... args)
{
Aurora::Console::Logging::WriteLinef(EAnsiColor::eYellow, "Debug", line, args...);
}
template<typename ... T>
static inline void LogWarn(const AuString &line, T... args)
{
Aurora::Console::Logging::WriteLinef(EAnsiColor::eRed, "Warn", line, args...);
}
template<typename ... T>
static inline void LogGame(const AuString &line, T... args)
{
Aurora::Console::Logging::WriteLinef(EAnsiColor::eBlue, "Game", line, args...);
}
}

View File

@ -0,0 +1,35 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AES.hpp
Date: 2021-6-11
Author: Reece
***/
#pragma once
namespace Aurora::Crypto::AES
{
AUKN_SYM AuUInt GetSafeCipherPadding(const void* plainText,
AuUInt plainTextLength);
// Remember: AES works in chunks of 128 bits
// IVS are 16 bytes long
// Chunks are 16 bytes long
// Keys are 16, 24, or 32 bytes long
// Initialization vectors must never be constant
// Initialization vectors should be determined by a handshaake
// It is not the end of the world if an IV is made public by design
// Keys must be random
// Initialization vectors could be derived from SHA1, Tiger, or SHA2 digests
AUKN_SYM bool Encrypt(const void* plainText, AuUInt plainTextLength,
const void* iv, void* outIv, AuUInt ivLength,
const void* key, AuUInt keyLength,
AuList<AuUInt8>& out,
bool safe);
AUKN_SYM bool Decrypt(const void* cipherText, AuUInt cipherTextLength,
const void* iv, void* outIv, AuUInt ivLength,
const void* key, AuUInt keyLength,
AuList<AuUInt8>& plainText,
bool safe);
}

View File

@ -0,0 +1,28 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: CA.hpp
Date: 2021-6-11
Author: Reece
***/
#pragma once
namespace Aurora::Crypto::CA
{
class ICertificateStore
{
public:
virtual void AddSignature(const PublicRSAKey& CA, const AuList<AuUInt8>& sig,
EHashType method, EPaddingType type) = 0;
virtual void AddPublicCert(const X509::Certificate& cert) = 0;
/// For future support of http gets of the CA list
virtual bool& AllowHTTPTree() = 0;
virtual bool CheckKey(const PublicKey& pub) = 0;
virtual bool CheckCert(const X509::Certificate& cert) = 0;
};
AUKN_SHARED_API(NewCA, ICertificateStore);
}

View File

@ -0,0 +1,40 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Crypto.hpp
Date: 2021-6-11
Author: Reece
***/
#pragma once
namespace Aurora::Crypto
{
using DerBuffer = AuList<AuUInt8>;
using PrivateRSAKey = DerBuffer; // a/k/a "RSA", OpenSSL, private key in mbedtls, PKCS1
using PublicRSAKey = DerBuffer;
using PrivateECCKey = DerBuffer;
using PublicECCKey = DerBuffer;
using PrivateKey = DerBuffer; // PKCS8
using PublicKey = DerBuffer;
namespace X509
{
using Certificate = AuList<AuUInt8>;
}
struct RSAPair
{
X509::Certificate pub;
PrivateRSAKey priv;
};
}
#include "EHashType.hpp"
#include "EPaddingType.hpp"
#include "AES/AES.hpp"
#include "X509/X509.hpp"
#include "CA/CA.hpp"
#include "ECC25519/ECC25519.hpp"
#include "ECCNIST/ECCNIST.hpp"
#include "PEM/PEM.hpp"
#include "RSA/RSA.hpp"

View File

@ -0,0 +1,13 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ECC25519.hpp
Date: 2021-6-11
Author: Reece
***/
#pragma once
namespace Aurora::Crypto::ECC25519
{
}

View File

@ -0,0 +1,13 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ECCNIST.hpp
Date: 2021-6-11
Author: Reece
***/
#pragma once
namespace Aurora::Crypto::ECCNIST
{
}

View File

@ -0,0 +1,19 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: EHashType.hpp
Date: 2021-6-11
Author: Reece
***/
#pragma once
namespace Aurora::Crypto
{
enum class EHashType
{
eSHA1_20_160,
eTiger_24_192,
eSHA2_32_256,
eSHA2_64_512
};
}

View File

@ -0,0 +1,24 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: EPaddingType.hpp
Date: 2021-6-11
Author: Reece
***/
#pragma once
namespace Aurora::Crypto
{
enum class EPaddingType
{
ePaddingNone,
// For use with encryption
ePKCS_OAEP,
// For use with signing and encryption
ePKCS_1_5,
// For use with signing
ePKCS_1_PSS,
// For use with signing
ePKCS_1_5_NA1
};
}

View File

@ -0,0 +1,23 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: PEM.hpp
Date: 2021-6-11
Author: Reece
***/
#pragma once
namespace Aurora::Crypto::PEM
{
AUKN_SYM AuString ToString(const Aurora::Crypto::X509::Certificate &in);
AUKN_SYM AuString PublicToString(const PublicKey &in);
AUKN_SYM AuString PrivateToString(const PrivateKey &in);
AUKN_SYM AuString PublicRSAToString(const PrivateRSAKey &in);
AUKN_SYM AuString PrivateRSAToString(const PublicRSAKey &in);
AUKN_SYM bool FromString(const AuString &in, Aurora::Crypto::X509::Certificate &out);
AUKN_SYM bool PublicFromString(const AuString &in, PublicKey &out);
AUKN_SYM bool PrivateFromString(const AuString &in, PrivateKey &out);
AUKN_SYM bool PublicRSAFromString(const AuString &in, PrivateRSAKey &out);
AUKN_SYM bool PrivateRSAFromString(const AuString &in, PublicRSAKey &out);
}

View File

@ -0,0 +1,13 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: RSA.hpp
Date: 2021-6-11
Author: Reece
***/
#pragma once
namespace Aurora::Crypto::RSA
{
}

View File

@ -0,0 +1,20 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ESignatureAlgorithm.hpp
Date: 2021-6-11
Author: Reece
***/
#pragma once
namespace Aurora::Crypto::X509
{
enum class ESignatureAlgorithm
{
eInvalidAlgorithm,
eMD5WithRSA,
eSHA1WithRSA,
eSHA256WithRSA,
eECDSAWithRSA
};
}

View File

@ -0,0 +1,62 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: X509.hpp
Date: 2021-6-11
Author: Reece
***/
#pragma once
#include "ESignatureAlgorithm.hpp"
namespace Aurora::Crypto::X509
{
// yes, these structure completely disregards the principles of the x509 structure and the rationales behind certain extensions
// however, this is not intended to be a grandiose TLS stack
//
// PKSC#1 and #8, and x509 extensions (ie: rfc5280 key-ids, v3 exts) are not supported in our deps
// we had to reimplement them ourselves >:(
// lets worry about the more important issues
struct CertName
{
AuString commonName; // Tbs
AuString department; // Tbs
AuString organization; // Tbs
AuString state; // Tbs
AuString countryCode; // Tbs
AuString name; // Tbs
AuString email; // Tbs
AuString title; // Tbs
};
struct DecodedCertificate
{
// TODO:
//SignatureAlgorithm signature;
struct Issuer : CertName
{
AuList<AuUInt8> id;
} issuer;
struct Subject : CertName
{
AuList<AuUInt8> id;
} subject;
struct Vaildity // Tbs
{ // Tbs
AuUInt issued; // Tbs
AuUInt expire; // Tbs
} validity; // Tbs
AuList<AuUInt8> serialNumber; // Tbs
AuList<AuUInt8> algorithmOid; // Tbs
// TODO: usage // extension
AuList<AuString> AIAs;
// TODO: AuString CRL;
// TODO: AuList<String> subjectNames;
};
AUKN_SYM bool Decode(const Certificate &der, DecodedCertificate &out);
AUKN_SYM bool Validate(const Certificate &der, const Certificate &parentDer);
}

View File

@ -0,0 +1,137 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Data.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::Data
{
enum class DataType
{
kTypeUInt, // Human friendly types
kTypeSInt,
kTypeNumber,
kTypeString,
kTypeBoolean,
kTypeUUID,
kTypeVec3,
kTypeVec4,
kTypeGenericMax, // Binary serialization
kTypeStructFloat,
kTypeStructUInt8,
kTypeStructInt8,
kTypeStructUInt16,
kTypeStructInt16,
kTypeStructUInt32,
kTypeStructInt32,
kTypeSpecialComponent, // Special QST
kTypeSpecialArray, //
kTypeSpecialObject, //
kTypeEND,
kTypeStructDouble = kTypeNumber, // overlap bin serial with human friendly aliases
kTypeStructUInt64 = kTypeUInt, //
kTypeStructInt64 = kTypeSInt, //
};
union PrimitiveValue
{
AuUInt64 uint;
AuInt64 sint;
double number;
bool boolean;
glm::vec3 vec3;
glm::vec4 vec4;
};
struct Value
{
#define CONSTRUCTOR(type, member)\
Value(type val)\
{\
primitive.member = val;\
}
CONSTRUCTOR(const glm::vec3 &, vec3);
CONSTRUCTOR(const glm::vec4 &, vec4);
CONSTRUCTOR(bool, boolean);
CONSTRUCTOR(double, number);
CONSTRUCTOR(AuInt64, sint);
CONSTRUCTOR(AuUInt64, uint);
#undef CONSTRUCTOR
Value(uuids::uuid val)
{
UUID = val;
}
Value(const AuString &val)
{
string = val;
}
Value()
{
}
PrimitiveValue primitive;
uuids::uuid UUID;
AuString string;
};
struct TypedValue
{
DataType type;
Value value;
};
template<DataType type>
static constexpr AuUInt GetDatatypeLength()
{
switch /*constexpr*/ (type)
{
case DataType::kTypeBoolean: return 1;
case DataType::kTypeStructFloat: return 4;
case DataType::kTypeStructDouble: return 8;
case DataType::kTypeVec3: return 3 * 4;
case DataType::kTypeVec4: return 4 * 4;
case DataType::kTypeStructUInt8: return 1;
case DataType::kTypeStructInt8: return 1;
case DataType::kTypeStructUInt16: return 2;
case DataType::kTypeStructInt16: return 2;
case DataType::kTypeStructUInt32: return 4;
case DataType::kTypeStructInt32: return 4;
case DataType::kTypeStructUInt64: return 8;
case DataType::kTypeStructInt64: return 8;
default: static_assert(false, "invalid datatype");
}
}
static AuUInt GetDatatypeLength(Data::DataType type)
{
switch /*constexpr*/ (type)
{
case DataType::kTypeBoolean: return 1;
case DataType::kTypeStructFloat: return 4;
case DataType::kTypeStructDouble: return 8;
case DataType::kTypeVec3: return 3 * 4;
case DataType::kTypeVec4: return 4 * 4;
case DataType::kTypeStructUInt8: return 1;
case DataType::kTypeStructInt8: return 1;
case DataType::kTypeStructUInt16: return 2;
case DataType::kTypeStructInt16: return 2;
case DataType::kTypeStructUInt32: return 4;
case DataType::kTypeStructInt32: return 4;
case DataType::kTypeStructUInt64: return 8;
case DataType::kTypeStructInt64: return 8;
default: return 0;
}
}
}

View File

@ -0,0 +1,58 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Debug.hpp
Date: 2021-6-9
Author: Reece
***/
#pragma once
#include <Aurora/Console/Console.hpp>
#include "StackTrace.hpp"
#include "FailureCategory.hpp"
namespace Aurora::Debug
{
/**
Retrieves a print-friendly callstack of the last trap (either innocent exception or fatal mem access) <br>
On Win32, this information is always available <br>
On other platforms, this function will likely yield no valuable information
*/
AUKN_SYM AuString GetLastErrorStack();
AUKN_SYM StackTrace GetLastStackTrace();
/**
Retrieve information about the last exception. <br>
On Win32, this information is always available <br>
On other platforms, this information is only available within C++14 catch blocks
*/
AUKN_SYM AuString GetLastException();
/**
Retrieve the last system error (IE: Win32, GetLastError())
*/
AUKN_SYM AuString GetLastSystemMessage();
/**
Prints the current error state of the thread including: <br>
Current System Error, <br>
Current Runtime Error, <br>
Last Exception Call Stack, <br>
Last major ring notification
*/
AUKN_SYM void PrintError();
/**
Immediately terminates the process.
May attempt some hardened telemetry debug ops
*/
AUKN_SYM AU_NORETURN void Panic();
}
#include "SysPanic.hpp"
#include "SysAssertions.hpp"
#include "SysErrors.hpp"

View File

@ -0,0 +1,39 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: FailureCategory.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::Debug
{
enum FailureCategory
{
kFailureGeneric,
kFailureNested,
kFailureMemory,
kFailureIO,
kFailureFIO,
kFailureNet,
kFailureAudio,
kFailureHAL,
kFailureHALContext,
kFailureCrypto,
kFailureParam,
kFailureLogicError,
kFailureMathError,
kFailureUnavailableError,
kFailureTimeoutError,
kFailureWatchdogError,
kFailureServiceError,
kFailurePermissionError,
kFailureOutOfRange,
kFailureSyntaxError,
kFailureDisconnected,
kFailureUninitialized,
kFailureUserBegin = 256
};
}

View File

@ -0,0 +1,24 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: StackTrace.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::Debug
{
struct StackTraceEntry
{
std::optional<AuString> label;
AuUInt64 address;
std::optional<AuString> module;
std::optional<std::tuple<AuString, int, int>> file; // file, line, offset
AUKN_SYM AuString Stringify() const;
};
using StackTrace = AuList<StackTraceEntry>;
AUKN_SYM AuString StringifyStackTrace(const StackTrace &backtrace);
}

View File

@ -0,0 +1,193 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: SysAssertions.hpp
Date: 2021-6-10
Author: Reece
***/
//#pragma once <- AURORA_NO_ASSERTIONS may be redefined. do not cache
#if !defined(AURORA_NO_ASSERTIONS)
// defines SysAssert and SysAssertDbg
#if defined(DEBUG)
/// @private
template<typename ... T>
static inline void SysAssertFileEx(const char *file, int fileno, const char *func, bool tru, T... args)
{
if (tru)
{
return;
}
Aurora::Console::Logging::WriteLinef(
Aurora::Console::EAnsiColor::eBoldRed,
"Fatal",
"Expression address: {} {}:{}", func, file, fileno);
if constexpr (sizeof...(T) == 0)
{
SysPanic("That's all folks");
}
else
{
SysPanic(args...);
}
}
/**
A simple assertion with an optional message
*/
#define SysAssert(tru, ...) \
do \
{ \
SysAssertFileEx(__FILE__, __LINE__, __FUNCTION__, tru, ## __VA_ARGS__); \
} while (0)
/**
A simple assertion with an optional message under debug targets
*/
#define SysAssertDbg SysAssert
#else
/// @private
template<typename ... T>
static inline void SysAssertEx(bool tru, T... args)
{
if (tru)
{
return;
}
if constexpr (sizeof...(T) == 0)
{
SysPanic("That's all folks");
}
else
{
SysPanic(args...);
}
}
/**
A simple assertion with an optional message
*/
#define SysAssert(tru, ...) \
do \
{ \
SysAssertEx(tru, ## __VA_ARGS__); \
} while (0)
/**
A simple assertion with an optional message under debug targets
*/
#define SysAssertDbg(tru, ...) do {} while (0)
#endif
// defines SysAssertExp and SysAssertDbgExp
#if defined(DEBUG)
/// @private
template<typename ... T>
static inline void SysAssertFileExpEx(const char *file, int fileno, const char *func, const char *exp, bool tru, T... args)
{
if (tru)
{
return;
}
Aurora::Console::Logging::WriteLinef(
Aurora::Console::EAnsiColor::eBoldRed,
"Fatal",
"Expression address: {} {}:{}", func, file, fileno);
Aurora::Console::Logging::WriteLinef(
Aurora::Console::EAnsiColor::eBoldRed,
"Fatal",
"Expression failed: {}", exp);
if constexpr (sizeof...(T) == 0)
{
SysPanic("That's all folks");
}
else
{
SysPanic(args...);
}
}