userver: userver/crypto/base64.hpp Source File
Loading...
Searching...
No Matches
base64.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/crypto/base64.hpp
4/// @brief @copybrief crypto::base64
5/// @ingroup userver_universal
6
7#include <string>
8#include <string_view>
9
10USERVER_NAMESPACE_BEGIN
11
12/// Cryptographic hashing
13namespace crypto::base64 {
14
15enum class Pad { kWith, kWithout };
16
17/// @brief Encodes data to Base64, add padding by default
18/// @param data binary data to encode
19/// @param pad controls if pad should be added or not
20/// @throws CryptoException internal library exception
21std::string Base64Encode(std::string_view data, Pad pad = Pad::kWith);
22
23/// @brief Decodes data from Base64
24/// @throws CryptoException internal library exception
25std::string Base64Decode(std::string_view data);
26
27#ifndef USERVER_NO_CRYPTOPP_BASE64_URL
28
29/// @brief Encodes data to Base64 (using URL alphabet), add padding by default
30/// @param data binary data to encode
31/// @param pad controls if pad should be added or not
32/// @throws CryptoException internal library exception
33std::string Base64UrlEncode(std::string_view data, Pad pad = Pad::kWith);
34
35/// @brief Decodes data from Base64 (using URL alphabet)
36/// @throws CryptoException internal library exception
37std::string Base64UrlDecode(std::string_view data);
38
39/// @brief Decodes @a data in-place and returns `true` on success.
40/// @note Supports both traditional and "web-safe" base64 encodings.
41[[nodiscard]] bool Base64UniversalDecodeInPlace(std::string& data) noexcept;
42
43#endif
44
45} // namespace crypto::base64
46
47USERVER_NAMESPACE_END