|
VLink 2.0.0
A high-performance communication middleware
|
Thread-safe AES-128-CBC encryption/decryption utility with custom callback support. 更多...
#include <security.h>
Public 类型 | |
| using | Callback = std::function<bool(const Bytes& in, Bytes& out)> |
| Callback type for custom encryption or decryption. | |
Public 成员函数 | |
| Security () | |
Constructs a Security object with the default AES key and IV. | |
| ~Security () | |
Destroys the Security object and frees the EVP context. | |
| void | set_key (const std::string &key) |
| Sets the AES encryption key. | |
| void | set_callbacks (Callback &&encrypt_callback, Callback &&decrypt_callback) |
| Installs custom encrypt and decrypt callbacks, bypassing the built-in AES. | |
| bool | encrypt (const Bytes &in, Bytes &out) |
Encrypts in and writes the ciphertext into out. | |
| bool | decrypt (const Bytes &in, Bytes &out) |
Decrypts in and writes the plaintext into out. | |
Thread-safe AES-128-CBC encryption/decryption utility with custom callback support.
Each Security instance holds its own EVP context and key material. Copy and assignment are disabled; instances are intended to be owned by a single transport endpoint.
| using vlink::Security::Callback = std::function<bool(const Bytes& in, Bytes& out)> |
Callback type for custom encryption or decryption.
Called with the input Bytes; the implementation must write the result into out and return true on success. When a custom callback is installed via set_callbacks(), the built-in AES implementation is bypassed.
| vlink::Security::Security | ( | ) |
Constructs a Security object with the default AES key and IV.
Initialises an OpenSSL EVP context with AES-128-CBC and PKCS7 padding when VLINK_ENABLE_SECURITY is defined. Otherwise logs a warning.
| vlink::Security::~Security | ( | ) |
Destroys the Security object and frees the EVP context.
Decrypts in and writes the plaintext into out.
Uses the custom decrypt callback if installed, otherwise uses AES-128-CBC. If in is empty, out is unchanged and true is returned immediately.
| in | Ciphertext bytes. |
| out | Output buffer for plaintext. Overwritten on success. |
true on success; false if decryption fails or the feature is disabled. Encrypts in and writes the ciphertext into out.
Uses the custom encrypt callback if installed, otherwise uses AES-128-CBC. If in is empty, out is unchanged and true is returned immediately.
| in | Plaintext bytes. |
| out | Output buffer for ciphertext. Overwritten on success. |
true on success; false if encryption fails or the feature is disabled. Installs custom encrypt and decrypt callbacks, bypassing the built-in AES.
When both callbacks are set, encrypt() delegates to encrypt_callback and decrypt() delegates to decrypt_callback. Set to nullptr to fall back to the built-in AES implementation.
| encrypt_callback | Custom encryption function. |
| decrypt_callback | Custom decryption function. |
| void vlink::Security::set_key | ( | const std::string & | key | ) |