J Reece Wilson
3defb1bb14
[*] 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
71 lines
1.8 KiB
C++
71 lines
1.8 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: Base64.cpp
|
|
Date: 2021-6-12
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "Base64.hpp"
|
|
#include <tomcrypt.h>
|
|
|
|
namespace Aurora::Parse
|
|
{
|
|
AUKN_SYM bool Base64Decode(const AuString &in, AuByteBuffer &decoded, bool url)
|
|
{
|
|
unsigned long length = in.size();
|
|
|
|
if (!AuTryResize(decoded, length))
|
|
{
|
|
SysPushErrorMem();
|
|
return false;
|
|
}
|
|
|
|
int status;
|
|
if (url)
|
|
{
|
|
status = base64url_decode(in.data(), in.size(), reinterpret_cast<unsigned char *>(&decoded[0]), &length);
|
|
}
|
|
else
|
|
{
|
|
status = base64_decode(in.data(), in.size(), reinterpret_cast<unsigned char *>(&decoded[0]), &length);
|
|
}
|
|
|
|
if (!AuTryResize(decoded, length))
|
|
{
|
|
SysPushErrorMem();
|
|
return false;
|
|
}
|
|
|
|
return status == CRYPT_OK;
|
|
}
|
|
|
|
AUKN_SYM bool Base64Encode(const Memory::MemoryViewRead &input, AuString &encoded, bool url)
|
|
{
|
|
unsigned long outLength = input.length + (input.length / 3.0) + 16;
|
|
|
|
if (!AuTryResize(encoded, outLength))
|
|
{
|
|
SysPushErrorMem();
|
|
return false;
|
|
}
|
|
|
|
int status;
|
|
if (url)
|
|
{
|
|
status = base64url_encode(reinterpret_cast<const unsigned char*>(input.ptr), input.length, &encoded[0], &outLength);
|
|
}
|
|
else
|
|
{
|
|
status = base64_encode(reinterpret_cast<const unsigned char*>(input.ptr), input.length, &encoded[0], &outLength);
|
|
}
|
|
|
|
if (!AuTryResize(encoded, outLength))
|
|
{
|
|
SysPushErrorMem();
|
|
return false;
|
|
}
|
|
|
|
return status == CRYPT_OK;
|
|
}
|
|
} |