From dfb1aba247e7aac62981553e9d16d12472074060 Mon Sep 17 00:00:00 2001 From: jmjatlanta Date: Mon, 17 Jul 2017 16:14:20 -0500 Subject: [PATCH] Fixed warnings --- crypto/aes.c | 10 +++++----- crypto/ephemeral.c | 2 +- crypto/key.c | 4 ++-- crypto/rsa.c | 4 ++-- net/multistream.c | 2 +- peer/peer.c | 8 ++++---- peer/peerstore.c | 2 +- record/message.c | 6 +++--- record/message_handler.c | 4 +++- record/record.c | 14 +++++++------- routing/dht_protocol.c | 8 ++++---- routing/kademlia.c | 2 +- secio/secio.c | 4 ++-- test/crypto/test_aes.h | 4 ++-- test/crypto/test_ephemeral.h | 2 +- test/crypto/test_key.h | 4 ++-- test/crypto/test_mac.h | 4 ++-- test/crypto/test_rsa.h | 4 ++-- test/test_multistream.h | 4 ++-- test/test_peer.h | 2 +- test/test_record.h | 24 ++++++++++++------------ test/test_secio.h | 12 ++++++------ 22 files changed, 66 insertions(+), 64 deletions(-) diff --git a/crypto/aes.c b/crypto/aes.c index 52f3af6..a4ea51c 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -29,7 +29,7 @@ int libp2p_crypto_aes_key_generate(char* key) { strlen( pers )) != 0) return 0; - if (mbedtls_ctr_drbg_random(&ctr_drbg, key, 32) != 0) + if (mbedtls_ctr_drbg_random(&ctr_drbg, (unsigned char*)key, 32) != 0) return 0; return 1; @@ -49,7 +49,7 @@ int libp2p_crypto_aes_encrypt(char* key, char* iv, char* input, size_t input_siz int new_size = 0; mbedtls_aes_context ctx; mbedtls_aes_init(&ctx); - mbedtls_aes_setkey_enc(&ctx, key, 256); + mbedtls_aes_setkey_enc(&ctx, (unsigned char*)key, 256); // turn input into a multiple of 16 new_size = input_size; if (new_size % 16 != 0) { @@ -62,7 +62,7 @@ int libp2p_crypto_aes_encrypt(char* key, char* iv, char* input, size_t input_siz // make room for the output *output = malloc(new_size); *output_size = new_size; - int retVal = mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, new_size, iv, padded_input, *output); + int retVal = mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, new_size, (unsigned char*)iv, (unsigned char*)padded_input, *output); free(padded_input); if (retVal != 0) free(output); @@ -82,11 +82,11 @@ int libp2p_crypto_aes_encrypt(char* key, char* iv, char* input, size_t input_siz int libp2p_crypto_aes_decrypt(char* key, char* iv, char* input, size_t input_size, unsigned char** output, size_t* output_size) { mbedtls_aes_context ctx; mbedtls_aes_init(&ctx); - mbedtls_aes_setkey_dec(&ctx, key, 256); + mbedtls_aes_setkey_dec(&ctx, (unsigned char*)key, 256); // make room for the output *output = malloc(input_size); *output_size = input_size; - if (mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, input_size, iv, input, *output) != 0) + if (mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, input_size, (unsigned char*)iv, (unsigned char*)input, *output) != 0) return 0; return 1; } diff --git a/crypto/ephemeral.c b/crypto/ephemeral.c index 4ceab12..de9cca4 100644 --- a/crypto/ephemeral.c +++ b/crypto/ephemeral.c @@ -176,7 +176,7 @@ int libp2p_crypto_ephemeral_keypair_generate(char* curve, struct EphemeralPrivat // create and marshal public key public_key->bytes_size = 66; public_key->bytes = (unsigned char*)malloc(public_key->bytes_size); - if (mbedtls_ecdh_make_public(&private_key->ctx, &public_key->bytes_size, (char*)public_key->bytes, public_key->bytes_size, mbedtls_ctr_drbg_random, &ctr_drbg) != 0) + if (mbedtls_ecdh_make_public(&private_key->ctx, &public_key->bytes_size, public_key->bytes, public_key->bytes_size, mbedtls_ctr_drbg_random, &ctr_drbg) != 0) goto exit; // ship all this stuff back to the caller diff --git a/crypto/key.c b/crypto/key.c index b44be15..3a61d67 100644 --- a/crypto/key.c +++ b/crypto/key.c @@ -55,7 +55,7 @@ int libp2p_crypto_public_key_protobuf_encode(const struct PublicKey* in, unsigne retVal = protobuf_encode_varint(1, WIRETYPE_VARINT, in->type, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used); *bytes_written += bytes_used; // public key - retVal = protobuf_encode_length_delimited(2, WIRETYPE_LENGTH_DELIMITED, in->data, in->data_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used); + retVal = protobuf_encode_length_delimited(2, WIRETYPE_LENGTH_DELIMITED, (char*)in->data, in->data_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used); if (retVal == 0) return 0; *bytes_written += bytes_used; @@ -156,7 +156,7 @@ int libp2p_crypto_private_key_protobuf_encode(const struct PrivateKey* in, unsig return 0; *bytes_written += bytes_used; // private key - if (!protobuf_encode_length_delimited(2, WIRETYPE_LENGTH_DELIMITED, in->data, in->data_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used)) + if (!protobuf_encode_length_delimited(2, WIRETYPE_LENGTH_DELIMITED, (char*)in->data, in->data_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used)) return 0; *bytes_written += bytes_used; return 1; diff --git a/crypto/rsa.c b/crypto/rsa.c index c22c934..c6c0c7b 100644 --- a/crypto/rsa.c +++ b/crypto/rsa.c @@ -285,7 +285,7 @@ int libp2p_crypto_rsa_sign(struct RsaPrivateKey* private_key, const char* messag int der_allocated = 0; // hash the incoming message - libp2p_crypto_hashing_sha256(message, message_length, hash); + libp2p_crypto_hashing_sha256((unsigned char*)message, message_length, hash); // put a null terminator on the key (if ncessary) if (private_key->der[private_key->der_length-1] != 0) { @@ -296,7 +296,7 @@ int libp2p_crypto_rsa_sign(struct RsaPrivateKey* private_key, const char* messag memcpy(der, private_key->der, private_key->der_length); der[private_key->der_length] = 0; } else { - der = private_key->der; + der = (unsigned char*)private_key->der; } // make a pk_context from the private key mbedtls_pk_init(&private_context); diff --git a/net/multistream.c b/net/multistream.c index 491ede7..33a3ac3 100644 --- a/net/multistream.c +++ b/net/multistream.c @@ -114,7 +114,7 @@ int libp2p_net_multistream_read(void* stream_context, unsigned char** results, s bytes = socket_read(*((int*)stream->socket_descriptor), &buffer[already_read], left, 0, timeout_secs); if (bytes < 0) { bytes = 0; - if ( (errno == EAGAIN)) { + if ( errno == EAGAIN ) { // do something intelligent } else { return 0; diff --git a/peer/peer.c b/peer/peer.c index a1a2d68..d8c1bc0 100644 --- a/peer/peer.c +++ b/peer/peer.c @@ -171,8 +171,8 @@ struct Libp2pPeer* libp2p_peer_copy(struct Libp2pPeer* in) { * @returns true if peer matches */ int libp2p_peer_matches_id(struct Libp2pPeer* in, const unsigned char* peer_id) { - if (strlen(peer_id) == in->id_size) { - if (strncmp(in->id, peer_id, in->id_size) == 0) + if (strlen((char*)peer_id) == in->id_size) { + if (strncmp(in->id, (char*)peer_id, in->id_size) == 0) return 1; } return 0; @@ -223,7 +223,7 @@ int libp2p_peer_protobuf_encode(struct Libp2pPeer* in, unsigned char* buffer, si struct Libp2pLinkedList* current = in->addr_head; while (current != NULL) { struct MultiAddress* data = (struct MultiAddress*)current->item; - retVal = protobuf_encode_length_delimited(2, WIRETYPE_LENGTH_DELIMITED, data->bytes, data->bsize, &buffer[*bytes_written], max_buffer_size - *bytes_written, &bytes_used); + retVal = protobuf_encode_length_delimited(2, WIRETYPE_LENGTH_DELIMITED, (char*)data->bytes, data->bsize, &buffer[*bytes_written], max_buffer_size - *bytes_written, &bytes_used); if (retVal == 0) return 0; *bytes_written += bytes_used; @@ -282,7 +282,7 @@ int libp2p_peer_protobuf_decode(unsigned char* in, size_t in_size, struct Libp2p struct Libp2pLinkedList* current = libp2p_utils_linked_list_new(); if (current == NULL) goto exit; - struct MultiAddress* address = multiaddress_new_from_bytes(buffer, buffer_size); + struct MultiAddress* address = multiaddress_new_from_bytes((unsigned char*)buffer, buffer_size); current->item = (void*)address; free(buffer); buffer = NULL; diff --git a/peer/peerstore.c b/peer/peerstore.c index 6625f09..4ba38c7 100644 --- a/peer/peerstore.c +++ b/peer/peerstore.c @@ -113,7 +113,7 @@ int libp2p_peerstore_add_peer(struct Peerstore* peerstore, struct Libp2pPeer* pe ma_string = ((struct MultiAddress*)peer->addr_head->item)->string; } // first check to see if it exists. If it does, return TRUE - if (libp2p_peerstore_get_peer_entry(peerstore, peer->id, peer->id_size) != NULL) { + if (libp2p_peerstore_get_peer_entry(peerstore, (unsigned char*)peer->id, peer->id_size) != NULL) { libp2p_logger_debug("peerstore", "Attempted to add %s to peerstore, but already there.\n", ma_string); return 1; } diff --git a/record/message.c b/record/message.c index fd97cbe..187f61b 100644 --- a/record/message.c +++ b/record/message.c @@ -138,7 +138,7 @@ int libp2p_message_protobuf_encode(const struct Libp2pMessage* in, unsigned char free(protobuf); return 0; } - retVal = protobuf_encode_length_delimited(3, WIRETYPE_LENGTH_DELIMITED, protobuf, protobuf_size, &buffer[*bytes_written], max_buffer_size - *bytes_written, &bytes_used); + retVal = protobuf_encode_length_delimited(3, WIRETYPE_LENGTH_DELIMITED, (char*)protobuf, protobuf_size, &buffer[*bytes_written], max_buffer_size - *bytes_written, &bytes_used); free(protobuf); if (retVal == 0) return 0; @@ -156,7 +156,7 @@ int libp2p_message_protobuf_encode(const struct Libp2pMessage* in, unsigned char free(peer_buffer); return 0; } - retVal = protobuf_encode_length_delimited(8, WIRETYPE_LENGTH_DELIMITED, peer_buffer, protobuf_size, &buffer[*bytes_written], max_buffer_size - *bytes_written, &bytes_used); + retVal = protobuf_encode_length_delimited(8, WIRETYPE_LENGTH_DELIMITED, (char*)peer_buffer, protobuf_size, &buffer[*bytes_written], max_buffer_size - *bytes_written, &bytes_used); free(peer_buffer); if (retVal == 0) return 0; @@ -175,7 +175,7 @@ int libp2p_message_protobuf_encode(const struct Libp2pMessage* in, unsigned char free(peer_buffer); return 0; } - retVal = protobuf_encode_length_delimited(9, WIRETYPE_LENGTH_DELIMITED, peer_buffer, protobuf_size, &buffer[*bytes_written], max_buffer_size - *bytes_written, &bytes_used); + retVal = protobuf_encode_length_delimited(9, WIRETYPE_LENGTH_DELIMITED, (char*)peer_buffer, protobuf_size, &buffer[*bytes_written], max_buffer_size - *bytes_written, &bytes_used); free(peer_buffer); if (retVal == 0) return 0; diff --git a/record/message_handler.c b/record/message_handler.c index e6f7635..e573a70 100644 --- a/record/message_handler.c +++ b/record/message_handler.c @@ -12,8 +12,10 @@ int libp2p_record_handler_ping(struct Libp2pPeer* peer, struct Libp2pMessage* me int libp2p_record_message_handle(struct Libp2pPeer* peer, struct Libp2pMessage* message) { switch (message->message_type) { - case (MESSAGE_TYPE_PING): + case (MESSAGE_TYPE_PING): return libp2p_record_handler_ping(peer, message); + default: + break; } return 0; } diff --git a/record/record.c b/record/record.c index 0601482..471bbe9 100644 --- a/record/record.c +++ b/record/record.c @@ -92,7 +92,7 @@ int libp2p_record_protobuf_encode(const struct Libp2pRecord* in, unsigned char* return 0; *bytes_written += bytes_used; // field 2 - retVal = protobuf_encode_length_delimited(2, WIRETYPE_LENGTH_DELIMITED, in->value, in->value_size, &buffer[*bytes_written], max_buffer_size - *bytes_written, &bytes_used); + retVal = protobuf_encode_length_delimited(2, WIRETYPE_LENGTH_DELIMITED, (char*)in->value, in->value_size, &buffer[*bytes_written], max_buffer_size - *bytes_written, &bytes_used); if (retVal == 0) return 0; *bytes_written += bytes_used; @@ -102,7 +102,7 @@ int libp2p_record_protobuf_encode(const struct Libp2pRecord* in, unsigned char* return 0; *bytes_written += bytes_used; // field 4 - retVal = protobuf_encode_length_delimited(4, WIRETYPE_LENGTH_DELIMITED, in->signature, in->signature_size, &buffer[*bytes_written], max_buffer_size - *bytes_written, &bytes_used); + retVal = protobuf_encode_length_delimited(4, WIRETYPE_LENGTH_DELIMITED, (char*)in->signature, in->signature_size, &buffer[*bytes_written], max_buffer_size - *bytes_written, &bytes_used); if (retVal == 0) return 0; *bytes_written += bytes_used; @@ -218,7 +218,7 @@ int libp2p_record_make_put_record (char** record_buf, size_t *rec_size, const st struct Libp2pRecord record; record.key = (char*)key; record.key_size = strlen(key); - record.value = (char*)value; + record.value = (unsigned char*)value; record.value_size = vlen; // clear the rest of the fields @@ -229,8 +229,8 @@ int libp2p_record_make_put_record (char** record_buf, size_t *rec_size, const st record.time_received_size = 0; // build a hash of the author's public key - libp2p_crypto_hashing_sha256(sk->public_key_der, sk->public_key_length, &hash[0]); - record.author = &hash[0]; + libp2p_crypto_hashing_sha256((unsigned char*)sk->public_key_der, sk->public_key_length, &hash[0]); + record.author = (char*)&hash[0]; record.author_size = 32; bytes_size = record.key_size + record.value_size + record.author_size; @@ -244,7 +244,7 @@ int libp2p_record_make_put_record (char** record_buf, size_t *rec_size, const st memcpy(&bytes[record.key_size], record.value, record.value_size); memcpy(&bytes[record.key_size + record.value_size], record.author, record.author_size); size_t sign_length = 0; - if (!libp2p_crypto_rsa_sign ((struct RsaPrivateKey*)sk, bytes, bytes_size, &sign_buf, &sign_length)) + if (!libp2p_crypto_rsa_sign ((struct RsaPrivateKey*)sk, (char*)bytes, bytes_size, &sign_buf, &sign_length)) goto exit; record.signature = sign_buf; record.signature_size = sign_length; @@ -256,7 +256,7 @@ int libp2p_record_make_put_record (char** record_buf, size_t *rec_size, const st if (*record_buf == NULL) goto exit; - if (!libp2p_record_protobuf_encode(&record, *record_buf, protobuf_size, &protobuf_size)) + if (!libp2p_record_protobuf_encode(&record, (unsigned char*)*record_buf, protobuf_size, &protobuf_size)) goto exit; *rec_size = protobuf_size; diff --git a/routing/dht_protocol.c b/routing/dht_protocol.c index 72f0177..8179b78 100644 --- a/routing/dht_protocol.c +++ b/routing/dht_protocol.c @@ -97,7 +97,7 @@ int libp2p_routing_dht_handle_get_providers(struct SessionContext* session, stru message->provider_peer_head = NULL; // Can I provide it? - if (libp2p_providerstore_get(providerstore, message->key, message->key_size, &peer_id, &peer_id_size)) { + if (libp2p_providerstore_get(providerstore, (unsigned char*)message->key, message->key_size, &peer_id, &peer_id_size)) { libp2p_logger_debug("dht_protocol", "I can provide a provider for this key.\n"); // we have a peer id, convert it to a peer object struct Libp2pPeer* peer = libp2p_peerstore_get_peer(peerstore, peer_id, peer_id_size); @@ -210,7 +210,7 @@ int libp2p_routing_dht_handle_add_provider(struct SessionContext* session, struc if (!libp2p_peerstore_add_peer(peerstore, peer)) goto exit; libp2p_logger_debug("dht_protocol", "About to add key to providerstore\n"); - if (!libp2p_providerstore_add(providerstore, message->key, message->key_size, peer->id, peer->id_size)) + if (!libp2p_providerstore_add(providerstore, (unsigned char*)message->key, message->key_size, (unsigned char*)peer->id, peer->id_size)) goto exit; } @@ -254,7 +254,7 @@ int libp2p_routing_dht_handle_get_value(struct SessionContext* session, struct L unsigned char* data = NULL; // We need to get the data from the disk - if(!filestore->node_get(message->key, message->key_size, (void**)&data, &data_size, filestore)) { + if(!filestore->node_get((unsigned char*)message->key, message->key_size, (void**)&data, &data_size, filestore)) { libp2p_logger_debug("dht_protocol", "handle_get_value: Unable to get key from filestore\n"); } @@ -308,7 +308,7 @@ int libp2p_routing_dht_handle_put_value(struct SessionContext* session, struct L int libp2p_routing_dht_handle_find_node(struct SessionContext* session, struct Libp2pMessage* message, struct Peerstore* peerstore, struct ProviderStore* providerstore, unsigned char** result_buffer, size_t *result_buffer_size) { // look through peer store - struct Libp2pPeer* peer = libp2p_peerstore_get_peer(peerstore, message->key, message->key_size); + struct Libp2pPeer* peer = libp2p_peerstore_get_peer(peerstore, (unsigned char*)message->key, message->key_size); if (peer != NULL) { message->provider_peer_head = libp2p_utils_linked_list_new(); message->provider_peer_head->item = libp2p_peer_copy(peer); diff --git a/routing/kademlia.c b/routing/kademlia.c index 5aaa3fb..3578a14 100644 --- a/routing/kademlia.c +++ b/routing/kademlia.c @@ -486,7 +486,7 @@ struct MultiAddress** search_kademlia(char* peer_id, int timeout) dht_hash (id, sizeof(id), peer_id, strlen(peer_id), NULL, 0, NULL, 0); //TODO: Is this the right place to ask the net? - dht_search(peer_id, 0, AF_INET, NULL, NULL); + dht_search((unsigned char*)peer_id, 0, AF_INET, NULL, NULL); to = search_kademlia_internal (id, 0, to); if (to == 0) return NULL; // time out. diff --git a/secio/secio.c b/secio/secio.c index c80df4f..03985ed 100644 --- a/secio/secio.c +++ b/secio/secio.c @@ -293,8 +293,8 @@ int libp2p_secio_sign(struct PrivateKey* private_key, const char* in, size_t in_ int libp2p_secio_stretch_keys(char* cipherType, char* hashType, unsigned char* secret, size_t secret_size, struct StretchedKey** k1_ptr, struct StretchedKey** k2_ptr) { int retVal = 0, num_filled = 0, hmac_size = 20; - struct StretchedKey* k1; - struct StretchedKey* k2; + struct StretchedKey* k1 = NULL; + struct StretchedKey* k2 = NULL; unsigned char* result = NULL;; size_t result_size = 0; char* seed = "key expansion"; diff --git a/test/crypto/test_aes.h b/test/crypto/test_aes.h index a1434d2..399207c 100644 --- a/test/crypto/test_aes.h +++ b/test/crypto/test_aes.h @@ -28,13 +28,13 @@ int test_aes() { if (encrypted == NULL) goto exit; - if (libp2p_crypto_aes_decrypt(key, iv_original, encrypted, output_size, &unencrypted, &output_size) != 1) + if (libp2p_crypto_aes_decrypt(key, iv_original, (char*)encrypted, output_size, &unencrypted, &output_size) != 1) goto exit; if (output_size != 48) goto exit; - if (strncmp(input, unencrypted, input_size) != 0) + if (strncmp(input, (char*)unencrypted, input_size) != 0) goto exit; retVal = 1; diff --git a/test/crypto/test_ephemeral.h b/test/crypto/test_ephemeral.h index d4a3b15..015fe46 100644 --- a/test/crypto/test_ephemeral.h +++ b/test/crypto/test_ephemeral.h @@ -71,7 +71,7 @@ int test_ephemeral_key_sign() { fprintf(stdout, "\n"); // attempt to sign - libp2p_crypto_rsa_sign(rsa_private_key, e_private_key->public_key->bytes, e_private_key->public_key->bytes_size, &result, &result_size); + libp2p_crypto_rsa_sign(rsa_private_key, (char*)e_private_key->public_key->bytes, e_private_key->public_key->bytes_size, &result, &result_size); retVal = 1; exit: diff --git a/test/crypto/test_key.h b/test/crypto/test_key.h index f8604b6..ba4f1bd 100644 --- a/test/crypto/test_key.h +++ b/test/crypto/test_key.h @@ -42,7 +42,7 @@ int test_protobuf_private_key() { struct PublicKey public_key; public_key.type = KEYTYPE_RSA; public_key.data_size = rsa_private_key.public_key_length; - public_key.data = rsa_private_key.public_key_der; + public_key.data = (unsigned char*)rsa_private_key.public_key_der; if (!libp2p_crypto_public_key_to_peer_id(&public_key, (char**)&final_id )) goto exit; @@ -50,7 +50,7 @@ int test_protobuf_private_key() { if (orig_peer_id_size != strlen((char*)final_id)) goto exit; - if (strncmp(orig_peer_id, (char*)final_id, strlen(final_id)) != 0) + if (strncmp(orig_peer_id, (char*)final_id, strlen((char*)final_id)) != 0) goto exit; retVal = 1; diff --git a/test/crypto/test_mac.h b/test/crypto/test_mac.h index 1b9fddf..68295fc 100644 --- a/test/crypto/test_mac.h +++ b/test/crypto/test_mac.h @@ -14,8 +14,8 @@ int test_crypto_hashing_sha256() { char result_mac1[32]; char result_mac2[32]; - libp2p_crypto_hashing_sha256(test_array, array_length, result_mac1); - libp2p_crypto_hashing_sha256(test_array, array_length, result_mac2); + libp2p_crypto_hashing_sha256((unsigned char*)&test_array[0], array_length, (unsigned char*)&result_mac1[0]); + libp2p_crypto_hashing_sha256((unsigned char*)&test_array[0], array_length, (unsigned char*)&result_mac2[0]); if (memcmp(result_mac1, result_mac2, 32) != 0) return 0; diff --git a/test/crypto/test_rsa.h b/test/crypto/test_rsa.h index c12a49e..56e8728 100644 --- a/test/crypto/test_rsa.h +++ b/test/crypto/test_rsa.h @@ -200,7 +200,7 @@ int test_crypto_rsa_public_key_to_peer_id() { struct PublicKey public_key; public_key.type = KEYTYPE_RSA; public_key.data_size = private_key.public_key_length; - public_key.data = private_key.public_key_der; + public_key.data = (unsigned char*)private_key.public_key_der; if (!libp2p_crypto_public_key_to_peer_id(&public_key, &final_id )) goto exit; @@ -247,7 +247,7 @@ int test_crypto_rsa_signing() { size_t result_size; // sign the buffer - if (libp2p_crypto_rsa_sign(private_key, bytes, num_bytes, &result, &result_size) == 0) { + if (libp2p_crypto_rsa_sign(private_key, (char*)&bytes[0], num_bytes, &result, &result_size) == 0) { if (result != NULL) free(result); return 0; diff --git a/test/test_multistream.h b/test/test_multistream.h index 641f0a9..2ceeb44 100644 --- a/test/test_multistream.h +++ b/test/test_multistream.h @@ -41,7 +41,7 @@ int test_multistream_get_list() { goto exit; // try to respond something, ls command - const unsigned char* out = "ls\n"; + const unsigned char* out = (unsigned char*)"ls\n"; if (libp2p_net_multistream_write(&session, out, strlen((char*)out)) <= 0) goto exit; @@ -52,7 +52,7 @@ int test_multistream_get_list() { goto exit; filtered = malloc(response_size + 1); - strncpy(filtered, response, response_size); + strncpy(filtered, (char*)response, response_size); filtered[response_size] = 0; fprintf(stdout, "Response from multistream ls: %s", (char*)filtered); diff --git a/test/test_peer.h b/test/test_peer.h index 31668b2..ed125d3 100644 --- a/test/test_peer.h +++ b/test/test_peer.h @@ -44,7 +44,7 @@ int test_peerstore() { goto exit; // now try to retrieve it - results = libp2p_peerstore_get_peer_entry(peerstore, "ABC123", 6); + results = libp2p_peerstore_get_peer_entry(peerstore, (unsigned char*)"ABC123", 6); if (results == NULL || results->peer->id_size != 6) goto exit; diff --git a/test/test_record.h b/test/test_record.h index 02abf0c..f7a6f84 100644 --- a/test/test_record.h +++ b/test/test_record.h @@ -32,7 +32,7 @@ int test_record_protobuf() { struct Libp2pRecord* results = NULL; struct MultiAddress *ma = NULL, *ma_results = NULL; size_t protobuf_size = 0; - char* protobuf = NULL; + unsigned char* protobuf = NULL; int retVal = 0; // protobuf, unprotobuf @@ -52,11 +52,11 @@ int test_record_protobuf() { goto exit; if (strcmp(record->key, results->key) != 0) goto exit; - if (strncmp(record->value, results->value, results->value_size) != 0) + if (strncmp((char*)record->value, (char*)results->value, results->value_size) != 0) goto exit; if (strncmp(record->author, results->author, results->author_size) != 0) goto exit; - if (strncmp(record->signature, results->signature, results->signature_size) != 0) + if (strncmp((char*)record->signature, (char*)results->signature, results->signature_size) != 0) goto exit; if (strncmp(record->time_received, results->time_received, results->time_received_size) != 0) goto exit; @@ -100,16 +100,16 @@ int test_record_make_put_record() { rsa_public_key.der_length = rsa_private_key->public_key_length; // sign and protobuf - if (libp2p_record_make_put_record(&protobuf, &protobuf_size, rsa_private_key, record_key, record_value, record_value_length, 1) != 0) + if (libp2p_record_make_put_record(&protobuf, &protobuf_size, rsa_private_key, record_key, (char*)record_value, record_value_length, 1) != 0) goto exit; // unprotobuf and test - if (!libp2p_record_protobuf_decode(protobuf, protobuf_size, &results)) + if (!libp2p_record_protobuf_decode((unsigned char*)protobuf, protobuf_size, &results)) goto exit; if (strcmp(record_key, results->key) != 0) goto exit; - if (strncmp(record_value, results->value, results->value_size) != 0) + if (strncmp((char*)record_value, (char*)results->value, results->value_size) != 0) goto exit; if (results->key_size != strlen(record_key) || results->value_size != record_value_length) @@ -119,9 +119,9 @@ int test_record_make_put_record() { signature_buffer_length = results->key_size + results->value_size + results->author_size; signature_buffer = malloc(signature_buffer_length); strncpy(&signature_buffer[0], results->key, results->key_size); - strncpy(&signature_buffer[results->key_size], results->value, results->value_size); + strncpy(&signature_buffer[results->key_size], (char*)results->value, results->value_size); strncpy(&signature_buffer[results->key_size + results->value_size], results->author, results->author_size); - if (!libp2p_crypto_rsa_verify(&rsa_public_key, signature_buffer, signature_buffer_length, results->signature)) + if (!libp2p_crypto_rsa_verify(&rsa_public_key, (unsigned char*)signature_buffer, signature_buffer_length, results->signature)) goto exit; // cleanup @@ -174,7 +174,7 @@ int test_record_peer_protobuf() { goto exit; // check results - if (!strncmp(peer->id, result->id, peer->id_size) == 0) + if (strncmp(peer->id, result->id, peer->id_size) != 0) goto exit; if (peer->id_size != result->id_size @@ -185,7 +185,7 @@ int test_record_peer_protobuf() { multi_addr2 = (struct MultiAddress*)result->addr_head->item; if (multi_addr1->bsize != multi_addr2->bsize) goto exit; - if (strncmp(multi_addr1->bytes, multi_addr2->bytes, multi_addr2->bsize) != 0) + if (strncmp((char*)multi_addr1->bytes, (char*)multi_addr2->bytes, multi_addr2->bsize) != 0) goto exit; // cleanup @@ -236,11 +236,11 @@ int test_record_message_protobuf() { // protobuf buffer_len = libp2p_message_protobuf_encode_size(message); buffer = malloc(buffer_len); - if (!libp2p_message_protobuf_encode(message, buffer, buffer_len, &buffer_len)) + if (!libp2p_message_protobuf_encode(message, (unsigned char*)buffer, buffer_len, &buffer_len)) goto exit; // decode - if (!libp2p_message_protobuf_decode(buffer, buffer_len, &result)) + if (!libp2p_message_protobuf_decode((unsigned char*)buffer, buffer_len, &result)) goto exit; // check results diff --git a/test/test_secio.h b/test/test_secio.h index 301872a..fb56232 100644 --- a/test/test_secio.h +++ b/test/test_secio.h @@ -111,7 +111,7 @@ int test_secio_handshake() { } // now attempt an "ls" - if (libp2p_net_multistream_write(&secure_session, "ls\n", 3) == 0) { + if (libp2p_net_multistream_write(&secure_session, (unsigned char*)"ls\n", 3) == 0) { fprintf(stdout, "Unable to send ls to multistream\n"); goto exit; } @@ -163,7 +163,7 @@ int libp2p_secio_encrypt(const struct SessionContext* session, const unsigned ch int libp2p_secio_decrypt(const struct SessionContext* session, const unsigned char* incoming, size_t incoming_size, unsigned char** outgoing, size_t* outgoing_size); int test_secio_encrypt_decrypt() { - unsigned char* original = "This is a test message"; + unsigned char* original = (unsigned char*)"This is a test message"; int retVal = 0; unsigned char* encrypted = NULL; size_t encrypted_size = 0; @@ -178,9 +178,9 @@ int test_secio_encrypt_decrypt() { secure_session.local_stretched_key->cipher_key = (unsigned char*)"abcdefghijklmnopqrstuvwxyzabcdef"; secure_session.local_stretched_key->cipher_size = 32; secure_session.local_stretched_key->mac_size = 40; - secure_session.local_stretched_key->mac_key = "abcdefghijklmnopqrstuvwxyzabcdefghijklmn"; + secure_session.local_stretched_key->mac_key = (unsigned char*)"abcdefghijklmnopqrstuvwxyzabcdefghijklmn"; secure_session.local_stretched_key->iv_size = 16; - secure_session.local_stretched_key->iv = "abcdefghijklmnop"; + secure_session.local_stretched_key->iv = (unsigned char*)"abcdefghijklmnop"; secure_session.mac_function = NULL; if (!libp2p_secio_encrypt(&secure_session, original, strlen((char*)original), &encrypted, &encrypted_size)) { @@ -198,7 +198,7 @@ int test_secio_encrypt_decrypt() { goto exit; } - if (strncmp(original, results, strlen( (char*) original)) != 0) { + if (strncmp((char*)original, (char*)results, strlen( (char*) original)) != 0) { fprintf(stderr, "String comparison did not match\n"); goto exit; } @@ -232,7 +232,7 @@ int test_secio_exchange_protobuf_encode() { protobuf_size = libp2p_secio_exchange_protobuf_encode_size(exch); protobuf = malloc(protobuf_size); - libp2p_secio_exchange_protobuf_encode(exch, protobuf, protobuf_size, &actual_size); + libp2p_secio_exchange_protobuf_encode(exch, (unsigned char*)protobuf, protobuf_size, &actual_size); if (actual_size > protobuf_size) goto exit;