summaryrefslogtreecommitdiff
path: root/toxencryptsave
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-03-26 12:39:09 -0400
committerirungentoo <irungentoo@gmail.com>2015-03-26 12:39:09 -0400
commit06b389ea5e4e0ffb1f8e6627d4909c53c23099e1 (patch)
tree6689e3ec5c518f2fbb07ca139cf5a944fe86b020 /toxencryptsave
parente888b89ac94066ab80bd72dbaa347bdab3856020 (diff)
Making tox_encrypted_new() use the same error codes as tox_new was a bad idea.
They now have their own error codes.
Diffstat (limited to 'toxencryptsave')
-rw-r--r--toxencryptsave/toxencryptsave.c8
-rw-r--r--toxencryptsave/toxencryptsave.h58
2 files changed, 59 insertions, 7 deletions
diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c
index 587c7048..874f0fd0 100644
--- a/toxencryptsave/toxencryptsave.c
+++ b/toxencryptsave/toxencryptsave.c
@@ -300,14 +300,14 @@ int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase,
300 * returns NULL on failure; see the documentation in toxcore/tox.h. 300 * returns NULL on failure; see the documentation in toxcore/tox.h.
301 */ 301 */
302Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *passphrase, 302Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *passphrase,
303 size_t pplength, TOX_ERR_NEW *error) 303 size_t pplength, TOX_ERR_ENCRYPTED_NEW *error)
304{ 304{
305 uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; 305 uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
306 uint8_t temp_data[decrypt_length]; 306 uint8_t temp_data[decrypt_length];
307 307
308 if (tox_pass_decrypt(data, length, passphrase, pplength, temp_data) 308 if (tox_pass_decrypt(data, length, passphrase, pplength, temp_data)
309 != decrypt_length) { 309 != decrypt_length) {
310 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_DECRYPTION_FAILED); 310 SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTED_NEW_LOAD_DECRYPTION_FAILED);
311 return NULL; 311 return NULL;
312 } 312 }
313 313
@@ -320,14 +320,14 @@ Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, s
320 * returns NULL on failure; see the documentation in toxcore/tox.h. 320 * returns NULL on failure; see the documentation in toxcore/tox.h.
321 */ 321 */
322Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key, 322Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key,
323 TOX_ERR_NEW *error) 323 TOX_ERR_ENCRYPTED_NEW *error)
324{ 324{
325 uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; 325 uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
326 uint8_t temp_data[decrypt_length]; 326 uint8_t temp_data[decrypt_length];
327 327
328 if (tox_pass_key_decrypt(data, length, key, temp_data) 328 if (tox_pass_key_decrypt(data, length, key, temp_data)
329 != decrypt_length) { 329 != decrypt_length) {
330 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_DECRYPTION_FAILED); 330 SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTED_NEW_LOAD_DECRYPTION_FAILED);
331 return NULL; 331 return NULL;
332 } 332 }
333 333
diff --git a/toxencryptsave/toxencryptsave.h b/toxencryptsave/toxencryptsave.h
index 9b613cac..db272592 100644
--- a/toxencryptsave/toxencryptsave.h
+++ b/toxencryptsave/toxencryptsave.h
@@ -35,7 +35,6 @@ extern "C" {
35#define TOX_DEFINED 35#define TOX_DEFINED
36typedef struct Tox Tox; 36typedef struct Tox Tox;
37struct Tox_Options; 37struct Tox_Options;
38typedef enum TOX_ERR_NEW TOX_ERR_NEW;
39#endif 38#endif
40 39
41// these functions provide access to these defines in toxencryptsave.c, which 40// these functions provide access to these defines in toxencryptsave.c, which
@@ -110,13 +109,66 @@ int tox_encrypted_save(const Tox *tox, uint8_t *data, uint8_t *passphrase, uint3
110 */ 109 */
111int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength, uint8_t *out); 110int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength, uint8_t *out);
112 111
112typedef enum TOX_ERR_ENCRYPTED_NEW {
113 TOX_ERR_ENCRYPTED_NEW_OK,
114 TOX_ERR_ENCRYPTED_NEW_NULL,
115 /**
116 * The function was unable to allocate enough memory to store the internal
117 * structures for the Tox object.
118 */
119 TOX_ERR_ENCRYPTED_NEW_MALLOC,
120 /**
121 * The function was unable to bind to a port. This may mean that all ports
122 * have already been bound, e.g. by other Tox instances, or it may mean
123 * a permission error. You may be able to gather more information from errno.
124 */
125 TOX_ERR_ENCRYPTED_NEW_PORT_ALLOC,
126 /**
127 * proxy_type was invalid.
128 */
129 TOX_ERR_ENCRYPTED_NEW_PROXY_BAD_TYPE,
130 /**
131 * proxy_type was valid but the proxy_host passed had an invalid format
132 * or was NULL.
133 */
134 TOX_ERR_ENCRYPTED_NEW_PROXY_BAD_HOST,
135 /**
136 * proxy_type was valid, but the proxy_port was invalid.
137 */
138 TOX_ERR_ENCRYPTED_NEW_PROXY_BAD_PORT,
139 /**
140 * The proxy host passed could not be resolved.
141 */
142 TOX_ERR_ENCRYPTED_NEW_PROXY_NOT_FOUND,
143 /**
144 * The byte array to be loaded contained an encrypted save.
145 */
146 TOX_ERR_ENCRYPTED_NEW_LOAD_ENCRYPTED,
147 /**
148 * The data format was invalid. This can happen when loading data that was
149 * saved by an older version of Tox, or when the data has been corrupted.
150 * When loading from badly formatted data, some data may have been loaded,
151 * and the rest is discarded. Passing an invalid length parameter also
152 * causes this error.
153 */
154 TOX_ERR_ENCRYPTED_NEW_LOAD_BAD_FORMAT,
155 /**
156 * The encrypted byte array could not be decrypted. Either the data was
157 * corrupt or the password/key was incorrect.
158 *
159 * NOTE: This error code is only set by tox_encrypted_new() and
160 * tox_encrypted_key_new(), in the toxencryptsave module.
161 */
162 TOX_ERR_ENCRYPTED_NEW_LOAD_DECRYPTION_FAILED
163} TOX_ERR_ENCRYPTED_NEW;
164
113/* Load the new messenger from encrypted data of size length. 165/* Load the new messenger from encrypted data of size length.
114 * All other arguments are like toxcore/tox_new(). 166 * All other arguments are like toxcore/tox_new().
115 * 167 *
116 * returns NULL on failure; see the documentation in toxcore/tox.h. 168 * returns NULL on failure; see the documentation in toxcore/tox.h.
117 */ 169 */
118Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *passphrase, 170Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *passphrase,
119 size_t pplength, TOX_ERR_NEW *error); 171 size_t pplength, TOX_ERR_ENCRYPTED_NEW *error);
120 172
121 173
122/******************************* BEGIN PART 1 ******************************* 174/******************************* BEGIN PART 1 *******************************
@@ -190,7 +242,7 @@ int tox_pass_key_decrypt(const uint8_t *data, uint32_t length, const uint8_t *ke
190 * returns NULL on failure; see the documentation in toxcore/tox.h. 242 * returns NULL on failure; see the documentation in toxcore/tox.h.
191 */ 243 */
192Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key, 244Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key,
193 TOX_ERR_NEW *error); 245 TOX_ERR_ENCRYPTED_NEW *error);
194 246
195 247
196/* Determines whether or not the given data is encrypted (by checking the magic number) 248/* Determines whether or not the given data is encrypted (by checking the magic number)