aboutsummaryrefslogtreecommitdiff
path: root/plugins/signal-protocol/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/signal-protocol/src')
-rw-r--r--plugins/signal-protocol/src/signal_helper.c38
-rw-r--r--plugins/signal-protocol/src/signal_helper.h6
-rw-r--r--plugins/signal-protocol/src/simple_ss.vala6
-rw-r--r--plugins/signal-protocol/src/store.vala20
4 files changed, 51 insertions, 19 deletions
diff --git a/plugins/signal-protocol/src/signal_helper.c b/plugins/signal-protocol/src/signal_helper.c
index d13b9c95..5cbf2ce2 100644
--- a/plugins/signal-protocol/src/signal_helper.c
+++ b/plugins/signal-protocol/src/signal_helper.c
@@ -3,14 +3,30 @@
#include <gcrypt.h>
-signal_protocol_address* signal_protocol_address_new() {
+signal_type_base* signal_type_ref_vapi(signal_type_base* instance) {
+ g_return_val_if_fail(instance != NULL, NULL);
+ signal_type_ref(instance);
+ return instance;
+}
+
+signal_type_base* signal_type_unref_vapi(signal_type_base* instance) {
+ g_return_val_if_fail(instance != NULL, NULL);
+ signal_type_unref(instance);
+ return NULL;
+}
+
+signal_protocol_address* signal_protocol_address_new(const gchar* name, int32_t device_id) {
+ g_return_val_if_fail(name != NULL, NULL);
signal_protocol_address* address = malloc(sizeof(signal_protocol_address));
- address->name = 0;
- address->device_id = 0;
+ address->device_id = NULL;
+ address->name = NULL;
+ signal_protocol_address_set_name(address, name);
+ signal_protocol_address_set_device_id(address, device_id);
return address;
}
void signal_protocol_address_free(signal_protocol_address* ptr) {
+ g_return_if_fail(ptr != NULL);
if (ptr->name) {
g_free((void*)ptr->name);
}
@@ -18,6 +34,8 @@ void signal_protocol_address_free(signal_protocol_address* ptr) {
}
void signal_protocol_address_set_name(signal_protocol_address* self, const gchar* name) {
+ g_return_if_fail(self != NULL);
+ g_return_if_fail(name != NULL);
gchar* n = g_malloc(strlen(name)+1);
memcpy(n, name, strlen(name));
n[strlen(name)] = 0;
@@ -29,13 +47,25 @@ void signal_protocol_address_set_name(signal_protocol_address* self, const gchar
}
gchar* signal_protocol_address_get_name(signal_protocol_address* self) {
- if (self->name == 0) return 0;
+ g_return_val_if_fail(self != NULL, NULL);
+ g_return_val_if_fail(self->name != NULL, 0);
gchar* res = g_malloc(sizeof(char) * (self->name_len + 1));
memcpy(res, self->name, self->name_len);
res[self->name_len] = 0;
return res;
}
+int32_t signal_protocol_address_get_device_id(signal_protocol_address* self) {
+ g_return_val_if_fail(self != NULL, NULL);
+ return self->device_id;
+}
+
+void signal_protocol_address_set_device_id(signal_protocol_address* self, int32_t device_id) {
+ g_return_if_fail(self != NULL);
+ self->device_id = device_id;
+}
+
+
session_pre_key* session_pre_key_new(uint32_t pre_key_id, ec_key_pair* pair, int* err) {
session_pre_key* res;
*err = session_pre_key_create(&res, pre_key_id, pair);
diff --git a/plugins/signal-protocol/src/signal_helper.h b/plugins/signal-protocol/src/signal_helper.h
index b4b05582..4319bce6 100644
--- a/plugins/signal-protocol/src/signal_helper.h
+++ b/plugins/signal-protocol/src/signal_helper.h
@@ -9,10 +9,14 @@
signal_type_base* signal_type_ref_vapi(signal_type_base* what);
signal_type_base* signal_type_unref_vapi(signal_type_base* what);
-signal_protocol_address* signal_protocol_address_new();
+
+signal_protocol_address* signal_protocol_address_new(const gchar* name, int32_t device_id);
void signal_protocol_address_free(signal_protocol_address* ptr);
void signal_protocol_address_set_name(signal_protocol_address* self, const gchar* name);
gchar* signal_protocol_address_get_name(signal_protocol_address* self);
+void signal_protocol_address_set_device_id(signal_protocol_address* self, int32_t device_id);
+int32_t signal_protocol_address_get_device_id(signal_protocol_address* self);
+
session_pre_key* session_pre_key_new(uint32_t pre_key_id, ec_key_pair* pair, int* err);
session_signed_pre_key* session_signed_pre_key_new(uint32_t id, uint64_t timestamp, ec_key_pair* pair, uint8_t* key, int key_len, int* err);
diff --git a/plugins/signal-protocol/src/simple_ss.vala b/plugins/signal-protocol/src/simple_ss.vala
index cc8e6b78..5213f736 100644
--- a/plugins/signal-protocol/src/simple_ss.vala
+++ b/plugins/signal-protocol/src/simple_ss.vala
@@ -7,10 +7,8 @@ public class SimpleSessionStore : SessionStore {
private Map<string, ArrayList<SessionStore.Session>> session_map = new HashMap<string, ArrayList<SessionStore.Session>>();
public override uint8[]? load_session(Address address) throws Error {
- string name = address.name;
- if (name == null) return null;
- if (session_map.has_key(name)) {
- foreach (SessionStore.Session session in session_map[name]) {
+ if (session_map.has_key(address.name)) {
+ foreach (SessionStore.Session session in session_map[address.name]) {
if (session.device_id == address.device_id) return session.record;
}
}
diff --git a/plugins/signal-protocol/src/store.vala b/plugins/signal-protocol/src/store.vala
index e0d74d0d..eab57e5b 100644
--- a/plugins/signal-protocol/src/store.vala
+++ b/plugins/signal-protocol/src/store.vala
@@ -142,9 +142,9 @@ public class Store : Object {
return 0;
}
- static int ss_load_session_func(out Buffer buffer, Address address, void* user_data) {
+ static int ss_load_session_func(out Buffer? buffer, Address address, void* user_data) {
Store store = (Store) user_data;
- uint8[] res = null;
+ uint8[]? res = null;
try {
res = store.session_store.load_session(address);
} catch (Error e) {
@@ -155,12 +155,12 @@ public class Store : Object {
buffer = null;
return 0;
}
- buffer = new Buffer.from(res);
+ buffer = new Buffer.from((!)res);
if (buffer == null) return ErrorCode.NOMEM;
return 1;
}
- static int ss_get_sub_device_sessions_func(out IntList sessions, char[] name, void* user_data) {
+ static int ss_get_sub_device_sessions_func(out IntList? sessions, char[] name, void* user_data) {
Store store = (Store) user_data;
try {
sessions = store.session_store.get_sub_device_sessions(carr_to_string(name));
@@ -206,9 +206,9 @@ public class Store : Object {
return 0;
}
- static int pks_load_pre_key(out Buffer record, uint32 pre_key_id, void* user_data) {
+ static int pks_load_pre_key(out Buffer? record, uint32 pre_key_id, void* user_data) {
Store store = (Store) user_data;
- uint8[] res = null;
+ uint8[]? res = null;
try {
res = store.pre_key_store.load_pre_key(pre_key_id);
} catch (Error e) {
@@ -219,7 +219,7 @@ public class Store : Object {
record = new Buffer(0);
return 0;
}
- record = new Buffer.from(res);
+ record = new Buffer.from((!)res);
if (record == null) return ErrorCode.NOMEM;
return 1;
}
@@ -251,9 +251,9 @@ public class Store : Object {
return 0;
}
- static int spks_load_signed_pre_key(out Buffer record, uint32 pre_key_id, void* user_data) {
+ static int spks_load_signed_pre_key(out Buffer? record, uint32 pre_key_id, void* user_data) {
Store store = (Store) user_data;
- uint8[] res = null;
+ uint8[]? res = null;
try {
res = store.signed_pre_key_store.load_signed_pre_key(pre_key_id);
} catch (Error e) {
@@ -264,7 +264,7 @@ public class Store : Object {
record = new Buffer(0);
return 0;
}
- record = new Buffer.from(res);
+ record = new Buffer.from((!)res);
if (record == null) return ErrorCode.NOMEM;
return 1;
}