AuroraRuntime/Source/Parse/Base32.cpp
Reece e5e36bd887 Large Commit
[*] Fix deadlock in the async subsystem (NoLockShutdown vs Shutdown in exception handler)
[+] Added ProccessMap NT variant
[+] Added ToolHelp image profiling
[*] Improved exception awareness
[*] Delegated SpawnThread to isolated TU, ready for reuse for RunAs and XNU Open - now with horrible evil alloc that could fail
[+] Added header for future api 'UtilRun'
[*] Improve NT core detection
[*] Changed small affinity bitmap to AuUInt64 instead of AuUInt32
[+] Added data structure to hold cpuids/affinity masks
[+] Implemented logger sinks
[+] Implemented logger glue logic
[*] Began migrating older loggers to sink-based default devices
[*] Minor refactors
[*] Improved internal exception discarding, not yet nothrow capable
[*] Minor create directory fix
2022-01-24 18:43:53 +00:00

49 lines
1.4 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Base32.cpp
Date: 2021-6-12
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Base32.hpp"
#include <tomcrypt.h>
namespace Aurora::Parse
{
AUKN_SYM bool Base32Decode(const AuString &in, AuByteBuffer &decoded)
{
unsigned long length = in.size();
try
{
decoded.resize(in.size());
auto status = base32_decode(in.data(), in.size(), reinterpret_cast<unsigned char *>(&decoded[0]), &length, BASE32_RFC4648);
decoded.resize(length);
return status == CRYPT_OK;
}
catch (...)
{
AuLogWarn("Decoding error: {}", in);
Debug::PrintError();
return false;
}
}
AUKN_SYM bool Base32Encode(const void *buffer, AuMach length, AuString &encoded)
{
unsigned long outLength = (length * 8 + 4) / 5;
try
{
encoded.resize(outLength);
auto status = base32_encode(reinterpret_cast<const unsigned char *>(buffer), length, &encoded[0], &outLength, BASE32_RFC4648);
encoded.resize(outLength);
return status == CRYPT_OK;
}
catch (...)
{
AuLogWarn("Encoding error");
Debug::PrintError();
return false;
}
}
}