From 406d292107f66a06f8db695645345b13ae8acc8b Mon Sep 17 00:00:00 2001 From: iphydf Date: Fri, 9 Sep 2016 15:02:45 +0100 Subject: [PATCH] Minor cleanups: header reordering, adding {}. I hadn't done this for the "fun" code, yet. Also, we should include system headers after our own headers. "In general, a module should be implemented by one or more .cpp files. Each of these .cpp files should include the header that defines their interface first. This ensures that all of the dependences of the module header have been properly added to the module header itself, and are not implicit. System headers should be included after user headers for a translation unit." -- http://llvm.org/docs/CodingStandards.html#a-public-header-file-is-a-module --- auto_tests/crypto_test.c | 2 +- auto_tests/messenger_test.c | 4 ++-- other/bootstrap_daemon/src/config.c | 2 +- other/fun/cracker.c | 13 ++++++++----- other/fun/sign.c | 17 +++++++++++------ toxav/bwcontroller.c | 2 +- toxcore/assoc.c | 2 +- toxcore/net_crypto.h | 2 +- 8 files changed, 26 insertions(+), 18 deletions(-) diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c index ff8ab41d..f39ee8d4 100644 --- a/auto_tests/crypto_test.c +++ b/auto_tests/crypto_test.c @@ -2,13 +2,13 @@ #include "config.h" #endif +#include "../toxcore/net_crypto.h" #include #include #include #include #include #include -#include "../toxcore/net_crypto.h" #include "helpers.h" diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index f7dc92d5..8f904ed1 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c @@ -14,12 +14,12 @@ #include "config.h" #endif +#include "../testing/misc_tools.c" // hex_string_to_bin +#include "../toxcore/Messenger.h" #include #include #include #include -#include "../testing/misc_tools.c" // hex_string_to_bin -#include "../toxcore/Messenger.h" #include "helpers.h" diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c index a0c6045d..27d1364a 100644 --- a/other/bootstrap_daemon/src/config.c +++ b/other/bootstrap_daemon/src/config.c @@ -403,7 +403,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) goto next; } - uint8_t *bs_public_key_bin = hex_string_to_bin((const char *)bs_public_key); + uint8_t *bs_public_key_bin = hex_string_to_bin(bs_public_key); const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), bs_public_key_bin); free(bs_public_key_bin); diff --git a/other/fun/cracker.c b/other/fun/cracker.c index 843b9359..7b020bb7 100644 --- a/other/fun/cracker.c +++ b/other/fun/cracker.c @@ -13,8 +13,8 @@ #include /* NaCl includes*/ -#include -#include +#include +#include /* Sodium include*/ //#include @@ -42,8 +42,9 @@ int main(int argc, char *argv[]) unsigned char *key = hex_string_to_bin(argv[1]); uint8_t pub_key[32], priv_key[32], c_key[32]; - if (len > 32) + if (len > 32) { len = 32; + } memcpy(c_key, key, len); free(key); @@ -53,14 +54,16 @@ int main(int argc, char *argv[]) crypto_scalarmult_curve25519_base(pub_key, priv_key); uint32_t i; - if (memcmp(c_key, pub_key, len) == 0) + if (memcmp(c_key, pub_key, len) == 0) { break; + } for (i = 32; i != 0; --i) { priv_key[i - 1] += 1; - if (priv_key[i - 1] != 0) + if (priv_key[i - 1] != 0) { break; + } } ++num_tries; diff --git a/other/fun/sign.c b/other/fun/sign.c index 56a9d1e2..0cd8f38e 100644 --- a/other/fun/sign.c +++ b/other/fun/sign.c @@ -15,9 +15,9 @@ * * NOTE: The signature is appended to the end of the file. */ +#include "../../testing/misc_tools.c" // hex_string_to_bin #include #include -#include "../../testing/misc_tools.c" // hex_string_to_bin int load_file(char *filename, char **result) { @@ -73,26 +73,30 @@ int main(int argc, char *argv[]) char *data; int size = load_file(argv[3], &data); - if (size < 0) + if (size < 0) { goto fail; + } unsigned long long smlen; char *sm = malloc(size + crypto_sign_ed25519_BYTES * 2); crypto_sign_ed25519(sm, &smlen, data, size, secret_key); free(secret_key); - if (smlen - size != crypto_sign_ed25519_BYTES) + if (smlen - size != crypto_sign_ed25519_BYTES) { goto fail; + } FILE *f = fopen(argv[4], "wb"); - if (f == NULL) + if (f == NULL) { goto fail; + } memcpy(sm + smlen, sm, crypto_sign_ed25519_BYTES); // Move signature from beginning to end of file. - if (fwrite(sm + (smlen - size), 1, smlen, f) != smlen) + if (fwrite(sm + (smlen - size), 1, smlen, f) != smlen) { goto fail; + } fclose(f); printf("Signed successfully.\n"); @@ -103,8 +107,9 @@ int main(int argc, char *argv[]) char *data; int size = load_file(argv[3], &data); - if (size < 0) + if (size < 0) { goto fail; + } char *signe = malloc(size + crypto_sign_ed25519_BYTES); memcpy(signe, data + size - crypto_sign_ed25519_BYTES, diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c index 34d97408..49a2d9e1 100644 --- a/toxav/bwcontroller.c +++ b/toxav/bwcontroller.c @@ -23,10 +23,10 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ -#include #include "../toxcore/logger.h" #include "../toxcore/util.h" #include "bwcontroller.h" +#include #define BWC_PACKET_ID 196 #define BWC_SEND_INTERVAL_MS 1000 diff --git a/toxcore/assoc.c b/toxcore/assoc.c index d99786b0..0a3845bc 100644 --- a/toxcore/assoc.c +++ b/toxcore/assoc.c @@ -10,8 +10,8 @@ #include "LAN_discovery.h" -#include #include "util.h" +#include /* * BASIC OVERVIEW: diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index c42463fc..c5eb3ecb 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h @@ -24,11 +24,11 @@ #ifndef NET_CRYPTO_H #define NET_CRYPTO_H -#include #include "DHT.h" #include "LAN_discovery.h" #include "TCP_connection.h" #include "logger.h" +#include #define CRYPTO_CONN_NO_CONNECTION 0 #define CRYPTO_CONN_COOKIE_REQUESTING 1 //send cookie request packets