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
This commit is contained in:
iphydf 2016-09-09 15:02:45 +01:00
parent 769db9dd9a
commit 406d292107
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
8 changed files with 26 additions and 18 deletions

View File

@ -2,13 +2,13 @@
#include "config.h"
#endif
#include "../toxcore/net_crypto.h"
#include <check.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include "../toxcore/net_crypto.h"
#include "helpers.h"

View File

@ -14,12 +14,12 @@
#include "config.h"
#endif
#include "../testing/misc_tools.c" // hex_string_to_bin
#include "../toxcore/Messenger.h"
#include <check.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include "../testing/misc_tools.c" // hex_string_to_bin
#include "../toxcore/Messenger.h"
#include "helpers.h"

View File

@ -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);

View File

@ -13,8 +13,8 @@
#include <time.h>
/* NaCl includes*/
#include <crypto_scalarmult_curve25519.h>
#include <randombytes.h>
#include <sodium/crypto_scalarmult_curve25519.h>
#include <sodium/randombytes.h>
/* Sodium include*/
//#include <sodium.h>
@ -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;

View File

@ -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 <sodium.h>
#include <string.h>
#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,

View File

@ -23,10 +23,10 @@
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <assert.h>
#include "../toxcore/logger.h"
#include "../toxcore/util.h"
#include "bwcontroller.h"
#include <assert.h>
#define BWC_PACKET_ID 196
#define BWC_SEND_INTERVAL_MS 1000

View File

@ -10,8 +10,8 @@
#include "LAN_discovery.h"
#include <assert.h>
#include "util.h"
#include <assert.h>
/*
* BASIC OVERVIEW:

View File

@ -24,11 +24,11 @@
#ifndef NET_CRYPTO_H
#define NET_CRYPTO_H
#include <pthread.h>
#include "DHT.h"
#include "LAN_discovery.h"
#include "TCP_connection.h"
#include "logger.h"
#include <pthread.h>
#define CRYPTO_CONN_NO_CONNECTION 0
#define CRYPTO_CONN_COOKIE_REQUESTING 1 //send cookie request packets