From 92a1fc5853d2c78400ccb02c6c09bc42f6732a04 Mon Sep 17 00:00:00 2001 From: z3bra Date: Mon, 31 Oct 2016 23:59:08 +0100 Subject: Load data into Tox_Option structure --- ratox.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index fbeae7b..8c28831 100644 --- a/ratox.c +++ b/ratox.c @@ -1006,6 +1006,8 @@ dataload(void) fd = open(savefile, O_RDONLY); if (fd < 0) { + toxopt.savedata_length = 0; + toxopt.savedata_data = NULL; if (encryptsavefile) { reprompt1: while (readpass("Data : New passphrase > ", &passphrase, &pplen) < 0); @@ -1035,13 +1037,18 @@ reprompt1: if (read(fd, data, sz) != sz) eprintf("read %s:", savefile); - if (tox_is_save_encrypted(data)) { + toxopt.savedata_length = sz; + toxopt.savedata_data = malloc(sz); + if (toxopt.savedata_data) + eprintf("malloc:"); + + if (tox_is_data_encrypted(data)) { if (!encryptsavefile) logmsg("Data : %s > Encrypted, but saving unencrypted\n", savefile); while (readpass("Data : Passphrase > ", &passphrase, &pplen) < 0 || - tox_encrypted_load(tox, data, sz, passphrase, pplen) < 0); + !tox_pass_decrypt(data, sz, passphrase, pplen, toxopt.savedata_data)); } else { - if (tox_load(tox, data, sz) < 0) + if (memcpy(toxopt.savedata_data, data, sz) < sz) eprintf("Data : %s > Failed to load\n", savefile); if (encryptsavefile) { logmsg("Data : %s > Not encrypted, but saving encrypted\n", savefile); -- cgit v1.2.3