2020-04-26 23:49:19 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-26 23:49:19 +03:00
|
|
|
*/
|
|
|
|
|
2020-05-28 21:40:53 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-10-13 17:48:48 +03:00
|
|
|
#include <AK/ByteBuffer.h>
|
2022-01-20 20:01:39 +03:00
|
|
|
#include <AK/Error.h>
|
2022-12-19 02:23:47 +03:00
|
|
|
#include <AK/String.h>
|
2020-10-13 17:48:48 +03:00
|
|
|
#include <AK/StringView.h>
|
2020-04-26 23:49:19 +03:00
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
2024-09-01 18:49:23 +03:00
|
|
|
size_t size_required_to_decode_base64(StringView);
|
|
|
|
|
2024-07-15 22:25:08 +03:00
|
|
|
ErrorOr<ByteBuffer> decode_base64(StringView);
|
|
|
|
ErrorOr<ByteBuffer> decode_base64url(StringView);
|
2023-01-10 11:34:29 +03:00
|
|
|
|
2024-09-02 00:41:57 +03:00
|
|
|
struct InvalidBase64 {
|
|
|
|
Error error;
|
|
|
|
size_t valid_input_bytes { 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
// On success, these return the number of input bytes that were decoded. This might be less than the
|
|
|
|
// string length if the output buffer was not large enough.
|
|
|
|
ErrorOr<size_t, InvalidBase64> decode_base64_into(StringView, ByteBuffer&);
|
|
|
|
ErrorOr<size_t, InvalidBase64> decode_base64url_into(StringView, ByteBuffer&);
|
|
|
|
|
2024-07-15 23:12:21 +03:00
|
|
|
enum class OmitPadding {
|
|
|
|
No,
|
|
|
|
Yes,
|
|
|
|
};
|
|
|
|
|
|
|
|
ErrorOr<String> encode_base64(ReadonlyBytes, OmitPadding = OmitPadding::No);
|
|
|
|
ErrorOr<String> encode_base64url(ReadonlyBytes, OmitPadding = OmitPadding::No);
|
2024-03-20 15:21:59 +03:00
|
|
|
|
2020-04-26 23:49:19 +03:00
|
|
|
}
|
|
|
|
|
2022-11-26 14:18:30 +03:00
|
|
|
#if USING_AK_GLOBALLY
|
2020-04-26 23:49:19 +03:00
|
|
|
using AK::decode_base64;
|
2024-03-20 15:21:59 +03:00
|
|
|
using AK::decode_base64url;
|
2020-06-13 05:09:31 +03:00
|
|
|
using AK::encode_base64;
|
2024-03-20 15:21:59 +03:00
|
|
|
using AK::encode_base64url;
|
2022-11-26 14:18:30 +03:00
|
|
|
#endif
|