Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

improve code consistency #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 31 additions & 30 deletions src/signal_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,9 @@ int signal_protocol_pre_key_load_key(signal_protocol_store_context *context, ses
session_pre_key *result_key = 0;

assert(context);
assert(context->pre_key_store.load_pre_key);
assert(context->pre_key_store.load_pre_key_func);

result = context->pre_key_store.load_pre_key(
result = context->pre_key_store.load_pre_key_func(
&buffer, pre_key_id,
context->pre_key_store.user_data);
if(result < 0) {
Expand All @@ -876,7 +876,7 @@ int signal_protocol_pre_key_store_key(signal_protocol_store_context *context, se
uint32_t id = 0;

assert(context);
assert(context->pre_key_store.store_pre_key);
assert(context->pre_key_store.store_pre_key_func);
assert(pre_key);

id = session_pre_key_get_id(pre_key);
Expand All @@ -886,7 +886,7 @@ int signal_protocol_pre_key_store_key(signal_protocol_store_context *context, se
goto complete;
}

result = context->pre_key_store.store_pre_key(
result = context->pre_key_store.store_pre_key_func(
id,
signal_buffer_data(buffer), signal_buffer_len(buffer),
context->pre_key_store.user_data);
Expand All @@ -904,9 +904,9 @@ int signal_protocol_pre_key_contains_key(signal_protocol_store_context *context,
int result = 0;

assert(context);
assert(context->pre_key_store.contains_pre_key);
assert(context->pre_key_store.contains_pre_key_func);

result = context->pre_key_store.contains_pre_key(
result = context->pre_key_store.contains_pre_key_func(
pre_key_id, context->pre_key_store.user_data);

return result;
Expand All @@ -917,9 +917,9 @@ int signal_protocol_pre_key_remove_key(signal_protocol_store_context *context, u
int result = 0;

assert(context);
assert(context->pre_key_store.remove_pre_key);
assert(context->pre_key_store.remove_pre_key_func);

result = context->pre_key_store.remove_pre_key(
result = context->pre_key_store.remove_pre_key_func(
pre_key_id, context->pre_key_store.user_data);

return result;
Expand All @@ -934,9 +934,9 @@ int signal_protocol_signed_pre_key_load_key(signal_protocol_store_context *conte
session_signed_pre_key *result_key = 0;

assert(context);
assert(context->signed_pre_key_store.load_signed_pre_key);
assert(context->signed_pre_key_store.load_signed_pre_key_func);

result = context->signed_pre_key_store.load_signed_pre_key(
result = context->signed_pre_key_store.load_signed_pre_key_func(
&buffer, signed_pre_key_id,
context->signed_pre_key_store.user_data);
if(result < 0) {
Expand All @@ -963,7 +963,7 @@ int signal_protocol_signed_pre_key_store_key(signal_protocol_store_context *cont
uint32_t id = 0;

assert(context);
assert(context->signed_pre_key_store.store_signed_pre_key);
assert(context->signed_pre_key_store.store_signed_pre_key_func);
assert(pre_key);

id = session_signed_pre_key_get_id(pre_key);
Expand All @@ -973,7 +973,7 @@ int signal_protocol_signed_pre_key_store_key(signal_protocol_store_context *cont
goto complete;
}

result = context->signed_pre_key_store.store_signed_pre_key(
result = context->signed_pre_key_store.store_signed_pre_key_func(
id,
signal_buffer_data(buffer), signal_buffer_len(buffer),
context->signed_pre_key_store.user_data);
Expand All @@ -991,9 +991,9 @@ int signal_protocol_signed_pre_key_contains_key(signal_protocol_store_context *c
int result = 0;

assert(context);
assert(context->signed_pre_key_store.contains_signed_pre_key);
assert(context->signed_pre_key_store.contains_signed_pre_key_func);

result = context->signed_pre_key_store.contains_signed_pre_key(
result = context->signed_pre_key_store.contains_signed_pre_key_func(
signed_pre_key_id, context->signed_pre_key_store.user_data);

return result;
Expand All @@ -1004,9 +1004,9 @@ int signal_protocol_signed_pre_key_remove_key(signal_protocol_store_context *con
int result = 0;

assert(context);
assert(context->signed_pre_key_store.remove_signed_pre_key);
assert(context->signed_pre_key_store.remove_signed_pre_key_func);

result = context->signed_pre_key_store.remove_signed_pre_key(
result = context->signed_pre_key_store.remove_signed_pre_key_func(
signed_pre_key_id, context->signed_pre_key_store.user_data);

return result;
Expand All @@ -1024,9 +1024,9 @@ int signal_protocol_identity_get_key_pair(signal_protocol_store_context *context
ratchet_identity_key_pair *result_key = 0;

assert(context);
assert(context->identity_key_store.get_identity_key_pair);
assert(context->identity_key_store.get_identity_key_pair_func);

result = context->identity_key_store.get_identity_key_pair(
result = context->identity_key_store.get_identity_key_pair_func(
&public_buf, &private_buf,
context->identity_key_store.user_data);
if(result < 0) {
Expand Down Expand Up @@ -1072,10 +1072,11 @@ int signal_protocol_identity_get_local_registration_id(signal_protocol_store_con
int result = 0;

assert(context);
assert(context->identity_key_store.get_local_registration_id);
assert(context->identity_key_store.get_local_registration_id_func);

result = context->identity_key_store.get_local_registration_id(
context->identity_key_store.user_data, registration_id);
result = context->identity_key_store.get_local_registration_id_func(
registration_id,
context->identity_key_store.user_data);

return result;
}
Expand All @@ -1086,22 +1087,22 @@ int signal_protocol_identity_save_identity(signal_protocol_store_context *contex
signal_buffer *buffer = 0;

assert(context);
assert(context->identity_key_store.save_identity);
assert(context->identity_key_store.save_identity_func);

if(identity_key) {
result = ec_public_key_serialize(&buffer, identity_key);
if(result < 0) {
goto complete;
}

result = context->identity_key_store.save_identity(
result = context->identity_key_store.save_identity_func(
address,
signal_buffer_data(buffer),
signal_buffer_len(buffer),
context->identity_key_store.user_data);
}
else {
result = context->identity_key_store.save_identity(
result = context->identity_key_store.save_identity_func(
address, 0, 0,
context->identity_key_store.user_data);
}
Expand All @@ -1120,14 +1121,14 @@ int signal_protocol_identity_is_trusted_identity(signal_protocol_store_context *
signal_buffer *buffer = 0;

assert(context);
assert(context->identity_key_store.is_trusted_identity);
assert(context->identity_key_store.is_trusted_identity_func);

result = ec_public_key_serialize(&buffer, identity_key);
if(result < 0) {
goto complete;
}

result = context->identity_key_store.is_trusted_identity(
result = context->identity_key_store.is_trusted_identity_func(
address,
signal_buffer_data(buffer),
signal_buffer_len(buffer),
Expand All @@ -1149,7 +1150,7 @@ int signal_protocol_sender_key_store_key(signal_protocol_store_context *context,
size_t user_buffer_len = 0;

assert(context);
assert(context->sender_key_store.store_sender_key);
assert(context->sender_key_store.store_sender_key_func);
assert(record);

result = sender_key_record_serialize(&buffer, record);
Expand All @@ -1163,7 +1164,7 @@ int signal_protocol_sender_key_store_key(signal_protocol_store_context *context,
user_buffer_len = signal_buffer_len(user_buffer);
}

result = context->sender_key_store.store_sender_key(
result = context->sender_key_store.store_sender_key_func(
sender_key_name,
signal_buffer_data(buffer), signal_buffer_len(buffer),
user_buffer_data, user_buffer_len,
Expand All @@ -1185,9 +1186,9 @@ int signal_protocol_sender_key_load_key(signal_protocol_store_context *context,
sender_key_record *result_record = 0;

assert(context);
assert(context->sender_key_store.load_sender_key);
assert(context->sender_key_store.load_sender_key_func);

result = context->sender_key_store.load_sender_key(
result = context->sender_key_store.load_sender_key_func(
&buffer, &user_buffer, sender_key_name,
context->sender_key_store.user_data);
if(result < 0) {
Expand Down
28 changes: 14 additions & 14 deletions src/signal_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ typedef struct signal_protocol_pre_key_store {
* @retval SG_SUCCESS if the key was found
* @retval SG_ERR_INVALID_KEY_ID if the key could not be found
*/
int (*load_pre_key)(signal_buffer **record, uint32_t pre_key_id, void *user_data);
int (*load_pre_key_func)(signal_buffer **record, uint32_t pre_key_id, void *user_data);

/**
* Store a local serialized PreKey record.
Expand All @@ -510,7 +510,7 @@ typedef struct signal_protocol_pre_key_store {
* @param record_len length of the serialized record
* @return 0 on success, negative on failure
*/
int (*store_pre_key)(uint32_t pre_key_id, uint8_t *record, size_t record_len, void *user_data);
int (*store_pre_key_func)(uint32_t pre_key_id, uint8_t *record, size_t record_len, void *user_data);

/**
* Determine whether there is a committed PreKey record matching the
Expand All @@ -519,15 +519,15 @@ typedef struct signal_protocol_pre_key_store {
* @param pre_key_id A PreKey record ID.
* @return 1 if the store has a record for the PreKey ID, 0 otherwise
*/
int (*contains_pre_key)(uint32_t pre_key_id, void *user_data);
int (*contains_pre_key_func)(uint32_t pre_key_id, void *user_data);

/**
* Delete a PreKey record from local storage.
*
* @param pre_key_id The ID of the PreKey record to remove.
* @return 0 on success, negative on failure
*/
int (*remove_pre_key)(uint32_t pre_key_id, void *user_data);
int (*remove_pre_key_func)(uint32_t pre_key_id, void *user_data);

/**
* Function called to perform cleanup when the data store context is being
Expand All @@ -550,7 +550,7 @@ typedef struct signal_protocol_signed_pre_key_store {
* @retval SG_SUCCESS if the key was found
* @retval SG_ERR_INVALID_KEY_ID if the key could not be found
*/
int (*load_signed_pre_key)(signal_buffer **record, uint32_t signed_pre_key_id, void *user_data);
int (*load_signed_pre_key_func)(signal_buffer **record, uint32_t signed_pre_key_id, void *user_data);

/**
* Store a local serialized signed PreKey record.
Expand All @@ -560,7 +560,7 @@ typedef struct signal_protocol_signed_pre_key_store {
* @param record_len length of the serialized record
* @return 0 on success, negative on failure
*/
int (*store_signed_pre_key)(uint32_t signed_pre_key_id, uint8_t *record, size_t record_len, void *user_data);
int (*store_signed_pre_key_func)(uint32_t signed_pre_key_id, uint8_t *record, size_t record_len, void *user_data);

/**
* Determine whether there is a committed signed PreKey record matching
Expand All @@ -569,15 +569,15 @@ typedef struct signal_protocol_signed_pre_key_store {
* @param signed_pre_key_id A signed PreKey record ID.
* @return 1 if the store has a record for the signed PreKey ID, 0 otherwise
*/
int (*contains_signed_pre_key)(uint32_t signed_pre_key_id, void *user_data);
int (*contains_signed_pre_key_func)(uint32_t signed_pre_key_id, void *user_data);

/**
* Delete a SignedPreKeyRecord from local storage.
*
* @param signed_pre_key_id The ID of the signed PreKey record to remove.
* @return 0 on success, negative on failure
*/
int (*remove_signed_pre_key)(uint32_t signed_pre_key_id, void *user_data);
int (*remove_signed_pre_key_func)(uint32_t signed_pre_key_id, void *user_data);

/**
* Function called to perform cleanup when the data store context is being
Expand All @@ -601,7 +601,7 @@ typedef struct signal_protocol_identity_key_store {
* The Signal Protocol library is responsible for freeing this buffer.
* @return 0 on success, negative on failure
*/
int (*get_identity_key_pair)(signal_buffer **public_data, signal_buffer **private_data, void *user_data);
int (*get_identity_key_pair_func)(signal_buffer **public_data, signal_buffer **private_data, void *user_data);

/**
* Return the local client's registration ID.
Expand All @@ -613,7 +613,7 @@ typedef struct signal_protocol_identity_key_store {
* registration ID, if it was successfully retrieved.
* @return 0 on success, negative on failure
*/
int (*get_local_registration_id)(void *user_data, uint32_t *registration_id);
int (*get_local_registration_id_func)(uint32_t *registration_id, void *user_data);

/**
* Save a remote client's identity key
Expand All @@ -628,7 +628,7 @@ typedef struct signal_protocol_identity_key_store {
* @param key_len Length of the remote client's identity key
* @return 0 on success, negative on failure
*/
int (*save_identity)(const signal_protocol_address *address, uint8_t *key_data, size_t key_len, void *user_data);
int (*save_identity_func)(const signal_protocol_address *address, uint8_t *key_data, size_t key_len, void *user_data);

/**
* Verify a remote client's identity key.
Expand All @@ -646,7 +646,7 @@ typedef struct signal_protocol_identity_key_store {
* @param key_len Length of the identity key to verify
* @return 1 if trusted, 0 if untrusted, negative on failure
*/
int (*is_trusted_identity)(const signal_protocol_address *address, uint8_t *key_data, size_t key_len, void *user_data);
int (*is_trusted_identity_func)(const signal_protocol_address *address, uint8_t *key_data, size_t key_len, void *user_data);

/**
* Function called to perform cleanup when the data store context is being
Expand All @@ -672,7 +672,7 @@ typedef struct signal_protocol_sender_key_store {
* @param user_record_len length of the application specific data
* @return 0 on success, negative on failure
*/
int (*store_sender_key)(const signal_protocol_sender_key_name *sender_key_name, uint8_t *record, size_t record_len, uint8_t *user_record, size_t user_record_len, void *user_data);
int (*store_sender_key_func)(const signal_protocol_sender_key_name *sender_key_name, uint8_t *record, size_t record_len, uint8_t *user_record, size_t user_record_len, void *user_data);

/**
* Returns a copy of the sender key record corresponding to the
Expand All @@ -688,7 +688,7 @@ typedef struct signal_protocol_sender_key_store {
* @param sender_key_name the (groupId + senderId + deviceId) tuple
* @return 1 if the record was loaded, 0 if the record was not found, negative on failure
*/
int (*load_sender_key)(signal_buffer **record, signal_buffer **user_record, const signal_protocol_sender_key_name *sender_key_name, void *user_data);
int (*load_sender_key_func)(signal_buffer **record, signal_buffer **user_record, const signal_protocol_sender_key_name *sender_key_name, void *user_data);

/**
* Function called to perform cleanup when the data store context is being
Expand Down