AuroraRuntime/Source/Parse/Base32.cpp
J Reece Wilson 3defb1bb14 [+] Linux Watcher
[*] Expand watcher API -> Breaking NT
[*] Reexpand loop queue API -> Breaking NT
[*] Linux CPUInfo clean up
[*] Bug fix: mkdir should set execute flag... because directories are special
[*] Refactor: Cleanup base64
[*] Bug fix: UNIX path normalization
[*] Bug fix: missing O_CREAT flag (au auto-creates)
[*] Normalize line endings
2022-04-10 16:40:49 +01:00

53 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();
if (!AuTryResize(decoded, length))
{
SysPushErrorMem();
return false;
}
auto status = base32_decode(in.data(), in.size(), reinterpret_cast<unsigned char *>(&decoded[0]), &length, BASE32_RFC4648);
if (!AuTryResize(decoded, length))
{
SysPushErrorMem();
return false;
}
return status == CRYPT_OK;
}
AUKN_SYM bool Base32Encode(const void *buffer, AuMach length, AuString &encoded)
{
unsigned long outLength = (length * 8 + 4) / 5;
if (!AuTryResize(encoded, length))
{
SysPushErrorMem();
return false;
}
auto status = base32_encode(reinterpret_cast<const unsigned char *>(buffer), length, &encoded[0], &outLength, BASE32_RFC4648);
if (!AuTryResize(encoded, length))
{
SysPushErrorMem();
return false;
}
return status == CRYPT_OK;
}
}