aboutsummaryrefslogtreecommitdiff
path: root/plugins/signal-protocol
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2020-01-09 13:39:36 +0100
committerMarvin W <git@larma.de>2020-01-09 13:39:36 +0100
commitb2af8c51124819d7c5d0bd348c52a0b15f54d582 (patch)
treee0e762d61dbd980bc9322b43d76461038671944a /plugins/signal-protocol
parent3650288a111625a24515e511fa7f1feff697b726 (diff)
downloaddino-b2af8c51124819d7c5d0bd348c52a0b15f54d582.tar.gz
dino-b2af8c51124819d7c5d0bd348c52a0b15f54d582.zip
Fix various typing issues in signal bindings
Diffstat (limited to 'plugins/signal-protocol')
-rw-r--r--plugins/signal-protocol/src/context.vala6
-rw-r--r--plugins/signal-protocol/src/signal_helper.c23
-rw-r--r--plugins/signal-protocol/src/signal_helper.h7
-rw-r--r--plugins/signal-protocol/tests/session_builder.vala16
-rw-r--r--plugins/signal-protocol/vapi/signal-protocol-native.vapi2
-rw-r--r--plugins/signal-protocol/vapi/signal-protocol-public.vapi18
6 files changed, 24 insertions, 48 deletions
diff --git a/plugins/signal-protocol/src/context.vala b/plugins/signal-protocol/src/context.vala
index 87b51756..40a07b0f 100644
--- a/plugins/signal-protocol/src/context.vala
+++ b/plugins/signal-protocol/src/context.vala
@@ -14,7 +14,7 @@ public class Context {
ctx.mutex.unlock();
}
- static void stderr_log(LogLevel level, string message, void* user_data) {
+ static void stderr_log(LogLevel level, string message, size_t len, void* user_data) {
printerr(@"$level: $message\n");
}
@@ -44,7 +44,9 @@ public class Context {
Gee.Set<PreKeyRecord> res = new Gee.HashSet<PreKeyRecord>();
for(uint i = start; i < start+count; i++) {
ECKeyPair pair = generate_key_pair();
- res.add(new PreKeyRecord(i, pair));
+ PreKeyRecord record;
+ throw_by_code(PreKeyRecord.create(out record, i, pair));
+ res.add(record);
}
return res;
}
diff --git a/plugins/signal-protocol/src/signal_helper.c b/plugins/signal-protocol/src/signal_helper.c
index 2d765420..41b11fd7 100644
--- a/plugins/signal-protocol/src/signal_helper.c
+++ b/plugins/signal-protocol/src/signal_helper.c
@@ -2,13 +2,13 @@
#include <gcrypt.h>
-signal_type_base* signal_type_ref_vapi(signal_type_base* instance) {
+signal_type_base* signal_type_ref_vapi(void* 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) {
+signal_type_base* signal_type_unref_vapi(void* instance) {
g_return_val_if_fail(instance != NULL, NULL);
signal_type_unref(instance);
return NULL;
@@ -17,7 +17,7 @@ signal_type_base* signal_type_unref_vapi(signal_type_base* instance) {
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->device_id = NULL;
+ address->device_id = -1;
address->name = NULL;
signal_protocol_address_set_name(address, name);
signal_protocol_address_set_device_id(address, device_id);
@@ -55,7 +55,7 @@ gchar* signal_protocol_address_get_name(signal_protocol_address* self) {
}
int32_t signal_protocol_address_get_device_id(signal_protocol_address* self) {
- g_return_val_if_fail(self != NULL, NULL);
+ g_return_val_if_fail(self != NULL, -1);
return self->device_id;
}
@@ -64,19 +64,6 @@ void signal_protocol_address_set_device_id(signal_protocol_address* self, int32_
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);
- return res;
-}
-
-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) {
- session_signed_pre_key* res;
- *err = session_signed_pre_key_create(&res, id, timestamp, pair, key, key_len);
- return res;
-}
-
int signal_vala_randomize(uint8_t *data, size_t len) {
gcry_randomize(data, len, GCRY_STRONG_RANDOM);
return SG_SUCCESS;
@@ -107,7 +94,7 @@ int signal_vala_hmac_sha256_init(void **hmac_context, const uint8_t *key, size_t
}
int signal_vala_hmac_sha256_update(void *hmac_context, const uint8_t *data, size_t data_len, void *user_data) {
- gcry_mac_hd_t* *ctx = hmac_context;
+ gcry_mac_hd_t* ctx = hmac_context;
if (gcry_mac_write(*ctx, data, data_len)) return SG_ERR_UNKNOWN;
diff --git a/plugins/signal-protocol/src/signal_helper.h b/plugins/signal-protocol/src/signal_helper.h
index 2c2c983f..949a3c7b 100644
--- a/plugins/signal-protocol/src/signal_helper.h
+++ b/plugins/signal-protocol/src/signal_helper.h
@@ -7,8 +7,8 @@
#define SG_CIPHER_AES_GCM_NOPADDING 1000
-signal_type_base* signal_type_ref_vapi(signal_type_base* what);
-signal_type_base* signal_type_unref_vapi(signal_type_base* what);
+signal_type_base* signal_type_ref_vapi(void* what);
+signal_type_base* signal_type_unref_vapi(void* what);
signal_protocol_address* signal_protocol_address_new(const gchar* name, int32_t device_id);
void signal_protocol_address_free(signal_protocol_address* ptr);
@@ -17,9 +17,6 @@ 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);
-
int signal_vala_randomize(uint8_t *data, size_t len);
int signal_vala_random_generator(uint8_t *data, size_t len, void *user_data);
int signal_vala_hmac_sha256_init(void **hmac_context, const uint8_t *key, size_t key_len, void *user_data);
diff --git a/plugins/signal-protocol/tests/session_builder.vala b/plugins/signal-protocol/tests/session_builder.vala
index c9f9c828..7e2448e1 100644
--- a/plugins/signal-protocol/tests/session_builder.vala
+++ b/plugins/signal-protocol/tests/session_builder.vala
@@ -92,10 +92,12 @@ class SessionBuilderTest : Gee.TestCase {
PreKeySignalMessage incoming_message = global_context.deserialize_pre_key_signal_message(outgoing_message.serialized);
/* Save the pre key and signed pre key in Bob's data store */
- PreKeyRecord bob_pre_key_record = new PreKeyRecord(bob_pre_key.pre_key_id, bob_pre_key_pair);
+ PreKeyRecord bob_pre_key_record;
+ throw_by_code(PreKeyRecord.create(out bob_pre_key_record, bob_pre_key.pre_key_id, bob_pre_key_pair));
bob_store.store_pre_key(bob_pre_key_record);
- SignedPreKeyRecord bob_signed_pre_key_record = new SignedPreKeyRecord(22, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature);
+ SignedPreKeyRecord bob_signed_pre_key_record;
+ throw_by_code(SignedPreKeyRecord.create(out bob_signed_pre_key_record, 22, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature));
bob_store.store_signed_pre_key(bob_signed_pre_key_record);
/* Create Bob's session cipher and decrypt the message from Alice */
@@ -160,10 +162,10 @@ class SessionBuilderTest : Gee.TestCase {
bob_pre_key = create_pre_key_bundle(bob_local_registration_id, 1, 31338, bob_pre_key_pair.public, 23, bob_signed_pre_key_pair.public, bob_signed_pre_key_signature, bob_identity_key_pair.public);
/* Save the new pre key and signed pre key in Bob's data store */
- bob_pre_key_record = new PreKeyRecord(bob_pre_key.pre_key_id, bob_pre_key_pair);
+ throw_by_code(PreKeyRecord.create(out bob_pre_key_record, bob_pre_key.pre_key_id, bob_pre_key_pair));
bob_store.store_pre_key(bob_pre_key_record);
- bob_signed_pre_key_record = new SignedPreKeyRecord(23, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature);
+ throw_by_code(SignedPreKeyRecord.create(out bob_signed_pre_key_record, 23, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature));
bob_store.store_signed_pre_key(bob_signed_pre_key_record);
/* Have Alice process Bob's pre key bundle */
@@ -260,9 +262,11 @@ class SessionBuilderTest : Gee.TestCase {
PreKeyBundle bob_pre_key = create_pre_key_bundle(bob_store.local_registration_id,1,31337,bob_pre_key_pair.public,0,null,null,bob_store.identity_key_pair.public);
/* Add Bob's pre keys to Bob's data store */
- PreKeyRecord bob_pre_key_record = new PreKeyRecord(bob_pre_key.pre_key_id, bob_pre_key_pair);
+ PreKeyRecord bob_pre_key_record;
+ throw_by_code(PreKeyRecord.create(out bob_pre_key_record, bob_pre_key.pre_key_id, bob_pre_key_pair));
bob_store.store_pre_key(bob_pre_key_record);
- SignedPreKeyRecord bob_signed_pre_key_record = new SignedPreKeyRecord(22, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature);
+ SignedPreKeyRecord bob_signed_pre_key_record;
+ throw_by_code(SignedPreKeyRecord.create(out bob_signed_pre_key_record, 22, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature));
bob_store.store_signed_pre_key(bob_signed_pre_key_record);
/*
diff --git a/plugins/signal-protocol/vapi/signal-protocol-native.vapi b/plugins/signal-protocol/vapi/signal-protocol-native.vapi
index 72ba1710..fd69d7d0 100644
--- a/plugins/signal-protocol/vapi/signal-protocol-native.vapi
+++ b/plugins/signal-protocol/vapi/signal-protocol-native.vapi
@@ -10,7 +10,7 @@ namespace Signal {
[CCode (has_target = false)]
public delegate void LockingFunc(void* user_data);
[CCode (has_target = false)]
- public delegate void LogFunc(LogLevel level, string message, void* user_data);
+ public delegate void LogFunc(LogLevel level, string message, size_t len, void* user_data);
[Compact]
[CCode (cname = "signal_crypto_provider", cheader_filename = "signal/signal_protocol.h")]
diff --git a/plugins/signal-protocol/vapi/signal-protocol-public.vapi b/plugins/signal-protocol/vapi/signal-protocol-public.vapi
index 40e85c7f..eaf73c0c 100644
--- a/plugins/signal-protocol/vapi/signal-protocol-public.vapi
+++ b/plugins/signal-protocol/vapi/signal-protocol-public.vapi
@@ -118,14 +118,7 @@ namespace Signal {
[Compact]
[CCode (cname = "session_pre_key", cprefix = "session_pre_key_", cheader_filename = "signal/session_pre_key.h,signal_helper.h")]
public class PreKeyRecord : TypeBase {
- public PreKeyRecord(uint32 id, ECKeyPair key_pair) throws GLib.Error {
- int err;
- this.new(id, key_pair, out err);
- throw_by_code(err);
- }
- [CCode (cheader_filename = "signal_helper.h")]
- private PreKeyRecord.new(uint32 id, ECKeyPair key_pair, out int err);
- private static int create(out PreKeyRecord pre_key, uint32 id, ECKeyPair key_pair);
+ public static int create(out PreKeyRecord pre_key, uint32 id, ECKeyPair key_pair);
//public static int deserialize(out PreKeyRecord pre_key, uint8[] data, NativeContext global_context);
[CCode (instance_pos = 2)]
public int serialze(out Buffer buffer);
@@ -166,14 +159,7 @@ namespace Signal {
[Compact]
[CCode (cname = "session_signed_pre_key", cprefix = "session_signed_pre_key_", cheader_filename = "signal/session_pre_key.h")]
public class SignedPreKeyRecord : TypeBase {
- public SignedPreKeyRecord(uint32 id, uint64 timestamp, ECKeyPair key_pair, uint8[] signature) throws GLib.Error {
- int err;
- this.new(id, timestamp, key_pair, signature, out err);
- throw_by_code(err);
- }
- [CCode (cheader_filename = "signal_helper.h")]
- private SignedPreKeyRecord.new(uint32 id, uint64 timestamp, ECKeyPair key_pair, uint8[] signature, out int err);
- private static int create(out SignedPreKeyRecord pre_key, uint32 id, uint64 timestamp, ECKeyPair key_pair, uint8[] signature);
+ public static int create(out SignedPreKeyRecord pre_key, uint32 id, uint64 timestamp, ECKeyPair key_pair, uint8[] signature);
[CCode (instance_pos = 2)]
public int serialze(out Buffer buffer);