C++ Essence Library 0.1.0
A Utility Library for Modern C++ Programming
Loading...
Searching...
No Matches
chunk_processor.hpp
1/*
2 * Copyright (c) 2024 The RefValue Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include "../compat.hpp"
26#include "../range.hpp"
27#include "../zstring_view.hpp"
28#include "abstract/chunk_processor.hpp"
29#include "common_types.hpp"
30
31#include <array>
32#include <cstddef>
33#include <span>
34#include <utility>
35
36namespace essence::crypto {
42 ES_API(CPPESSENCE) abstract::chunk_processor make_base64_encoder(bool newlines = false);
43
48 ES_API(CPPESSENCE) abstract::chunk_processor make_base64_decoder();
49
59 ES_API(CPPESSENCE)
60 abstract::chunk_processor make_symmetric_cipher_chunk_processor(zstring_view cipher_name,
61 cipher_padding_mode padding_mode, std::span<const std::byte> key, std::span<const std::byte> iv,
62 bool encryption = true);
63
75 template <byte_like_contiguous_range KeyRange, byte_like_contiguous_range IVRange>
76 abstract::chunk_processor make_symmetric_cipher_chunk_processor(zstring_view cipher_name,
77 cipher_padding_mode padding_mode, KeyRange&& key, IVRange&& iv, bool encryption = true) {
78 return make_symmetric_cipher_chunk_processor(
79 cipher_name, padding_mode, as_const_byte_span(key), as_const_byte_span(iv), encryption);
80 }
81
87 ES_API(CPPESSENCE)
88 abstract::chunk_processor chain_chunk_processors(std::span<abstract::chunk_processor> processors);
89
96 template <typename... Args>
97 requires(std::same_as<std::decay_t<Args>, abstract::chunk_processor> && ...)
98 abstract::chunk_processor chain_chunk_processors(Args&&... args) {
99 std::array processors{std::move(args)...};
100
101 return chain_chunk_processors(processors);
102 }
103} // namespace essence::crypto