Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
Crypter.h
浏览该文件的文档.
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
54 const void *crypter_pointer{};
55};
56
58class Decrypter final : public Crypter {
59public:
60 explicit Decrypter(const CrypterContext::Ptr &crypter_context);
61
62 ~Decrypter() override;
63
64 int update(void *out, int &out_len, const void *in, int in_len) const noexcept override;
65
66 int final(void *out, int &out_len) const noexcept override;
67
68private:
69 void *ctx_;
71};
72
74class Encrypter final : public Crypter {
75public:
76 explicit Encrypter(const CrypterContext::Ptr &crypter_context);
77
78 ~Encrypter() override;
79
80 int update(void *out, int &out_len, const void *in, int in_len) const noexcept override;
81
82 int final(void *out, int &out_len) const noexcept override;
83
84private:
85 void *ctx_;
87};
88
89}