Jamie Reece Wilson
83f34b0c47
03:28:55:638 17>2 of 53388 functions (<0.1%) were compiled, the rest were copied from previous compilation. 03:28:55:638 17> 0 functions were new in current compilation 03:28:55:638 17> 65 functions had inline decision re-evaluated but remain unchanged 03:28:56:749 17>Finished generating code the header of const AuString & is the same as std::string_view therefore nothing changes. in fact, we still need to alloc strings a bunch of times for a zero terminated string. worse, <c++20 always allocs each time we want to access a hashmap with o(1) lookup, making small hashmaps kinda pointless when we always have to alloc+copy (thx std) perhaps this will help some language binders
64 lines
1.8 KiB
C++
64 lines
1.8 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuBase32.cpp
|
|
Date: 2021-6-12
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "AuBase32.hpp"
|
|
#include <tomcrypt.h>
|
|
|
|
namespace Aurora::Parse
|
|
{
|
|
AUKN_SYM bool Base32Decode(const AuROString &in, AuByteBuffer &decoded)
|
|
{
|
|
int iRet;
|
|
unsigned long uLength = in.size();
|
|
|
|
auto writeView = decoded.GetOrAllocateLinearWriteable(uLength);
|
|
if (!writeView)
|
|
{
|
|
SysPushErrorMem();
|
|
return false;
|
|
}
|
|
|
|
iRet = ::base32_decode(AuReinterpretCast<const char *>(in.data()),
|
|
(unsigned long)uLength,
|
|
AuReinterpretCast<unsigned char *>(decoded.writePtr),
|
|
&uLength,
|
|
BASE32_RFC4648);
|
|
if (iRet != CRYPT_OK)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
decoded.writePtr += uLength;
|
|
return true;
|
|
}
|
|
|
|
AUKN_SYM bool Base32Encode(const Memory::MemoryViewRead &input, AuString &encoded)
|
|
{
|
|
unsigned long uOutLength = ((input.length * 8 + 4) / 5) + 5;
|
|
|
|
if (!AuTryResize(encoded, uOutLength))
|
|
{
|
|
SysPushErrorMem();
|
|
return false;
|
|
}
|
|
|
|
auto iRet = ::base32_encode(AuReinterpretCast<const unsigned char *>(input.ptr),
|
|
(unsigned long)input.length,
|
|
&encoded[0],
|
|
&uOutLength,
|
|
BASE32_RFC4648);
|
|
|
|
if (!AuTryResize(encoded, uOutLength))
|
|
{
|
|
SysPushErrorMem();
|
|
return false;
|
|
}
|
|
|
|
return iRet == CRYPT_OK;
|
|
}
|
|
} |