lib/crypto/Base64: add overload which returns AllocatedArray<std::byte>
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "Base64.hxx"
|
||||
#include "lib/ffmpeg/Error.hxx"
|
||||
#include "util/AllocatedArray.hxx"
|
||||
|
||||
extern "C" {
|
||||
#include <libavutil/base64.h>
|
||||
@@ -54,3 +55,12 @@ DecodeBase64(std::span<std::byte> out, const char *in)
|
||||
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
AllocatedArray<std::byte>
|
||||
DecodeBase64(std::string_view src)
|
||||
{
|
||||
AllocatedArray<std::byte> dest{CalculateBase64OutputSize(src.size())};
|
||||
const std::size_t dest_size = DecodeBase64(dest, src);
|
||||
dest.SetSize(dest_size);
|
||||
return dest;
|
||||
}
|
||||
|
@@ -33,6 +33,8 @@
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
|
||||
template<typename T> class AllocatedArray;
|
||||
|
||||
constexpr size_t
|
||||
CalculateBase64OutputSize(size_t in_size) noexcept
|
||||
{
|
||||
@@ -50,3 +52,11 @@ DecodeBase64(std::span<std::byte> out, std::string_view in);
|
||||
*/
|
||||
size_t
|
||||
DecodeBase64(std::span<std::byte> out, const char *in);
|
||||
|
||||
/**
|
||||
* Throws on error.
|
||||
*
|
||||
* @return the decoded string
|
||||
*/
|
||||
AllocatedArray<std::byte>
|
||||
DecodeBase64(std::string_view src);
|
||||
|
Reference in New Issue
Block a user