Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder parameters of the public API #67

Merged
merged 16 commits into from
Jul 3, 2016
Merged
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
60 changes: 30 additions & 30 deletions bindings/molch.i
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ extern return_status molch_create_user(
const size_t public_master_key_length,
unsigned char **const prekey_list,
size_t *const prekey_list_length,
const unsigned char *const random_data,
const size_t random_data_length,
unsigned char * backup_key,
const size_t backup_key_length,
unsigned char **const backup,
size_t *const backup_length
size_t *const backup_length,
const unsigned char *const random_data,
const size_t random_data_length
);

extern return_status molch_destroy_user(
Expand All @@ -95,7 +95,7 @@ extern return_status molch_destroy_user(

extern size_t molch_user_count();

extern return_status molch_user_list(
extern return_status molch_list_users(
unsigned char **const user_list,
size_t * const user_list_length,
size_t * count);
Expand All @@ -108,60 +108,60 @@ extern molch_message_type molch_get_message_type(
const unsigned char * const packet,
const size_t packet_length);

extern return_status molch_create_send_conversation(
extern return_status molch_start_send_conversation(
unsigned char * const conversation_id,
const size_t conversation_id_length,
unsigned char ** const packet,
size_t *packet_length,
const unsigned char * const message,
const size_t message_length,
const unsigned char * const prekey_list,
const size_t prekey_list_length,
const unsigned char * const sender_public_master_key,
const size_t sender_public_master_key_length,
const unsigned char * const receiver_public_master_key,
const size_t receiver_public_master_key_length,
const unsigned char * const prekey_list,
const size_t prekey_list_length,
const unsigned char * const message,
const size_t message_length,
unsigned char ** const backup,
size_t * const backup_length
);

extern return_status molch_create_receive_conversation(
extern return_status molch_start_receive_conversation(
unsigned char * const conversation_id,
const size_t conversation_id_length,
unsigned char ** const message,
size_t * const message_length,
const unsigned char * const packet,
const size_t packet_length,
unsigned char ** const prekey_list,
size_t * const prekey_list_length,
const unsigned char * const sender_public_master_key,
const size_t sender_public_master_key_length,
const unsigned char * const receiver_public_master_key,
const size_t receiver_public_master_key_length,
const unsigned char * const sender_public_master_key,
const size_t sender_public_master_key_length,
const unsigned char * const packet,
const size_t packet_length,
unsigned char ** const backup,
size_t * const backup_length
);

extern return_status molch_encrypt_message(
unsigned char ** const packet,
size_t *packet_length,
const unsigned char * const message,
const size_t message_length,
const unsigned char * const conversation_id,
const size_t conversation_id_length,
const unsigned char * const message,
const size_t message_length,
unsigned char ** const backup,
size_t * const backup_length
);

extern return_status molch_decrypt_message(
unsigned char ** const message,
size_t *message_length,
const unsigned char * const packet,
const size_t packet_length,
const unsigned char * const conversation_id,
const size_t conversation_id_length,
uint32_t * const receive_message_number,
uint32_t * const previous_receive_message_number,
const unsigned char * const conversation_id,
const size_t conversation_id_length,
const unsigned char * const packet,
const size_t packet_length,
unsigned char ** const backup,
size_t * const backup_length
);
Expand All @@ -174,13 +174,13 @@ extern void molch_end_conversation(
);

extern return_status molch_list_conversations(
const unsigned char * const user_public_master_key,
const size_t user_public_master_key_length,
unsigned char ** const conversation_list,
size_t * const conversation_list_length,
size_t * const number);
size_t * const number,
const unsigned char * const user_public_master_key,
const size_t user_public_master_key_length);

extern char *molch_print_status(return_status status, size_t * const output_length);
extern char *molch_print_status(size_t * const output_length, return_status status);

extern const char *molch_print_status_type(status_type type);

Expand All @@ -195,20 +195,20 @@ extern return_status molch_conversation_export(
extern return_status molch_export(unsigned char ** const backup, size_t *backup_length);

extern return_status molch_conversation_import(
unsigned char * new_backup_key,
const size_t new_backup_key_length,
const unsigned char * const backup,
const size_t backup_length,
const unsigned char * backup_key,
const size_t backup_key,
unsigned char * new_backup_key,
const size_t new_backup_key_length);
const size_t backup_key);

return_status molch_import(
unsigned char * const new_backup_key,
const size_t new_backup_key_length,
unsigned char * const backup,
const size_t backup_length,
const unsigned char * const backup_key,
const size_t backup_key_length,
unsigned char * const new_backup_key,
const size_t new_backup_key_length);
const size_t backup_key_length);

extern return_status molch_get_prekey_list(
unsigned char * const public_master_key,
Expand Down
63 changes: 34 additions & 29 deletions bindings/molch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ function molch.user.new(random_spice --[[optional]])
32,
temp_prekey_list,
prekey_list_length,
spice_userdata,
spice_userdata_length,
raw_backup_key,
32,
temp_backup,
backup_length
backup_length,
spice_userdata,
spice_userdata_length
)
local status_type = molch_interface.get_status(status)
if status_type ~= molch_interface.SUCCESS then
Expand Down Expand Up @@ -216,11 +216,11 @@ function molch.user_count()
end
molch.user.count = molch.user_count

function molch.user_list()
function molch.list_users()
local count = molch_interface.size_t()
local list_length = molch_interface.size_t()
local raw_list = molch_interface.create_ucstring_pointer()
local status = molch_interface.molch_user_list(raw_list, list_length, count)
local status = molch_interface.molch_list_users(raw_list, list_length, count)
local status_type = molch_interface.get_status(status)
if status_type ~= molch_interface.SUCCESS then
error(molch.print_errors(status))
Expand All @@ -236,7 +236,7 @@ function molch.user_list()

return list
end
molch.user.list = molch.user_list
molch.user.list = molch.list_users

function molch:export()
local backup_length = molch_interface.size_t()
Expand Down Expand Up @@ -294,7 +294,12 @@ function molch.user:list_conversations()
local count = molch_interface.size_t()
local raw_list_length = molch_interface.size_t()
local raw_list = molch_interface.create_ucstring_pointer()
local status = molch_interface.molch_list_conversations(convert_to_c_string(self.id), #self.id, raw_list, raw_list_length, count)
local status = molch_interface.molch_list_conversations(
raw_list,
raw_list_length,
count,
convert_to_c_string(self.id),
#self.id)
local status_type = molch_interface.get_status(status)
if status_type ~= molch_interface.SUCCESS then
error(molch.print_errors(status))
Expand All @@ -319,11 +324,11 @@ function molch.import(backup)
local new_backup_key = molch_interface.ucstring_array(32)

local status = molch_interface.molch_import(
new_backup_key,
32,
backup_string,
backup_length,
raw_backup_key,
32,
new_backup_key,
32)
local status_type = molch_interface.get_status(status)
if status_type ~= molch_interface.SUCCESS then
Expand All @@ -347,7 +352,7 @@ function molch.import(backup)
end

-- update global user list
local user_list = molch.user_list()
local user_list = molch.list_users()
local user_id_lookup = {}
for _,user_id in ipairs(user_list) do
user_id_lookup[user_id] = true
Expand Down Expand Up @@ -390,7 +395,7 @@ function molch.import(backup)
end
end

function molch.user:create_send_conversation(message, prekey_list, receiver_id)
function molch.user:start_send_conversation(message, prekey_list, receiver_id)
local conversation = {}
setmetatable(conversation, molch.conversation)

Expand All @@ -403,19 +408,19 @@ function molch.user:create_send_conversation(message, prekey_list, receiver_id)
local raw_message, raw_message_length = convert_to_c_string(message)
local raw_prekey_list, raw_prekey_list_length = convert_to_c_string(prekey_list)

local status = molch_interface.molch_create_send_conversation(
local status = molch_interface.molch_start_send_conversation(
raw_conversation_id,
molch_interface.CONVERSATION_ID_SIZE,
raw_packet,
raw_packet_length,
raw_message,
raw_message_length,
raw_prekey_list,
raw_prekey_list_length,
convert_to_c_string(self.id),
#self.id,
convert_to_c_string(receiver_id),
#receiver_id,
raw_prekey_list,
raw_prekey_list_length,
raw_message,
raw_message_length,
raw_backup,
raw_backup_length)
local status_type = molch_interface.get_status(status)
Expand Down Expand Up @@ -444,7 +449,7 @@ function molch.user:create_send_conversation(message, prekey_list, receiver_id)
return conversation, packet
end

function molch.user:create_receive_conversation(packet, sender_id)
function molch.user:start_receive_conversation(packet, sender_id)
local conversation = {}
setmetatable(conversation, molch.conversation)

Expand All @@ -458,19 +463,19 @@ function molch.user:create_receive_conversation(packet, sender_id)

local raw_packet, raw_packet_length = convert_to_c_string(packet)

local status = molch_interface.molch_create_receive_conversation(
local status = molch_interface.molch_start_receive_conversation(
raw_conversation_id,
molch_interface.CONVERSATION_ID_SIZE,
raw_message,
raw_message_length,
raw_packet,
raw_packet_length,
raw_prekey_list,
raw_prekey_list_length,
convert_to_c_string(sender_id),
#sender_id,
convert_to_c_string(self.id),
#self.id,
convert_to_c_string(sender_id),
#sender_id,
raw_packet,
raw_packet_length,
raw_backup,
raw_backup_length)
local status_type = molch_interface.get_status(status)
Expand Down Expand Up @@ -535,10 +540,10 @@ function molch.conversation:encrypt_message(message)
local status = molch_interface.molch_encrypt_message(
raw_packet,
raw_packet_length,
raw_message,
raw_message_length,
convert_to_c_string(self.id),
#self.id,
raw_message,
raw_message_length,
raw_backup,
raw_backup_length)
local status_type = molch_interface.get_status(status)
Expand Down Expand Up @@ -569,12 +574,12 @@ function molch.conversation:decrypt_message(packet)
local status = molch_interface.molch_decrypt_message(
raw_message,
raw_message_length,
raw_packet,
raw_packet_length,
convert_to_c_string(self.id),
#self.id,
raw_receive_message_number,
raw_previous_receive_message_number,
convert_to_c_string(self.id),
#self.id,
raw_packet,
raw_packet_length,
raw_backup,
raw_backup_length)
local status_type = molch_interface.get_status(status)
Expand Down Expand Up @@ -624,7 +629,7 @@ end

function molch.print_errors(status)
local size = molch_interface.size_t()
local raw_error_stack = molch_interface.molch_print_status(status, size)
local raw_error_stack = molch_interface.molch_print_status(size, status)
molch_interface.molch_destroy_return_status(status)
return raw_error_stack
end
Expand Down
8 changes: 4 additions & 4 deletions bindings/scenarios/scenarios.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function alice_send(message)

local packet
if not alice_conversation then
alice_conversation, packet = alice:create_send_conversation(message, bob.prekey_list, bob.id)
alice_conversation, packet = alice:start_send_conversation(message, bob.prekey_list, bob.id)
else
packet = alice_conversation:encrypt_message(message)
end
Expand All @@ -61,7 +61,7 @@ function bob_send(message)

local packet
if not bob_conversation then
bob_conversation, packet = bob:create_send_conversation(message, alice.prekey_list, alice.id)
bob_conversation, packet = bob:start_send_conversation(message, alice.prekey_list, alice.id)
else
packet = bob_conversation:encrypt_message(message)
end
Expand All @@ -87,7 +87,7 @@ function alice_receive(number)
local packet = table.remove(bob_sent, number).packet

if not alice_conversation then
alice_conversation, message = alice:create_receive_conversation(packet, bob.id)
alice_conversation, message = alice:start_receive_conversation(packet, bob.id)
receive_message_number = 0
previous_receive_message_number = 0
else
Expand Down Expand Up @@ -118,7 +118,7 @@ function bob_receive(number)
local packet = table.remove(alice_sent, number).packet

if not bob_conversation then
bob_conversation, message = bob:create_receive_conversation(packet, alice.id)
bob_conversation, message = bob:start_receive_conversation(packet, alice.id)
receive_message_number = 0
previous_receive_message_number = 0
else
Expand Down
Loading