/*** Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: Base32.cpp Date: 2021-6-12 Author: Reece ***/ #include #include "Base32.hpp" #include namespace Aurora::Parse { AUKN_SYM bool Base32Decode(const AuString &in, Memory::ByteBuffer &decoded) { unsigned long length = in.size(); try { decoded.resize(in.size()); auto status = base32_decode(in.data(), in.size(), reinterpret_cast(&decoded[0]), &length, BASE32_RFC4648); decoded.resize(length); return status == CRYPT_OK; } catch (...) { Console::Logging::LogWarn("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(buffer), length, &encoded[0], &outLength, BASE32_RFC4648); encoded.resize(outLength); return status == CRYPT_OK; } catch (...) { Console::Logging::LogWarn("Encoding error"); Debug::PrintError(); return false; } } }