Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various minor fixes (mostly comments) #64

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
4 changes: 2 additions & 2 deletions include/session/config/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ typedef struct config_string_list {
/// API: base/config_merge
///
/// Merges the config object with one or more remotely obtained config strings. After this call the
/// config object may be unchanged, complete replaced, or updated and needing a push, depending on
/// config object may be unchanged, completely replaced, or updated and needing a push, depending on
/// the messages that are merged; the caller should check config_needs_push().
///
/// Declaration:
Expand Down Expand Up @@ -309,7 +309,7 @@ LIBSESSION_EXPORT config_string_list* config_current_hashes(const config_object*
/// Inputs:
/// - `conf` -- [in] Pointer to the config_object object
/// - `len` -- [out] Pointer where the number of keys will be written (that is: the returned pointer
/// will be to a buffer which has a size of of this value times 32).
/// will be to a buffer which has a size of this value times 32).
///
/// Outputs:
/// - `unsigned char*` -- pointer to newly malloced key data (a multiple of 32 bytes); the pointer
Expand Down
2 changes: 1 addition & 1 deletion include/session/config/contacts.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ LIBSESSION_EXPORT void contacts_set(config_object* conf, const contacts_contact*
// contacts_contact c;
// if (contacts_get_or_construct(conf, &c, some_session_id)) {
// const char* new_nickname = "Joe";
// c.approved = new_nickname;
// c.nickname = new_nickname;
// contacts_set_or_create(conf, &c);
// } else {
// // some_session_id was invalid!
Expand Down
2 changes: 1 addition & 1 deletion include/session/config/encrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern "C" {
/// ```
///
/// Inputs:
/// - `message` -- [in] The message to encrypted in binary
/// - `message` -- [in] The message to encrypt in binary
/// - `mlen` -- [in] Length of the message provided
/// - `key_base` -- [in] Key, must be binary
/// - `domain` -- [in] Text
Expand Down
4 changes: 2 additions & 2 deletions include/session/config/encrypt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace session::config {
///
/// Inputs:
/// - `message` -- message to encrypt
/// - `key_base` -- Fixed key that all clients, must be 32 bytes.
/// - `key_base` -- Fixed key that all clients can calculate independently, must be 32 bytes.
/// - `domain` -- short string for the keyed hash
///
/// Outputs:
Expand All @@ -43,7 +43,7 @@ ustring encrypt(ustring_view message, ustring_view key_base, std::string_view do
///
/// Inputs:
/// - `message` -- message to encrypt
/// - `key_base` -- Fixed key that all clients, must be 32 bytes.
/// - `key_base` -- Fixed key that all clients can calculate independently, must be 32 bytes.
/// - `domain` -- short string for the keyed hash
void encrypt_inplace(ustring& message, ustring_view key_base, std::string_view domain);

Expand Down
5 changes: 2 additions & 3 deletions include/session/config/groups/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ extern "C" {

#include "../base.h"
#include "../profile_pic.h"
#include "../util.h"

LIBSESSION_EXPORT extern const size_t GROUP_INFO_NAME_MAX_LENGTH;
LIBSESSION_EXPORT extern const size_t GROUP_INFO_DESCRIPTION_MAX_LENGTH;
Expand Down Expand Up @@ -116,7 +115,7 @@ LIBSESSION_EXPORT user_profile_pic groups_info_get_pic(const config_object* conf

/// API: groups_info/groups_info_set_pic
///
/// Sets a user profile
/// Sets a profile picture
///
/// Inputs:
/// - `conf` -- [in] Pointer to the config object
Expand Down Expand Up @@ -199,7 +198,7 @@ LIBSESSION_EXPORT void groups_info_set_delete_before(config_object* conf, int64_
/// - `conf` -- [in] Pointer to the config object
///
/// Outputs:
/// - `int64_t` -- Unix timestamp before which messages should be deleted. Returns 0 if not set.
/// - `int64_t` -- Unix timestamp before which attachments should be deleted. Returns 0 if not set.
LIBSESSION_EXPORT int64_t groups_info_get_attach_delete_before(const config_object* conf);

/// API: groups_info/groups_info_set_attach_delete_before
Expand Down
7 changes: 4 additions & 3 deletions include/session/config/groups/info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class Info final : public ConfigBase {
/// Inputs: none.
///
/// Outputs:
/// - `int64_t` -- the unix timestamp for which all older messages shall be delete
/// - `int64_t` -- the unix timestamp for which all older messages shall be deleted
std::optional<int64_t> get_delete_before() const;

/// API: groups/Info::set_delete_attach_before
Expand All @@ -254,13 +254,14 @@ class Info final : public ConfigBase {
/// Inputs:
/// - `timestamp` -- the new unix timestamp before which clients should delete attachments. Pass
/// 0
/// (or negative) to disable the delete-attachment-before timestamp.
/// (or negative) to disable the delete-attachments-before timestamp.
void set_delete_attach_before(int64_t timestamp);

/// API: groups/Info::get_delete_attach_before
///
/// Returns the delete-attachments-before unix timestamp (seconds) for the group; clients should
/// delete all messages from the closed group with timestamps earlier than this value, if set.
/// delete all attachments from the closed group with timestamps earlier than this value, if
/// set.
///
/// Returns std::nullopt if no delete-attachments-before timestamp is set.
///
Expand Down
2 changes: 1 addition & 1 deletion include/session/config/groups/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ LIBSESSION_EXPORT const unsigned char* groups_keys_get_key(const config_group_ke
/// API: groups/groups_keys_is_admin
///
/// Returns true if this object has the group private keys, i.e. the user is an all-powerful
/// wiz^H^H^Hadmin of the group.
/// admin of the group.
///
/// Inputs:
/// - `conf` -- the groups config object
Expand Down
21 changes: 11 additions & 10 deletions include/session/config/groups/keys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "../../config.hpp"
#include "../base.hpp"
#include "../namespaces.hpp"
#include "../profile_pic.hpp"
#include "members.hpp"

namespace session::config::groups {
Expand Down Expand Up @@ -120,7 +119,7 @@ class Keys final : public ConfigSig {
// Inserts a key into the correct place in `keys_`.
void insert_key(std::string_view message_hash, key_info&& key);

// Returned the blinding factor for a given session X25519 pubkey. This depends on the group's
// Returns the blinding factor for a given session X25519 pubkey. This depends on the group's
// seed and thus is only obtainable by an admin account.
std::array<unsigned char, 32> subaccount_blind_factor(
const std::array<unsigned char, 32>& session_xpk) const;
Expand All @@ -134,7 +133,7 @@ class Keys final : public ConfigSig {

// 75 because:
// 2 // for the 'de' delimiters of the outer dict
// + 3 + 2 + 12 // for the `1:g` and `iNNNNNNNNNNe` generation keypair
// + 3 + 2 + 12 // for the `1:G` and `iNNNNNNNNNNe` generation keypair
// + 3 + 3 + 24 // for the `1:n`, `24:`, and 24 byte nonce
// + 3 + 3 + 48 // for the `1:K`, `48:`, and 48 byte ciphertexted key
// + 3 + 6 // for the `1:k` and `NNNNN:` key and prefix of the keys pair
Expand All @@ -158,19 +157,21 @@ class Keys final : public ConfigSig {

/// API: groups/Keys::Keys
///
/// Constructs a group members config object from existing data (stored from `dump()`) and a
/// Constructs a group keys config object from existing data (stored from `dump()`) and a
/// list of encryption keys for encrypting new and decrypting existing messages.
///
/// To construct a blank info object (i.e. with no pre-existing dumped data to load) pass
/// To construct a blank keys object (i.e. with no pre-existing dumped data to load) pass
/// `std::nullopt` as the last argument.
///
/// Inputs:
/// - `user_ed25519_secretkey` is the ed25519 secret key backing the current user's session ID,
/// and is used to decrypt incoming keys. It is required.
/// - `group_ed25519_pubkey` is the public key of the group, used to verify message signatures
/// on key updates. Required. Should not include the `03` prefix.
/// - `group_ed25519_secretkey` is the secret key of the group, used to encrypt, decrypt, and
/// sign config messages. This is only possessed by the group admin(s), and must be provided
/// - `group_ed25519_secretkey` is the secret key of the group, used to sign config messages and
/// swarm authentication tokens and to encrypt and decrypt encryption keys for regular
/// messages.
/// This is only possessed by the group admin(s), and must be provided
/// in order to make and push config changes.
/// - `dumped` -- either `std::nullopt` to construct a new, empty object; or binary state data
/// that was previously dumped from an instance of this class by calling `dump()`.
Expand Down Expand Up @@ -322,7 +323,7 @@ class Keys final : public ConfigSig {
///
/// Generates a supplemental key message for one or more session IDs. This is used to
/// distribute existing active keys to a new member so that that member can access existing
/// keys, configs, and messages. Only admins can call this.
/// configs and messages. Only admins can call this.
///
/// The recommended order of operations for adding such a member is:
/// - add the member to Members
Expand Down Expand Up @@ -374,7 +375,7 @@ class Keys final : public ConfigSig {
/// (Internally this packs the flags, blinding factor, and group admin signature together and
/// will be 4 + 32 + 64 = 100 bytes long).
///
/// This value must be provided to the user so that they can authentication. The user should
/// This value must be provided to the user so that they can authenticate. The user should
/// call `swarm_verify_subaccount` to verify that the signing value was indeed signed by a
/// group admin before using/storing it.
///
Expand Down Expand Up @@ -579,7 +580,7 @@ class Keys final : public ConfigSig {
/// call rekey()). Note that this value will also remain true until the pushed data is fetched
/// and loaded via `load_key_message`.
///
/// Note that this not only tracks when an automatic `rekey()` is needed because of a key
/// Note that this only tracks when an automatic `rekey()` is needed because of a key
/// collision (such as two admins removing different members at the same time); there are other
/// situations in which rekey() should also be called (such as when kicking a member) that are
/// not reflected by this flag.
Expand Down
9 changes: 5 additions & 4 deletions include/session/config/groups/members.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ enum groups_members_remove_status { REMOVED_MEMBER = 1, REMOVED_MEMBER_AND_MESSA
typedef struct config_group_member {
char session_id[67]; // in hex; 66 hex chars + null terminator.

// These two will be 0-length strings when unset:
// This will be a 0-length string when unset:
char name[101];

user_profile_pic profile_pic;

bool admin;
Expand Down Expand Up @@ -131,7 +132,7 @@ LIBSESSION_EXPORT bool groups_members_erase(config_object* conf, const char* ses
/// - `conf` -- input - Pointer to the config object
///
/// Outputs:
/// - `size_t` -- number of contacts
/// - `size_t` -- number of members
LIBSESSION_EXPORT size_t groups_members_size(const config_object* conf);

typedef struct groups_members_iterator {
Expand All @@ -146,8 +147,8 @@ typedef struct groups_members_iterator {
///
/// group_member m;
/// groups_members_iterator *it = groups_members_iterator_new(group);
/// for (; !groups_members_iterator_done(it, &c); groups_members_iterator_advance(it)) {
/// // c.session_id, c.name, etc. are loaded
/// for (; !groups_members_iterator_done(it, &m); groups_members_iterator_advance(it)) {
/// // m.session_id, m.name, etc. are loaded
/// }
/// groups_members_iterator_free(it);
///
Expand Down
18 changes: 10 additions & 8 deletions include/session/config/groups/members.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct member {
/// that the invitation should be reissued).
///
/// Inputs:
/// - `failed` can be specified and set to `true` to the invite status to "failed-to-send";
/// - `failed` can be specified and set to `true` to set the invite status to "failed-to-send";
/// otherwise omitting it or giving as `false` sets the invite status to "sent."
void set_invited(bool failed = false) { invite_status = failed ? INVITE_FAILED : INVITE_SENT; }

Expand Down Expand Up @@ -276,11 +276,12 @@ class Members final : public ConfigBase {
/// Constructs a group members config object from existing data (stored from `dump()`) and a
/// list of encryption keys for encrypting new and decrypting existing messages.
///
/// To construct a blank info object (i.e. with no pre-existing dumped data to load) pass
/// To construct a blank members object (i.e. with no pre-existing dumped data to load) pass
/// `std::nullopt` as the third argument.
///
/// Encryption keys must be loaded before the Info object can be modified or parse other Info
/// messages, and are typically loaded by providing the `Info` object to the `Keys` class.
/// Encryption keys must be loaded before the Members object can be modified or parse other
/// Members messages, and are typically loaded by providing the `Members` object to the `Keys`
/// class.
///
/// Inputs:
/// - `ed25519_pubkey` is the public key of this group, used to validate config messages.
Expand Down Expand Up @@ -371,13 +372,14 @@ class Members final : public ConfigBase {
/// removed |= members.erase("050000111122223333...");
///
/// if (removed) {
/// auto new_keys_conf = keys.rekey(members);
/// members.add_key(*keys.pending_key(), true);
/// auto [seqno, new_memb_conf, obs] = members.push();
/// auto new_keys_conf = keys.rekey(info, members);
/// auto [members_seqno, new_memb_conf, members_obs] = members.push();
/// auto [info_seqno, new_info_conf, info_obs] = info.push();
///
/// // Send the two new configs to the swarm (via a seqence of two `store`s):
/// // Send the three new configs to the swarm (via a sequence of three `store`s):
/// // - new_keys_conf goes into the keys namespace
/// // - new_memb_conf goes into the members namespace
/// // - new_info_conf goes into the info namespace
/// }
///
/// Inputs:
Expand Down
6 changes: 3 additions & 3 deletions include/session/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct sodium_ptr {
public:
sodium_ptr() : x{nullptr} {}
sodium_ptr(std::nullptr_t) : sodium_ptr{} {}
~sodium_ptr() { reset(x); }
~sodium_ptr() { reset(); }

// Allocates and constructs a new `T` in-place, forwarding any given arguments to the `T`
// constructor. If this sodium_ptr already has an object, `reset()` is first called implicitly
Expand Down Expand Up @@ -214,7 +214,7 @@ struct sodium_array {
}

// Loads the array from a pointer and size; this first resets a value (if present), allocates a
// new array of the given size, the copies the given value(s) into the new buffer. T must be
// new array of the given size, then copies the given value(s) into the new buffer. T must be
// copyable. This is *not* safe to use if `buf` points into the currently allocated data.
template <typename = std::enable_if_t<std::is_copy_constructible_v<T>>>
void load(const T* data, size_t length) {
Expand All @@ -225,7 +225,7 @@ struct sodium_array {
if constexpr (std::is_trivially_copyable_v<T>)
std::memcpy(buf, data, sizeof(T) * length);
else
for (; len < length; len++)
for (len = 0; len < length; len++)
new (buf[len]) T(data[len]);
}

Expand Down
4 changes: 2 additions & 2 deletions include/session/xed25519.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <string>
#include <string_view>

namespace session::xed25519 {
#include "session/types.hpp"

using ustring_view = std::basic_string_view<unsigned char>;
namespace session::xed25519 {

/// XEd25519-signs a message given the curve25519 privkey and message.
std::array<unsigned char, 64> sign(
Expand Down
1 change: 0 additions & 1 deletion src/config/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ ustring ConfigBase::dump() {
ustring ConfigBase::make_dump() const {
auto data = _config->serialize(false /* disable signing for local storage */);
auto data_sv = from_unsigned_sv(data);
oxenc::bt_list old_hashes;

oxenc::bt_dict_producer d;
d.append("!", static_cast<int>(_state));
Expand Down
2 changes: 0 additions & 2 deletions src/config/contacts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

#include "internal.hpp"
#include "session/config/contacts.h"
#include "session/config/error.h"
#include "session/export.h"
#include "session/types.hpp"
#include "session/util.hpp"

using namespace std::literals;
using namespace session::config;
Expand Down
3 changes: 1 addition & 2 deletions src/config/groups/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "session/config/groups/info.h"
#include "session/export.h"
#include "session/types.hpp"
#include "session/util.hpp"

using namespace std::literals;

Expand Down Expand Up @@ -344,7 +343,7 @@ LIBSESSION_C_API void groups_info_set_delete_before(config_object* conf, int64_t
/// - `conf` -- [in] Pointer to the config object
///
/// Outputs:
/// - `int64_t` -- Unix timestamp before which messages should be deleted. Returns 0 if not set.
/// - `int64_t` -- Unix timestamp before which attachments should be deleted. Returns 0 if not set.
LIBSESSION_C_API int64_t groups_info_get_attach_delete_before(const config_object* conf) {
return unbox<groups::Info>(conf)->get_delete_attach_before().value_or(0);
}
Expand Down