Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
Crypter.h
Go to the documentation of this file.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
20
21#pragma once
22
23#include <sese/io/InputBuffer.h>
24
25namespace sese::security::evp {
26
28class Crypter {
29public:
30 virtual ~Crypter() = default;
31
38 virtual int update(void *out, int &out_len, const void *in, int in_len) const noexcept = 0;
39
44 virtual int final(void *out, int &out_len) const noexcept = 0;
45};
46
49 using Ptr = std::unique_ptr<CrypterContext>;
50
53 const void *crypter_pointer{};
54};
55
57class Decrypter final : public Crypter {
58public:
59 explicit Decrypter(const CrypterContext::Ptr &crypter_context);
60
61 ~Decrypter() override;
62
63 int update(void *out, int &out_len, const void *in, int in_len) const noexcept override;
64
65 int final(void *out, int &out_len) const noexcept override;
66
67private:
68 void *ctx_;
70};
71
73class Encrypter final : public Crypter {
74public:
75 explicit Encrypter(const CrypterContext::Ptr &crypter_context);
76
77 ~Encrypter() override;
78
79 int update(void *out, int &out_len, const void *in, int in_len) const noexcept override;
80
81 int final(void *out, int &out_len) const noexcept override;
82
83private:
84 void *ctx_;
86};
87
88}