Skip to content

Commit e7eed21

Browse files
committed
Made blinded_contact_info implementation details private, handle invalid case
1 parent f7e4fbf commit e7eed21

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

include/session/config/contacts.hpp

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ struct contact_info {
119119
};
120120

121121
struct blinded_contact_info {
122-
community comm;
123-
124122
const std::string session_id() const; // in hex
125123
std::string name;
126124
profile_pic profile_picture;
@@ -153,17 +151,51 @@ struct blinded_contact_info {
153151
/// - `name` -- Name to assign to the contact
154152
void set_name(std::string name);
155153

154+
/// API: contacts/blinded_contact_info::community_base_url
155+
///
156+
/// Accesses the base url for the community (i.e. not including room or pubkey). Always
157+
/// lower-case/normalized.
158+
///
159+
/// Inputs: None
160+
///
161+
/// Outputs:
162+
/// - `const std::string&` -- Returns the base url
163+
const std::string& community_base_url() const { return comm.base_url(); }
164+
165+
/// API: contacts/blinded_contact_info::community_pubkey
166+
///
167+
/// Accesses the community server pubkey (32 bytes).
168+
///
169+
/// Inputs: None
170+
///
171+
/// Outputs:
172+
/// - `const std::vector<unsigned char>&` -- Returns the pubkey
173+
const std::vector<unsigned char>& community_pubkey() const { return comm.pubkey(); }
174+
175+
/// API: contacts/blinded_contact_info::community_pubkey_hex
176+
///
177+
/// Accesses the community server pubkey as hex (64 hex digits).
178+
///
179+
/// Inputs: None
180+
///
181+
/// Outputs:
182+
/// - `std::string` -- Returns the pubkey
183+
std::string community_pubkey_hex() const { return comm.pubkey_hex(); }
184+
185+
private:
186+
friend class Contacts;
187+
friend struct session::config::comm_iterator_helper;
188+
189+
community comm;
190+
191+
void load(const dict& info_dict);
192+
156193
/// These functions are here so we can use the `comm_iterator_helper` for loading data
157194
/// into this struct
158195
void set_base_url(std::string_view base_url);
159196
void set_room(std::string_view room);
160197
void set_pubkey(std::span<const unsigned char> pubkey);
161198
void set_pubkey(std::string_view pubkey);
162-
163-
private:
164-
friend class Contacts;
165-
friend struct session::config::comm_iterator_helper;
166-
void load(const dict& info_dict);
167199
};
168200

169201
class Contacts : public ConfigBase {

src/config/contacts.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ void blinded_contact_info::set_base_url(std::string_view base_url) {
383383
}
384384

385385
void blinded_contact_info::set_room(std::string_view room) {
386+
if (room.size() != 64 || !oxenc::is_hex(room))
387+
throw std::invalid_argument{
388+
fmt::format("Invalid room: expected 64 hex digits; got {}", room)};
389+
386390
comm.set_room(room);
387391
}
388392

0 commit comments

Comments
 (0)