Skip to content

Commit 38bb785

Browse files
committed
chore: fix build for clangd
1 parent 61e0d1a commit 38bb785

File tree

14 files changed

+1077
-1041
lines changed

14 files changed

+1077
-1041
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ set(ENABLE_ONIONREQ OFF)
3737
# as it is not part of the archive. We actually don't care about it on session-desktop
3838
set(SUBMODULE_CHECK OFF)
3939

40-
file(GLOB SOURCE_FILES src/*.cpp src/groups/*.cpp )
40+
file(GLOB SOURCE_FILES src/*.cpp src/groups/*.cpp src/encrypt_decrypt/*.cpp src/pro/*.cpp src/meta/*.cpp )
4141

4242
add_subdirectory(libsession-util)
4343

include/base_config.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
#include <cassert>
77
#include <memory>
88
#include <oxen/log.hpp>
9-
#include <span>
109
#include <stdexcept>
1110
#include <unordered_set>
1211

1312
#include "session/config/base.hpp"
14-
#include "session/logging.hpp"
15-
#include "session/types.hpp"
1613
#include "utilities.hpp"
1714

1815
namespace session::nodeapi {
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#pragma once
2+
3+
#include <napi.h>
4+
#include <oxenc/base64.h>
5+
#include <oxenc/hex.h>
6+
7+
#include "meta/meta_base_wrapper.hpp"
8+
9+
namespace session::nodeapi {
10+
11+
class MultiEncryptWrapper : public Napi::ObjectWrap<MultiEncryptWrapper> {
12+
public:
13+
MultiEncryptWrapper(const Napi::CallbackInfo& info) :
14+
Napi::ObjectWrap<MultiEncryptWrapper>{info} {
15+
throw std::invalid_argument(
16+
"MultiEncryptWrapper is static and doesn't need to be constructed");
17+
}
18+
19+
static void Init(Napi::Env env, Napi::Object exports) {
20+
MetaBaseWrapper::NoBaseClassInitHelper<MultiEncryptWrapper>(
21+
env,
22+
exports,
23+
"MultiEncryptWrapperNode",
24+
{
25+
StaticMethod<&MultiEncryptWrapper::multiEncrypt>(
26+
"multiEncrypt",
27+
static_cast<napi_property_attributes>(
28+
napi_writable | napi_configurable)),
29+
StaticMethod<&MultiEncryptWrapper::multiDecryptEd25519>(
30+
"multiDecryptEd25519",
31+
static_cast<napi_property_attributes>(
32+
napi_writable | napi_configurable)),
33+
// Attachments encrypt/decrypt
34+
StaticMethod<&MultiEncryptWrapper::attachmentDecrypt>(
35+
"attachmentDecrypt",
36+
static_cast<napi_property_attributes>(
37+
napi_writable | napi_configurable)),
38+
StaticMethod<&MultiEncryptWrapper::attachmentEncrypt>(
39+
"attachmentEncrypt",
40+
static_cast<napi_property_attributes>(
41+
napi_writable | napi_configurable)),
42+
43+
// Destination encrypt
44+
StaticMethod<&MultiEncryptWrapper::encryptFor1o1>(
45+
"encryptFor1o1",
46+
static_cast<napi_property_attributes>(
47+
napi_writable | napi_configurable)),
48+
49+
StaticMethod<&MultiEncryptWrapper::encryptForCommunity>(
50+
"encryptForCommunity",
51+
static_cast<napi_property_attributes>(
52+
napi_writable | napi_configurable)),
53+
StaticMethod<&MultiEncryptWrapper::encryptForCommunityInbox>(
54+
"encryptForCommunityInbox",
55+
static_cast<napi_property_attributes>(
56+
napi_writable | napi_configurable)),
57+
StaticMethod<&MultiEncryptWrapper::encryptForGroup>(
58+
"encryptForGroup",
59+
static_cast<napi_property_attributes>(
60+
napi_writable | napi_configurable)),
61+
62+
// Destination decrypt
63+
StaticMethod<&MultiEncryptWrapper::decryptForCommunity>(
64+
"decryptForCommunity",
65+
static_cast<napi_property_attributes>(
66+
napi_writable | napi_configurable)),
67+
StaticMethod<&MultiEncryptWrapper::decryptFor1o1>(
68+
"decryptFor1o1",
69+
static_cast<napi_property_attributes>(
70+
napi_writable | napi_configurable)),
71+
StaticMethod<&MultiEncryptWrapper::decryptForGroup>(
72+
"decryptForGroup",
73+
static_cast<napi_property_attributes>(
74+
napi_writable | napi_configurable)),
75+
});
76+
}
77+
78+
private:
79+
static Napi::Value multiEncrypt(const Napi::CallbackInfo& info);
80+
static Napi::Value multiDecryptEd25519(const Napi::CallbackInfo& info);
81+
82+
/**
83+
* ===========================================
84+
* =========== ATTACHMENTS CALLS =============
85+
* ===========================================
86+
*/
87+
88+
static Napi::Value attachmentEncrypt(const Napi::CallbackInfo& info);
89+
static Napi::Value attachmentDecrypt(const Napi::CallbackInfo& info);
90+
91+
/**
92+
* ===========================================
93+
* ============= ENCRYPT CALLS ===============
94+
* ===========================================
95+
*/
96+
97+
static Napi::Value encryptFor1o1(const Napi::CallbackInfo& info);
98+
static Napi::Value encryptForCommunityInbox(const Napi::CallbackInfo& info);
99+
static Napi::Value encryptForCommunity(const Napi::CallbackInfo& info);
100+
static Napi::Value encryptForGroup(const Napi::CallbackInfo& info);
101+
/**
102+
* ===========================================
103+
* ============= DECRYPT CALLS ===============
104+
* ===========================================
105+
*/
106+
107+
static Napi::Value decryptForCommunity(const Napi::CallbackInfo& info);
108+
static Napi::Value decryptFor1o1(const Napi::CallbackInfo& info);
109+
static Napi::Value decryptForGroup(const Napi::CallbackInfo& info);
110+
};
111+
}; // namespace session::nodeapi

