71 lines
2.8 KiB
C++
71 lines
2.8 KiB
C++
#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
|