diff options
author | dubslow <bunslow@gmail.com> | 2014-09-24 18:06:30 -0500 |
---|---|---|
committer | dubslow <bunslow@gmail.com> | 2014-09-24 18:06:30 -0500 |
commit | d409bad30dd1657f6b54ea5e38a4d9155f718ae1 (patch) | |
tree | 475f2bf947d6a72a03f030676648f7581b6fa6db | |
parent | ba6ae15a739257200b04a10b6ecd22fe210951e1 (diff) |
remove tox_avatar_hash
-rw-r--r-- | testing/test_avatars.c | 20 | ||||
-rw-r--r-- | toxcore/tox.c | 5 | ||||
-rw-r--r-- | toxcore/tox.h | 26 |
3 files changed, 15 insertions, 36 deletions
diff --git a/testing/test_avatars.c b/testing/test_avatars.c index fc7e9d6f..a7bc9cd8 100644 --- a/testing/test_avatars.c +++ b/testing/test_avatars.c | |||
@@ -222,7 +222,7 @@ static int load_user_avatar(Tox *tox, char *base_dir, int friendnum, | |||
222 | } | 222 | } |
223 | 223 | ||
224 | *datalen = ret; | 224 | *datalen = ret; |
225 | tox_avatar_hash(tox, hash, data, *datalen); | 225 | tox_hash(tox, hash, data, *datalen); |
226 | 226 | ||
227 | return 0; | 227 | return 0; |
228 | } | 228 | } |
@@ -305,7 +305,7 @@ static void friend_avatar_info_cb(Tox *tox, int32_t n, uint8_t format, uint8_t * | |||
305 | char *base_dir = (char *) ud; | 305 | char *base_dir = (char *) ud; |
306 | uint8_t addr[TOX_CLIENT_ID_SIZE]; | 306 | uint8_t addr[TOX_CLIENT_ID_SIZE]; |
307 | char addr_str[2 * TOX_CLIENT_ID_SIZE + 1]; | 307 | char addr_str[2 * TOX_CLIENT_ID_SIZE + 1]; |
308 | char hash_str[2 * TOX_AVATAR_HASH_LENGTH + 1]; | 308 | char hash_str[2 * TOX_HASH_LENGTH + 1]; |
309 | 309 | ||
310 | if (tox_get_client_id(tox, n, addr) == 0) { | 310 | if (tox_get_client_id(tox, n, addr) == 0) { |
311 | byte_to_hex_str(addr, TOX_CLIENT_ID_SIZE, addr_str); | 311 | byte_to_hex_str(addr, TOX_CLIENT_ID_SIZE, addr_str); |
@@ -315,7 +315,7 @@ static void friend_avatar_info_cb(Tox *tox, int32_t n, uint8_t format, uint8_t * | |||
315 | printf("Receiving avatar information from friend number %u.\n", n); | 315 | printf("Receiving avatar information from friend number %u.\n", n); |
316 | } | 316 | } |
317 | 317 | ||
318 | byte_to_hex_str(hash, TOX_AVATAR_HASH_LENGTH, hash_str); | 318 | byte_to_hex_str(hash, TOX_HASH_LENGTH, hash_str); |
319 | DEBUG("format=%u, hash=%s", format, hash_str); | 319 | DEBUG("format=%u, hash=%s", format, hash_str); |
320 | 320 | ||
321 | if (format == TOX_AVATAR_FORMAT_NONE) { | 321 | if (format == TOX_AVATAR_FORMAT_NONE) { |
@@ -333,13 +333,13 @@ static void friend_avatar_info_cb(Tox *tox, int32_t n, uint8_t format, uint8_t * | |||
333 | */ | 333 | */ |
334 | uint32_t cur_av_len; | 334 | uint32_t cur_av_len; |
335 | uint8_t cur_av_data[TOX_AVATAR_MAX_DATA_LENGTH]; | 335 | uint8_t cur_av_data[TOX_AVATAR_MAX_DATA_LENGTH]; |
336 | uint8_t cur_av_hash[TOX_AVATAR_HASH_LENGTH]; | 336 | uint8_t cur_av_hash[TOX_HASH_LENGTH]; |
337 | int ret; | 337 | int ret; |
338 | 338 | ||
339 | ret = load_user_avatar(tox, base_dir, n, format, cur_av_hash, cur_av_data, &cur_av_len); | 339 | ret = load_user_avatar(tox, base_dir, n, format, cur_av_hash, cur_av_data, &cur_av_len); |
340 | 340 | ||
341 | if (ret != 0 | 341 | if (ret != 0 |
342 | && memcpy(cur_av_hash, hash, TOX_AVATAR_HASH_LENGTH) != 0) { | 342 | && memcpy(cur_av_hash, hash, TOX_HASH_LENGTH) != 0) { |
343 | printf(" -> Cached avatar is outdated. Requesting avatar data.\n"); | 343 | printf(" -> Cached avatar is outdated. Requesting avatar data.\n"); |
344 | tox_request_avatar_data(tox, n); | 344 | tox_request_avatar_data(tox, n); |
345 | } else { | 345 | } else { |
@@ -355,7 +355,7 @@ static void friend_avatar_data_cb(Tox *tox, int32_t n, uint8_t format, | |||
355 | char *base_dir = (char *) ud; | 355 | char *base_dir = (char *) ud; |
356 | uint8_t addr[TOX_CLIENT_ID_SIZE]; | 356 | uint8_t addr[TOX_CLIENT_ID_SIZE]; |
357 | char addr_str[2 * TOX_CLIENT_ID_SIZE + 1]; | 357 | char addr_str[2 * TOX_CLIENT_ID_SIZE + 1]; |
358 | char hash_str[2 * TOX_AVATAR_HASH_LENGTH + 1]; | 358 | char hash_str[2 * TOX_HASH_LENGTH + 1]; |
359 | 359 | ||
360 | if (tox_get_client_id(tox, n, addr) == 0) { | 360 | if (tox_get_client_id(tox, n, addr) == 0) { |
361 | byte_to_hex_str(addr, TOX_CLIENT_ID_SIZE, addr_str); | 361 | byte_to_hex_str(addr, TOX_CLIENT_ID_SIZE, addr_str); |
@@ -365,7 +365,7 @@ static void friend_avatar_data_cb(Tox *tox, int32_t n, uint8_t format, | |||
365 | printf("Receiving avatar data from friend number %u.\n", n); | 365 | printf("Receiving avatar data from friend number %u.\n", n); |
366 | } | 366 | } |
367 | 367 | ||
368 | byte_to_hex_str(hash, TOX_AVATAR_HASH_LENGTH, hash_str); | 368 | byte_to_hex_str(hash, TOX_HASH_LENGTH, hash_str); |
369 | DEBUG("format=%u, datalen=%d, hash=%s\n", format, datalen, hash_str); | 369 | DEBUG("format=%u, datalen=%d, hash=%s\n", format, datalen, hash_str); |
370 | 370 | ||
371 | delete_user_avatar(tox, base_dir, n); | 371 | delete_user_avatar(tox, base_dir, n); |
@@ -505,14 +505,14 @@ static void print_avatar_info(Tox *tox) | |||
505 | { | 505 | { |
506 | uint8_t format; | 506 | uint8_t format; |
507 | uint8_t data[TOX_AVATAR_MAX_DATA_LENGTH]; | 507 | uint8_t data[TOX_AVATAR_MAX_DATA_LENGTH]; |
508 | uint8_t hash[TOX_AVATAR_HASH_LENGTH]; | 508 | uint8_t hash[TOX_HASH_LENGTH]; |
509 | uint32_t data_length; | 509 | uint32_t data_length; |
510 | char hash_str[2 * TOX_AVATAR_HASH_LENGTH + 1]; | 510 | char hash_str[2 * TOX_HASH_LENGTH + 1]; |
511 | 511 | ||
512 | int ret = tox_get_self_avatar(tox, &format, data, &data_length, sizeof(data), hash); | 512 | int ret = tox_get_self_avatar(tox, &format, data, &data_length, sizeof(data), hash); |
513 | DEBUG("tox_get_self_avatar returned %d", ret); | 513 | DEBUG("tox_get_self_avatar returned %d", ret); |
514 | DEBUG("format: %d, data_length: %d", format, data_length); | 514 | DEBUG("format: %d, data_length: %d", format, data_length); |
515 | byte_to_hex_str(hash, TOX_AVATAR_HASH_LENGTH, hash_str); | 515 | byte_to_hex_str(hash, TOX_HASH_LENGTH, hash_str); |
516 | DEBUG("hash: %s", hash_str); | 516 | DEBUG("hash: %s", hash_str); |
517 | } | 517 | } |
518 | 518 | ||
diff --git a/toxcore/tox.c b/toxcore/tox.c index 819a67dd..21854de4 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -831,11 +831,6 @@ int tox_hash(const Tox *tox, uint8_t *hash, const uint8_t *data, const uint32_t | |||
831 | return m_hash(hash, data, datalen); | 831 | return m_hash(hash, data, datalen); |
832 | } | 832 | } |
833 | 833 | ||
834 | int tox_avatar_hash(const Tox *tox, uint8_t *hash, const uint8_t *data, const uint32_t datalen) | ||
835 | { | ||
836 | return m_hash(hash, data, datalen); | ||
837 | } | ||
838 | |||
839 | int tox_request_avatar_info(const Tox *tox, const int32_t friendnumber) | 834 | int tox_request_avatar_info(const Tox *tox, const int32_t friendnumber) |
840 | { | 835 | { |
841 | const Messenger *m = tox; | 836 | const Messenger *m = tox; |
diff --git a/toxcore/tox.h b/toxcore/tox.h index c5484fba..d285e3fc 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -38,8 +38,7 @@ extern "C" { | |||
38 | #define TOX_MAX_STATUSMESSAGE_LENGTH 1007 | 38 | #define TOX_MAX_STATUSMESSAGE_LENGTH 1007 |
39 | #define TOX_CLIENT_ID_SIZE 32 | 39 | #define TOX_CLIENT_ID_SIZE 32 |
40 | #define TOX_AVATAR_MAX_DATA_LENGTH 16384 | 40 | #define TOX_AVATAR_MAX_DATA_LENGTH 16384 |
41 | #define TOX_AVATAR_HASH_LENGTH /*crypto_hash_sha256_BYTES*/ 32 | 41 | #define TOX_HASH_LENGTH /*crypto_hash_sha256_BYTES*/ 32 |
42 | #define TOX_HASH_LENGTH TOX_AVATAR_HASH_LENGTH | ||
43 | 42 | ||
44 | #define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t)) | 43 | #define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t)) |
45 | 44 | ||
@@ -614,34 +613,19 @@ int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t | |||
614 | 613 | ||
615 | /* Generates a cryptographic hash of the given data. | 614 | /* Generates a cryptographic hash of the given data. |
616 | * This function may be used by clients for any purpose, but is provided primarily for | 615 | * This function may be used by clients for any purpose, but is provided primarily for |
617 | * validating cached avatars. | 616 | * validating cached avatars. This use is highly recommended to avoid unnecessary avatar |
617 | * updates. | ||
618 | * This function is a wrapper to internal message-digest functions. | 618 | * This function is a wrapper to internal message-digest functions. |
619 | * | 619 | * |
620 | * Arguments: | 620 | * Arguments: |
621 | * hash - destination buffer for the hash data, it must be exactly TOX_HASH_LENGTH bytes long. | 621 | * hash - destination buffer for the hash data, it must be exactly TOX_HASH_LENGTH bytes long. |
622 | * data - data to be hashed; | 622 | * data - data to be hashed; |
623 | * datalen - length of the data; | 623 | * datalen - length of the data; for avatars, should be TOX_AVATAR_MAX_DATA_LENGTH |
624 | * | 624 | * |
625 | * returns 0 on success | 625 | * returns 0 on success |
626 | * returns -1 on failure. | 626 | * returns -1 on failure. |
627 | */ | 627 | */ |
628 | int m_hash(uint8_t *hash, const uint8_t *data, const uint32_t datalen); | 628 | int tox_hash(const Tox *tox, uint8_t *hash, const uint8_t *data, const uint32_t datalen); |
629 | |||
630 | /* Generates a cryptographic hash of the given avatar data. | ||
631 | * This function is a wrapper to tox_hash and specifically provided | ||
632 | * to generate hashes from user avatars that may be memcmp()ed with the values returned by the | ||
633 | * other avatar functions. It is specially important to validate cached avatars. | ||
634 | * | ||
635 | * Arguments: | ||
636 | * hash - destination buffer for the hash data, it must be exactly TOX_AVATAR_HASH_LENGTH bytes long. | ||
637 | * data - avatar image data; | ||
638 | * datalen - length of the avatar image data; it must be <= MAX_AVATAR_DATA_LENGTH. | ||
639 | * | ||
640 | * returns 0 on success | ||
641 | * returns -1 on failure. | ||
642 | */ | ||
643 | int tox_avatar_hash(const Tox *tox, uint8_t *hash, const uint8_t *data, const uint32_t datalen); | ||
644 | |||
645 | 629 | ||
646 | /* Request avatar information from a friend. | 630 | /* Request avatar information from a friend. |
647 | * Asks a friend to provide their avatar information (image format and hash). The friend may | 631 | * Asks a friend to provide their avatar information (image format and hash). The friend may |