include/meta/meta_base_wrapper.hpp

Lines changed: 4 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
#include <napi.h>
44

5-
#include <optional>
5+
#include <memory>
66
#include <vector>
77

88
#include "../base_config.hpp"
9-
#include "../groups/meta_group.hpp"
9+
#include "groups/meta_group.hpp"
10+
1011
namespace session::nodeapi {
1112

1213
class MetaBaseWrapper {
@@ -34,86 +35,7 @@ class MetaBaseWrapper {
3435
}
3536

3637
static std::unique_ptr<session::nodeapi::MetaGroup> constructGroupWrapper(
37-
const Napi::CallbackInfo& info, const std::string& class_name) {
38-
return wrapExceptions(info, [&] {
39-
if (!info.IsConstructCall())
40-
throw std::invalid_argument{
41-
"You need to call the constructor with the `new` syntax"};
42-
43-
assertInfoLength(info, 1);
44-
auto arg = info[0];
45-
assertIsObject(arg);
46-
auto obj = arg.As<Napi::Object>();
47-
48-
if (obj.IsEmpty())
49-
throw std::invalid_argument("constructGroupWrapper received empty");
50-
51-
assertIsUInt8Array(obj.Get("userEd25519Secretkey"), "constructGroupWrapper userEd");
52-
auto user_ed25519_secretkey = toCppBuffer(
53-
obj.Get("userEd25519Secretkey"),
54-
class_name + ":constructGroupWrapper.userEd25519Secretkey");
55-
56-
assertIsUInt8Array(obj.Get("groupEd25519Pubkey"), "constructGroupWrapper groupEd");
57-
auto group_ed25519_pubkey = toCppBuffer(
58-
obj.Get("groupEd25519Pubkey"),
59-
class_name + ":constructGroupWrapper.groupEd25519Pubkey");
60-
61-
std::optional<std::vector<unsigned char>> group_ed25519_secretkey = maybeNonemptyBuffer(
62-
obj.Get("groupEd25519Secretkey"),
63-
class_name + ":constructGroupWrapper.groupEd25519Secretkey");
64-
65-
std::optional<std::vector<unsigned char>> dumped_meta = maybeNonemptyBuffer(
66-
obj.Get("metaDumped"), class_name + ":constructGroupWrapper.metaDumped");
67-
68-
std::optional<std::string> dumped_info;
69-
std::optional<std::string> dumped_members;
70-
std::optional<std::string> dumped_keys;
71-
72-
if (dumped_meta) {
73-
auto dumped_meta_str = to_string(*dumped_meta);
74-
75-
oxenc::bt_dict_consumer combined{dumped_meta_str};
76-
// NB: must read in ascii-sorted order:
77-
if (!combined.skip_until("info"))
78-
throw std::runtime_error{"info dump not found in combined dump!"};
79-
dumped_info = combined.consume_string();
80-
81-
if (!combined.skip_until("keys"))
82-
throw std::runtime_error{"keys dump not found in combined dump!"};
83-
dumped_keys = combined.consume_string();
84-
85-
if (!combined.skip_until("members"))
86-
throw std::runtime_error{"members dump not found in combined dump!"};
87-
dumped_members = combined.consume_string();
88-
}
89-
90-
// Note, we keep shared_ptr for those as the Keys one need a reference to Members and
91-
// Info on its own currently.
92-
auto info = std::make_shared<config::groups::Info>(
93-
group_ed25519_pubkey,
94-
group_ed25519_secretkey,
95-
(dumped_info ? std::make_optional(session::to_span(*dumped_info))
96-
: std::nullopt));
97-
98-
auto members = std::make_shared<config::groups::Members>(
99-
group_ed25519_pubkey,
100-
group_ed25519_secretkey,
101-
(dumped_members ? std::make_optional(session::to_span(*dumped_members))
102-
: std::nullopt));
103-
104-
auto keys = std::make_shared<config::groups::Keys>(
105-
user_ed25519_secretkey,
106-
group_ed25519_pubkey,
107-
group_ed25519_secretkey,
108-
(dumped_keys ? std::make_optional(session::to_span(*dumped_keys))
109-
: std::nullopt),
110-
*info,
111-
*members);
112-
113-
return std::make_unique<session::nodeapi::MetaGroup>(
114-
info, members, keys, group_ed25519_pubkey, group_ed25519_secretkey);
115-
});
116-
}
38+
const Napi::CallbackInfo& info, const std::string& class_name);
11739
};
11840

11941
} // namespace session::nodeapi

0 commit comments

Comments
 (0)