lib/crypto/Base64: use std::string_view

This commit is contained in:
Max Kellermann
2022-05-20 11:24:22 +02:00
parent 01b32d5ee0
commit 6633c7fd42
2 changed files with 4 additions and 6 deletions

View File

@@ -29,7 +29,6 @@
#include "Base64.hxx" #include "Base64.hxx"
#include "lib/ffmpeg/Error.hxx" #include "lib/ffmpeg/Error.hxx"
#include "util/StringView.hxx"
extern "C" { extern "C" {
#include <libavutil/base64.h> #include <libavutil/base64.h>
@@ -38,11 +37,11 @@ extern "C" {
#include <string> #include <string>
size_t size_t
DecodeBase64(std::span<std::byte> out, StringView in) DecodeBase64(std::span<std::byte> out, std::string_view in)
{ {
/* since av_base64_decode() wants a null-terminated string, we /* since av_base64_decode() wants a null-terminated string, we
need to make a copy here and null-terminate it */ need to make a copy here and null-terminate it */
const std::string copy(in.data, in.size); const std::string copy{in};
return DecodeBase64(out, copy.c_str()); return DecodeBase64(out, copy.c_str());
} }

View File

@@ -31,8 +31,7 @@
#include <cstddef> #include <cstddef>
#include <span> #include <span>
#include <string_view>
struct StringView;
constexpr size_t constexpr size_t
CalculateBase64OutputSize(size_t in_size) noexcept CalculateBase64OutputSize(size_t in_size) noexcept
@@ -44,7 +43,7 @@ CalculateBase64OutputSize(size_t in_size) noexcept
* Throws on error. * Throws on error.
*/ */
size_t size_t
DecodeBase64(std::span<std::byte> out, StringView in); DecodeBase64(std::span<std::byte> out, std::string_view in);
/** /**
* Throws on error. * Throws on error.