You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
2.3 KiB

// Copyright (C) 2024 Simon Quigley <tsimonq2@ubuntu.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licens.
#ifndef UTILS_H
#define UTILS_H
#include <string>
#include <map>
#include <optional>
#include <curl/curl.h>
#include <nlohmann/json.hpp>
size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp);
std::string url_encode(const std::string& value);
std::string url_decode(const std::string& value);
std::string compute_hmac_sha1(const std::string& key, const std::string& data);
std::string generate_nonce();
std::string generate_timestamp();
std::string build_oauth_header_impl(const std::string& consumer_key,
const std::string& oauth_token,
const std::string& oauth_token_secret,
const std::string& http_method,
const std::string& url,
const std::map<std::string, std::string>& additional_params);
std::optional<std::string> get_secret(const std::string& schema,
const std::string& attribute,
const std::string& value);
std::string base64_encode(const unsigned char* data, size_t len);
std::string base64_decode(const std::string& encoded_string);
std::map<std::string, std::string> parse_response(const std::string& response, std::map<std::string, std::string>& params);
bool open_url_impl(const std::string& url);
std::string encode_service_identifier(const std::string& identifier);
std::string decode_service_identifier(const std::string& encoded);
extern const std::string PLAINTEXT_CREDENTIALS_FILE;
#endif // UTILS_H