Compare commits
5 Commits
d712d3a9d8
...
v0.1.4.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77879e6521 | ||
|
|
3b4d591eff | ||
|
|
4add1edd11 | ||
|
|
5493c0dcf3 | ||
|
|
cd7e957692 |
@@ -20,7 +20,7 @@
|
|||||||
- **IMPROVED**: Enhanced build documentation with platform-specific instructions
|
- **IMPROVED**: Enhanced build documentation with platform-specific instructions
|
||||||
- **IMPROVED**: Better project structure and organization
|
- **IMPROVED**: Better project structure and organization
|
||||||
|
|
||||||
s## v0.1.1.3 (2025-08-28)
|
## v0.1.1.3 (2025-08-28)
|
||||||
|
|
||||||
### New Features
|
### New Features
|
||||||
- **File Upload Functionality**: New `upload_file()` function added
|
- **File Upload Functionality**: New `upload_file()` function added
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ set(HEADERS
|
|||||||
# Create the shared library
|
# Create the shared library
|
||||||
add_library(privatebinapi SHARED ${SOURCES} ${HEADERS})
|
add_library(privatebinapi SHARED ${SOURCES} ${HEADERS})
|
||||||
|
|
||||||
|
# Define PRIVATEBINAPI_EXPORTS for the library build
|
||||||
|
target_compile_definitions(privatebinapi PRIVATE PRIVATEBINAPI_EXPORTS)
|
||||||
|
|
||||||
# Include directories
|
# Include directories
|
||||||
target_include_directories(privatebinapi PUBLIC
|
target_include_directories(privatebinapi PUBLIC
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||||
@@ -109,12 +112,11 @@ if(ENABLE_LLVM_COVERAGE)
|
|||||||
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
|
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
|
||||||
add_link_options(-fprofile-instr-generate)
|
add_link_options(-fprofile-instr-generate)
|
||||||
|
|
||||||
# Helper variables for report tools (can be overridden from environment)
|
# Helper variables for report tools
|
||||||
set(LLVM_PROFDATA "llvm-profdata" CACHE STRING "Path to llvm-profdata")
|
set(LLVM_PROFDATA "llvm-profdata" CACHE STRING "Path to llvm-profdata")
|
||||||
set(LLVM_COV "llvm-cov" CACHE STRING "Path to llvm-cov")
|
set(LLVM_COV "llvm-cov" CACHE STRING "Path to llvm-cov")
|
||||||
|
|
||||||
# Custom target to run tests and produce coverage report
|
# Custom target to run tests and produce coverage report
|
||||||
# Usage: cmake --build build --target coverage_llvm --config Release
|
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
coverage_llvm
|
coverage_llvm
|
||||||
COMMAND ${CMAKE_COMMAND} -E env
|
COMMAND ${CMAKE_COMMAND} -E env
|
||||||
|
|||||||
@@ -3,6 +3,14 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
// Helper function to wait between API calls to avoid rate limiting
|
||||||
|
void wait_between_calls() {
|
||||||
|
std::cout << "[privatebinapi] Waiting 12 seconds to avoid rate limiting..." << std::endl;
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(12));
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
std::cout << "PrivateBin API C++ DLL Example" << std::endl;
|
std::cout << "PrivateBin API C++ DLL Example" << std::endl;
|
||||||
@@ -129,6 +137,9 @@ int main(int argc, char* argv[]) {
|
|||||||
std::cout << "✗ Plaintext paste failed. Error code: " << result << std::endl;
|
std::cout << "✗ Plaintext paste failed. Error code: " << result << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait between API calls to avoid rate limiting
|
||||||
|
wait_between_calls();
|
||||||
|
|
||||||
// Test 2: Syntax highlighting format
|
// Test 2: Syntax highlighting format
|
||||||
std::cout << "\n2. Testing syntax highlighting format..." << std::endl;
|
std::cout << "\n2. Testing syntax highlighting format..." << std::endl;
|
||||||
char* code_paste_url = nullptr;
|
char* code_paste_url = nullptr;
|
||||||
@@ -167,6 +178,9 @@ int main() {
|
|||||||
std::cout << "✗ Syntax highlighting paste failed. Error code: " << result << std::endl;
|
std::cout << "✗ Syntax highlighting paste failed. Error code: " << result << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait between API calls to avoid rate limiting
|
||||||
|
wait_between_calls();
|
||||||
|
|
||||||
// Test 3: Markdown format
|
// Test 3: Markdown format
|
||||||
std::cout << "\n3. Testing markdown format..." << std::endl;
|
std::cout << "\n3. Testing markdown format..." << std::endl;
|
||||||
char* markdown_paste_url = nullptr;
|
char* markdown_paste_url = nullptr;
|
||||||
@@ -213,6 +227,9 @@ int result = create_paste(server_url, content, password, expiration, format,
|
|||||||
std::cout << "✗ Markdown paste failed. Error code: " << result << std::endl;
|
std::cout << "✗ Markdown paste failed. Error code: " << result << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait between API calls to avoid rate limiting
|
||||||
|
wait_between_calls();
|
||||||
|
|
||||||
// Test 4: Interactive format selection
|
// Test 4: Interactive format selection
|
||||||
std::cout << "\n4. Interactive format selection..." << std::endl;
|
std::cout << "\n4. Interactive format selection..." << std::endl;
|
||||||
char* interactive_paste_url = nullptr;
|
char* interactive_paste_url = nullptr;
|
||||||
|
|||||||
@@ -31,3 +31,4 @@ Get-ChildItem -LiteralPath $OutDir -File | Format-Table Name,Length -AutoSize
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,3 +36,4 @@ Get-ChildItem -LiteralPath $BinDir -File | ForEach-Object {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,3 +44,4 @@ if ($resp.StatusCode -ge 200 -and $resp.StatusCode -lt 300) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -46,3 +46,4 @@ foreach ($f in $files) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -77,3 +77,4 @@ Write-Host 'Release notes updated with links.'
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,18 +16,19 @@ std::string Base58::encode(const std::vector<unsigned char>& data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert to base58
|
// Convert to base58
|
||||||
std::vector<unsigned char> digits((data.size() - leading_zeros) * 138 / 100 + 1);
|
size_t digits_size = (data.size() - leading_zeros) * 138 / 100 + 1;
|
||||||
|
std::vector<unsigned char> digits(digits_size);
|
||||||
size_t digitslen = 1;
|
size_t digitslen = 1;
|
||||||
|
|
||||||
for (size_t i = leading_zeros; i < data.size(); i++) {
|
for (size_t i = leading_zeros; i < data.size(); i++) {
|
||||||
unsigned int carry = data[i];
|
size_t carry = static_cast<size_t>(data[i]);
|
||||||
for (size_t j = 0; j < digitslen; j++) {
|
for (size_t j = 0; j < digitslen; j++) {
|
||||||
carry += (unsigned int)(digits[j]) << 8;
|
carry += static_cast<size_t>(digits[j]) << 8;
|
||||||
digits[j] = carry % 58;
|
digits[j] = static_cast<unsigned char>(carry % 58);
|
||||||
carry /= 58;
|
carry /= 58;
|
||||||
}
|
}
|
||||||
while (carry > 0) {
|
while (carry > 0) {
|
||||||
digits[digitslen++] = carry % 58;
|
digits[digitslen++] = static_cast<unsigned char>(carry % 58);
|
||||||
carry /= 58;
|
carry /= 58;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,22 +57,23 @@ std::vector<unsigned char> Base58::decode(const std::string& encoded) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert from base58
|
// Convert from base58
|
||||||
std::vector<unsigned char> bytes((encoded.length() - leading_ones) * 733 / 1000 + 1);
|
size_t bytes_size = (encoded.length() - leading_ones) * 733 / 1000 + 1;
|
||||||
|
std::vector<unsigned char> bytes(bytes_size);
|
||||||
size_t byteslen = 1;
|
size_t byteslen = 1;
|
||||||
|
|
||||||
for (size_t i = leading_ones; i < encoded.length(); i++) {
|
for (size_t i = leading_ones; i < encoded.length(); i++) {
|
||||||
unsigned int carry = ALPHABET.find(encoded[i]);
|
size_t carry = static_cast<size_t>(ALPHABET.find(encoded[i]));
|
||||||
if (carry == std::string::npos) {
|
if (carry == std::string::npos) {
|
||||||
throw std::invalid_argument("Invalid character in Base58 string");
|
throw std::invalid_argument("Invalid character in Base58 string");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t j = 0; j < byteslen; j++) {
|
for (size_t j = 0; j < byteslen; j++) {
|
||||||
carry += (unsigned int)(bytes[j]) * 58;
|
carry += static_cast<size_t>(bytes[j]) * 58;
|
||||||
bytes[j] = carry & 0xff;
|
bytes[j] = static_cast<unsigned char>(carry & 0xff);
|
||||||
carry >>= 8;
|
carry >>= 8;
|
||||||
}
|
}
|
||||||
while (carry > 0) {
|
while (carry > 0) {
|
||||||
bytes[byteslen++] = carry & 0xff;
|
bytes[byteslen++] = static_cast<unsigned char>(carry & 0xff);
|
||||||
carry >>= 8;
|
carry >>= 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,13 +45,13 @@ std::vector<unsigned char> Crypto::encrypt(const std::vector<unsigned char>& pla
|
|||||||
encryption.EncryptAndAuthenticate(
|
encryption.EncryptAndAuthenticate(
|
||||||
ciphertext.data(),
|
ciphertext.data(),
|
||||||
auth_tag.data(),
|
auth_tag.data(),
|
||||||
auth_tag.size(),
|
static_cast<int>(auth_tag.size()),
|
||||||
iv.data(),
|
iv.data(),
|
||||||
iv.size(),
|
static_cast<int>(iv.size()),
|
||||||
nullptr,
|
nullptr,
|
||||||
0, // Additional authenticated data
|
0, // Additional authenticated data
|
||||||
plaintext.data(),
|
plaintext.data(),
|
||||||
plaintext.size()
|
static_cast<int>(plaintext.size())
|
||||||
);
|
);
|
||||||
|
|
||||||
return ciphertext;
|
return ciphertext;
|
||||||
@@ -79,13 +79,13 @@ std::vector<unsigned char> Crypto::decrypt(const std::vector<unsigned char>& cip
|
|||||||
bool valid = decryption.DecryptAndVerify(
|
bool valid = decryption.DecryptAndVerify(
|
||||||
plaintext.data(),
|
plaintext.data(),
|
||||||
auth_tag.data(),
|
auth_tag.data(),
|
||||||
auth_tag.size(),
|
static_cast<int>(auth_tag.size()),
|
||||||
iv.data(),
|
iv.data(),
|
||||||
iv.size(),
|
static_cast<int>(iv.size()),
|
||||||
nullptr,
|
nullptr,
|
||||||
0, // Additional authenticated data
|
0, // Additional authenticated data
|
||||||
ciphertext.data(),
|
ciphertext.data(),
|
||||||
ciphertext.size()
|
static_cast<int>(ciphertext.size())
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!valid) {
|
if(!valid) {
|
||||||
|
|||||||
@@ -26,14 +26,14 @@ static void copy_string_to_output(const std::string& source, char** destination)
|
|||||||
if (destination) {
|
if (destination) {
|
||||||
*destination = static_cast<char*>(malloc(source.length() + 1));
|
*destination = static_cast<char*>(malloc(source.length() + 1));
|
||||||
if (*destination) {
|
if (*destination) {
|
||||||
std::strcpy(*destination, source.c_str());
|
strcpy_s(*destination, source.length() + 1, source.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
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* password, const char* expiration,
|
||||||
const char* format, int burn_after_reading,
|
const char* format, int burn_after_reading,
|
||||||
int open_discussion, char** paste_url,
|
int open_discussion, char** paste_url,
|
||||||
@@ -128,7 +128,7 @@ int create_paste(const char* server_url, const char* content,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int upload_file(const char* server_url, const char* file_path,
|
PRIVATEBIN_API int upload_file(const char* server_url, const char* file_path,
|
||||||
const char* password, const char* expiration,
|
const char* password, const char* expiration,
|
||||||
int burn_after_reading, int open_discussion,
|
int burn_after_reading, int open_discussion,
|
||||||
char** paste_url, char** delete_token) {
|
char** paste_url, char** delete_token) {
|
||||||
@@ -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) {
|
const char* key, char** content) {
|
||||||
|
|
||||||
if (!server_url || !paste_id || !key || !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) {
|
const char* delete_token) {
|
||||||
|
|
||||||
if (!server_url || !paste_id || !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) {
|
if (str) {
|
||||||
free(str);
|
free(str);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,12 @@ static bool extract_paste_id_and_key(const std::string& full_url, std::string& p
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
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") {
|
if (!it || std::string(it) == "0") {
|
||||||
std::cout << "[test] PRIVATEBIN_IT not set; skipping integration test." << std::endl;
|
std::cout << "[test] PRIVATEBIN_IT not set; skipping integration test." << std::endl;
|
||||||
|
free(it);
|
||||||
return 0; // treat as success when integration testing is disabled
|
return 0; // treat as success when integration testing is disabled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user