diff --git a/CMakeLists.txt b/CMakeLists.txt index 71aef7a..4b7ab6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,9 @@ set(HEADERS # Create the shared library add_library(privatebinapi SHARED ${SOURCES} ${HEADERS}) +# Define PRIVATEBINAPI_EXPORTS for the library build +target_compile_definitions(privatebinapi PRIVATE PRIVATEBINAPI_EXPORTS) + # Include directories target_include_directories(privatebinapi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include @@ -110,4 +113,4 @@ if(ENABLE_LLVM_COVERAGE) WORKING_DIRECTORY ${CMAKE_BINARY_DIR} DEPENDS privatebinapi ) -endif() \ No newline at end of file +endif() diff --git a/src/base58.cpp b/src/base58.cpp index 1e7ab93..6697475 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -16,7 +16,7 @@ std::string Base58::encode(const std::vector& data) { } // Convert to base58 - std::vector digits((data.size() - leading_zeros) * 138 / 100 + 1); + std::vector digits(static_cast((data.size() - leading_zeros) * 138 / 100 + 1)); size_t digitslen = 1; for (size_t i = leading_zeros; i < data.size(); i++) { diff --git a/src/crypto.cpp b/src/crypto.cpp index 472ff59..a452208 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -45,13 +45,13 @@ std::vector Crypto::encrypt(const std::vector& pla encryption.EncryptAndAuthenticate( ciphertext.data(), auth_tag.data(), - auth_tag.size(), + static_cast(auth_tag.size()), iv.data(), - iv.size(), + static_cast(iv.size()), nullptr, 0, // Additional authenticated data plaintext.data(), - plaintext.size() + static_cast(plaintext.size()) ); return ciphertext; @@ -79,13 +79,13 @@ std::vector Crypto::decrypt(const std::vector& cip bool valid = decryption.DecryptAndVerify( plaintext.data(), auth_tag.data(), - auth_tag.size(), + static_cast(auth_tag.size()), iv.data(), - iv.size(), + static_cast(iv.size()), nullptr, 0, // Additional authenticated data ciphertext.data(), - ciphertext.size() + static_cast(ciphertext.size()) ); if(!valid) { diff --git a/src/privatebinapi.cpp b/src/privatebinapi.cpp index b3d2d56..b1e733a 100644 --- a/src/privatebinapi.cpp +++ b/src/privatebinapi.cpp @@ -26,14 +26,14 @@ static void copy_string_to_output(const std::string& source, char** destination) if (destination) { *destination = static_cast(malloc(source.length() + 1)); if (*destination) { - std::strcpy(*destination, source.c_str()); + strcpy_s(*destination, source.length() + 1, source.c_str()); } } } extern "C" { -int create_paste(const char* server_url, const char* content, +PRIVATEBIN_API int create_paste(const char* server_url, const char* content, const char* password, const char* expiration, const char* format, int burn_after_reading, int open_discussion, char** paste_url, @@ -128,10 +128,10 @@ int create_paste(const char* server_url, const char* content, } } -int upload_file(const char* server_url, const char* file_path, - const char* password, const char* expiration, - int burn_after_reading, int open_discussion, - char** paste_url, char** delete_token) { +PRIVATEBIN_API int upload_file(const char* server_url, const char* file_path, + const char* password, const char* expiration, + int burn_after_reading, int open_discussion, + char** paste_url, char** delete_token) { if (!server_url || !file_path) { return ERROR_INVALID_INPUT; @@ -248,7 +248,7 @@ int upload_file(const char* server_url, const char* file_path, } } -int get_paste(const char* server_url, const char* paste_id, +PRIVATEBIN_API int get_paste(const char* server_url, const char* paste_id, const char* key, char** content) { if (!server_url || !paste_id || !key || !content) { @@ -305,7 +305,7 @@ int get_paste(const char* server_url, const char* paste_id, } } -int delete_paste(const char* server_url, const char* paste_id, +PRIVATEBIN_API int delete_paste(const char* server_url, const char* paste_id, const char* delete_token) { if (!server_url || !paste_id || !delete_token) { @@ -347,7 +347,7 @@ int delete_paste(const char* server_url, const char* paste_id, } } -void free_string(char* str) { +PRIVATEBIN_API void free_string(char* str) { if (str) { free(str); } diff --git a/tests/test_basic.cpp b/tests/test_basic.cpp index 7ddc9e2..3bfcb4a 100644 --- a/tests/test_basic.cpp +++ b/tests/test_basic.cpp @@ -21,9 +21,12 @@ static bool extract_paste_id_and_key(const std::string& full_url, std::string& p } int main() { - const char* it = std::getenv("PRIVATEBIN_IT"); + char* it = nullptr; + size_t len = 0; + _dupenv_s(&it, &len, "PRIVATEBIN_IT"); if (!it || std::string(it) == "0") { std::cout << "[test] PRIVATEBIN_IT not set; skipping integration test." << std::endl; + free(it); return 0; // treat as success when integration testing is disabled }