Skip to content

Commit

Permalink
add nulltermination to vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavrax committed Oct 12, 2023
1 parent eece376 commit 6eeaace
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cpp/pubnub_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,13 @@ class crypto_module: public into_crypto_provider_ptr {
* @return The encrypted buffer
*/
std::vector<std::uint8_t> encrypt(std::vector<std::uint8_t>& to_encrypt) {
to_encrypt.push_back('\0');
pubnub_bymebl_t to_encrypt_c;
to_encrypt_c.ptr = to_encrypt.data();
to_encrypt_c.size = to_encrypt.size();

pubnub_bymebl_t result = this->d_module->encrypt(this->d_module, to_encrypt_c);
to_encrypt.pop_back();

if (result.ptr == nullptr) {
throw std::runtime_error("crypto_module::encrypt: Encryption failed!");
Expand All @@ -685,11 +687,13 @@ class crypto_module: public into_crypto_provider_ptr {
* @return The decrypted buffer
*/
std::vector<std::uint8_t> decrypt(std::vector<std::uint8_t>& to_decrypt) {
to_encrypt.push_back('\0');
pubnub_bymebl_t to_decrypt_c;
to_decrypt_c.ptr = to_decrypt.data();
to_decrypt_c.size = to_decrypt.size();

pubnub_bymebl_t result = this->d_module->decrypt(this->d_module, to_decrypt_c);
to_encrypt.pop_back();

if (result.ptr == nullptr) {
throw std::runtime_error("crypto_module::decrypt: Decryption failed!");
Expand Down

0 comments on commit 6eeaace

Please sign in to comment.