Initial commit: PrivateBin API C++ DLL implementation
This commit is contained in:
30
include/base58.h
Normal file
30
include/base58.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef BASE58_H
|
||||
#define BASE58_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Base58 {
|
||||
public:
|
||||
/**
|
||||
* Encodes data using Base58
|
||||
*
|
||||
* @param data The data to encode
|
||||
* @return The Base58 encoded string
|
||||
*/
|
||||
static std::string encode(const std::vector<unsigned char>& data);
|
||||
|
||||
/**
|
||||
* Decodes a Base58 string
|
||||
*
|
||||
* @param encoded The Base58 encoded string
|
||||
* @return The decoded data
|
||||
*/
|
||||
static std::vector<unsigned char> decode(const std::string& encoded);
|
||||
|
||||
private:
|
||||
static const std::string ALPHABET;
|
||||
static const int BASE58_BASE = 58;
|
||||
};
|
||||
|
||||
#endif // BASE58_H
|
||||
76
include/crypto.h
Normal file
76
include/crypto.h
Normal file
@ -0,0 +1,76 @@
|
||||
#ifndef CRYPTO_H
|
||||
#define CRYPTO_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Crypto {
|
||||
public:
|
||||
/**
|
||||
* Generates a random key of specified length
|
||||
*
|
||||
* @param length The length of the key to generate
|
||||
* @return The generated key
|
||||
*/
|
||||
static std::vector<unsigned char> generate_key(size_t length);
|
||||
|
||||
/**
|
||||
* Encrypts data using AES-GCM
|
||||
*
|
||||
* @param plaintext The data to encrypt
|
||||
* @param key The encryption key
|
||||
* @param iv The initialization vector
|
||||
* @param auth_tag Output parameter for the authentication tag
|
||||
* @return The encrypted data
|
||||
*/
|
||||
static std::vector<unsigned char> encrypt(const std::vector<unsigned char>& plaintext,
|
||||
const std::vector<unsigned char>& key,
|
||||
const std::vector<unsigned char>& iv,
|
||||
std::vector<unsigned char>& auth_tag);
|
||||
|
||||
/**
|
||||
* Decrypts data using AES-GCM
|
||||
*
|
||||
* @param ciphertext The data to decrypt
|
||||
* @param key The decryption key
|
||||
* @param iv The initialization vector
|
||||
* @param auth_tag The authentication tag
|
||||
* @return The decrypted data
|
||||
*/
|
||||
static std::vector<unsigned char> decrypt(const std::vector<unsigned char>& ciphertext,
|
||||
const std::vector<unsigned char>& key,
|
||||
const std::vector<unsigned char>& iv,
|
||||
const std::vector<unsigned char>& auth_tag);
|
||||
|
||||
/**
|
||||
* Derives a key using PBKDF2-HMAC-SHA256
|
||||
*
|
||||
* @param password The password to derive from
|
||||
* @param salt The salt to use
|
||||
* @param iterations The number of iterations
|
||||
* @param key_length The length of the derived key
|
||||
* @return The derived key
|
||||
*/
|
||||
static std::vector<unsigned char> pbkdf2_hmac_sha256(const std::string& password,
|
||||
const std::vector<unsigned char>& salt,
|
||||
int iterations,
|
||||
size_t key_length);
|
||||
|
||||
/**
|
||||
* Compresses data using zlib
|
||||
*
|
||||
* @param data The data to compress
|
||||
* @return The compressed data
|
||||
*/
|
||||
static std::vector<unsigned char> compress(const std::vector<unsigned char>& data);
|
||||
|
||||
/**
|
||||
* Decompresses data using zlib
|
||||
*
|
||||
* @param data The data to decompress
|
||||
* @return The decompressed data
|
||||
*/
|
||||
static std::vector<unsigned char> decompress(const std::vector<unsigned char>& data);
|
||||
};
|
||||
|
||||
#endif // CRYPTO_H
|
||||
47
include/http_client.h
Normal file
47
include/http_client.h
Normal file
@ -0,0 +1,47 @@
|
||||
#ifndef HTTP_CLIENT_H
|
||||
#define HTTP_CLIENT_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class HttpClient {
|
||||
public:
|
||||
/**
|
||||
* Performs an HTTP GET request
|
||||
*
|
||||
* @param url The URL to request
|
||||
* @param response Output parameter for the response
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool get(const std::string& url, std::string& response);
|
||||
|
||||
/**
|
||||
* Performs an HTTP POST request
|
||||
*
|
||||
* @param url The URL to request
|
||||
* @param data The data to send
|
||||
* @param response Output parameter for the response
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool post(const std::string& url, const std::string& data,
|
||||
std::string& response);
|
||||
|
||||
/**
|
||||
* Performs an HTTP DELETE request
|
||||
*
|
||||
* @param url The URL to request
|
||||
* @param data The data to send
|
||||
* @param response Output parameter for the response
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool delete_req(const std::string& url, const std::string& data,
|
||||
std::string& response);
|
||||
|
||||
private:
|
||||
#ifdef WINDOWS
|
||||
// Windows-specific implementation details
|
||||
#elif LINUX
|
||||
// Linux-specific implementation details
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // HTTP_CLIENT_H
|
||||
71
include/json_parser.h
Normal file
71
include/json_parser.h
Normal file
@ -0,0 +1,71 @@
|
||||
#ifndef JSON_PARSER_H
|
||||
#define JSON_PARSER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
class JsonParser {
|
||||
public:
|
||||
/**
|
||||
* Creates a paste JSON structure
|
||||
*
|
||||
* @param cipher_text The encrypted text
|
||||
* @param auth_tag The authentication tag
|
||||
* @param iv The initialization vector
|
||||
* @param salt The salt used for key derivation
|
||||
* @param expiration The expiration time
|
||||
* @param format The format of the paste
|
||||
* @param burn_after_reading Whether to burn after reading
|
||||
* @param open_discussion Whether to enable discussion
|
||||
* @return The JSON structure
|
||||
*/
|
||||
static json create_paste_json(const std::vector<unsigned char>& cipher_text,
|
||||
const std::vector<unsigned char>& auth_tag,
|
||||
const std::vector<unsigned char>& iv,
|
||||
const std::vector<unsigned char>& salt,
|
||||
const std::string& expiration,
|
||||
const std::string& format,
|
||||
bool burn_after_reading,
|
||||
bool open_discussion);
|
||||
|
||||
/**
|
||||
* Parses a paste JSON structure
|
||||
*
|
||||
* @param json_data The JSON data to parse
|
||||
* @param cipher_text Output parameter for the encrypted text
|
||||
* @param auth_tag Output parameter for the authentication tag
|
||||
* @param iv Output parameter for the initialization vector
|
||||
* @param salt Output parameter for the salt
|
||||
* @param expiration Output parameter for the expiration time
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
static bool parse_paste_json(const json& json_data,
|
||||
std::vector<unsigned char>& cipher_text,
|
||||
std::vector<unsigned char>& auth_tag,
|
||||
std::vector<unsigned char>& iv,
|
||||
std::vector<unsigned char>& salt,
|
||||
std::string& expiration);
|
||||
|
||||
/**
|
||||
* Parses a response JSON structure
|
||||
*
|
||||
* @param response The response string to parse
|
||||
* @param status Output parameter for the status
|
||||
* @param message Output parameter for the message (if error)
|
||||
* @param paste_id Output parameter for the paste ID (if success)
|
||||
* @param url Output parameter for the URL (if success)
|
||||
* @param delete_token Output parameter for the delete token (if success)
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
static bool parse_response(const std::string& response,
|
||||
int& status,
|
||||
std::string& message,
|
||||
std::string& paste_id,
|
||||
std::string& url,
|
||||
std::string& delete_token);
|
||||
};
|
||||
|
||||
#endif // JSON_PARSER_H
|
||||
72
include/privatebinapi.h
Normal file
72
include/privatebinapi.h
Normal file
@ -0,0 +1,72 @@
|
||||
#ifndef PRIVATEBIN_API_H
|
||||
#define PRIVATEBIN_API_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef PRIVATEBINAPI_EXPORTS
|
||||
#define PRIVATEBIN_API __declspec(dllexport)
|
||||
#else
|
||||
#define PRIVATEBIN_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define PRIVATEBIN_API
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Creates a new paste on a PrivateBin server
|
||||
*
|
||||
* @param server_url The URL of the PrivateBin server
|
||||
* @param content The content to paste
|
||||
* @param password Optional password for the paste (can be NULL)
|
||||
* @param expiration Expiration time ("5min", "10min", "1hour", "1day", "1week", "1month", "1year", "never")
|
||||
* @param format Format of the paste ("plaintext", "syntaxhighlighting", "markdown")
|
||||
* @param burn_after_reading Set to 1 to enable burn after reading, 0 to disable
|
||||
* @param open_discussion Set to 1 to enable discussion, 0 to disable
|
||||
* @param paste_url Output parameter for the URL of the created paste
|
||||
* @param delete_token Output parameter for the deletion token
|
||||
* @return 0 on success, error code on failure
|
||||
*/
|
||||
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,
|
||||
char** delete_token);
|
||||
|
||||
/**
|
||||
* Retrieves a paste from a PrivateBin server
|
||||
*
|
||||
* @param server_url The URL of the PrivateBin server
|
||||
* @param paste_id The ID of the paste to retrieve
|
||||
* @param key The decryption key for the paste
|
||||
* @param content Output parameter for the content of the paste
|
||||
* @return 0 on success, error code on failure
|
||||
*/
|
||||
PRIVATEBIN_API int get_paste(const char* server_url, const char* paste_id,
|
||||
const char* key, char** content);
|
||||
|
||||
/**
|
||||
* Deletes a paste from a PrivateBin server
|
||||
*
|
||||
* @param server_url The URL of the PrivateBin server
|
||||
* @param paste_id The ID of the paste to delete
|
||||
* @param delete_token The deletion token for the paste
|
||||
* @return 0 on success, error code on failure
|
||||
*/
|
||||
PRIVATEBIN_API int delete_paste(const char* server_url, const char* paste_id,
|
||||
const char* delete_token);
|
||||
|
||||
/**
|
||||
* Frees memory allocated by the API functions
|
||||
*
|
||||
* @param str The string to free
|
||||
*/
|
||||
PRIVATEBIN_API void free_string(char* str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // PRIVATEBIN_API_H
|
||||
Reference in New Issue
Block a user