53 lines
1.4 KiB
C++
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(), (unsigned long)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) + 5;
|
|
|
|
if (!AuTryResize(encoded, outLength))
|
|
{
|
|
SysPushErrorMem();
|
|
return false;
|
|
}
|
|
|
|
auto status = base32_encode(reinterpret_cast<const unsigned char *>(buffer), (unsigned long)length, &encoded[0], &outLength, BASE32_RFC4648);
|
|
if (!AuTryResize(encoded, length))
|
|
{
|
|
SysPushErrorMem();
|
|
return false;
|
|
}
|
|
|
|
return status == CRYPT_OK;
|
|
}
|
|
} |