mirror of
https://github.com/lux-tel/libsession-util.git
synced 2026-10-30 20:25:11 +00:00
- Generic cpp/c api docs into different directories so that you can generate both at once without trampling one or the other. - `make` with no args now does both by default. - Combine doc-building CI jobs into one job that builds and then uploads both at once. - Move CI-specific upload script into `/utils/ci` - Remove most `Declaration:` sections: if no such section is found, we now scrape the source code for the code immediately following the comment and use that. Declaration: is now only used where that isn't the same, or where it has multiple declarations in one. - Remove most of the C++ Declaration:s (the C ones seem different enough from the actual code items). - Make `Outputs:` optional and remove all the superflous `void` output descriptions.
74 lines
2.1 KiB
C++
74 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <stdexcept>
|
|
|
|
#include "session/types.hpp"
|
|
|
|
namespace session::config {
|
|
|
|
// Profile pic info.
|
|
struct profile_pic {
|
|
static constexpr size_t MAX_URL_LENGTH = 223;
|
|
|
|
std::string url;
|
|
ustring key;
|
|
|
|
static void check_key(ustring_view key) {
|
|
if (!(key.empty() || key.size() == 32))
|
|
throw std::invalid_argument{"Invalid profile pic key: 32 bytes required"};
|
|
}
|
|
|
|
// Default constructor, makes an empty profile pic
|
|
profile_pic() = default;
|
|
|
|
// Constructs from a URL and key. Key must be empty or 32 bytes.
|
|
profile_pic(std::string_view url, ustring_view key) : url{url}, key{key} {
|
|
check_key(this->key);
|
|
}
|
|
|
|
// Constructs from a string/ustring pair moved into the constructor
|
|
profile_pic(std::string&& url, ustring&& key) : url{std::move(url)}, key{std::move(key)} {
|
|
check_key(this->key);
|
|
}
|
|
|
|
/// API: profile_pic/profile_pic::empty
|
|
///
|
|
/// Returns true if either url or key are empty (or invalid)
|
|
///
|
|
/// Inputs: None
|
|
///
|
|
/// Outputs:
|
|
/// - `bool` -- Returns true if either url or key are empty
|
|
bool empty() const { return url.empty() || key.size() != 32; }
|
|
|
|
/// API: profile_pic/profile_pic::clear
|
|
///
|
|
/// Clears the current url/key, if set. This is just a shortcut for calling `.clear()` on each
|
|
/// of them.
|
|
///
|
|
/// Inputs: None
|
|
void clear() {
|
|
url.clear();
|
|
key.clear();
|
|
}
|
|
|
|
// The object in boolean context is true if url and key are both set, i.e. the opposite of
|
|
// `empty()`.
|
|
explicit operator bool() const { return !empty(); }
|
|
|
|
/// API: profile_pic/profile_pic::set_key
|
|
///
|
|
/// Sets and validates the key. The key can be empty, or 32 bytes. This is almost the same as
|
|
/// just setting `.key` directly, except that it will throw if the provided key is invalid (i.e.
|
|
/// neither empty nor 32 bytes).
|
|
///
|
|
/// Inputs:
|
|
/// - `new_key` -- binary data of a new key to be set. Must be 32 bytes
|
|
void set_key(ustring new_key) {
|
|
check_key(new_key);
|
|
key = std::move(new_key);
|
|
}
|
|
};
|
|
|
|
} // namespace session::config
|