C++ Essence Library 0.1.0
A Utility Library for Modern C++ Programming
Loading...
Searching...
No Matches
pubkey_cipher_provider.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 "../abi/string.hpp"
26#include "../abi/vector.hpp"
27#include "../compat.hpp"
28#include "../range.hpp"
29#include "asymmetric_key.hpp"
30
31#include <cstddef>
32#include <memory>
33#include <span>
34#include <string_view>
35
36namespace essence::crypto {
38 public:
39 ES_API(CPPESSENCE) explicit pubkey_cipher_provider(const asymmetric_key& key);
40 ES_API(CPPESSENCE) pubkey_cipher_provider(pubkey_cipher_provider&&) noexcept;
41 ES_API(CPPESSENCE) ~pubkey_cipher_provider();
42 ES_API(CPPESSENCE) pubkey_cipher_provider& operator=(pubkey_cipher_provider&&) noexcept;
43 [[nodiscard]] ES_API(CPPESSENCE) bool encryptor() const noexcept;
44 [[nodiscard]] ES_API(CPPESSENCE) std::shared_ptr<void> context() const;
45 [[nodiscard]] ES_API(CPPESSENCE) abi::vector<std::byte> as_bytes(std::span<const std::byte> buffer) const;
46 [[nodiscard]] ES_API(CPPESSENCE) abi::string as_string(std::span<const std::byte> buffer) const;
47 [[nodiscard]] ES_API(CPPESSENCE) abi::string as_base64(std::span<const std::byte> buffer) const;
48 [[nodiscard]] ES_API(CPPESSENCE) abi::string string_from_base64(std::string_view base64) const;
49 [[nodiscard]] ES_API(CPPESSENCE) abi::vector<std::byte> bytes_from_base64(std::string_view base64) const;
50
51 template <byte_like_contiguous_range Range>
52 abi::vector<std::byte> as_bytes(Range&& range) const {
53 return as_bytes(as_const_byte_span(range));
54 }
55
56 template <byte_like_contiguous_range Range>
57 abi::string as_string(Range&& range) const {
58 return as_string(as_const_byte_span(range));
59 }
60
61 template <byte_like_contiguous_range Range>
62 abi::string as_base64(Range&& range) const {
63 return as_base64(as_const_byte_span(range));
64 }
65
66 private:
67 class impl;
68
69 std::unique_ptr<impl> impl_;
70 };
71} // namespace essence::crypto
Represents an asymmetric key or key pair for a pubkey encryption algorithm.
Definition asymmetric_key.hpp:40
Definition pubkey_cipher_provider.hpp:37