Fix various typing issues in signal bindings

This commit is contained in:
Marvin W 2020-01-09 13:39:36 +01:00
parent 3650288a11
commit b2af8c5112
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A
6 changed files with 24 additions and 48 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -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);

View file

@ -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);
/*

View file

@ -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")]

View file

@ -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);