Fixed warnings
This commit is contained in:
parent
ffd27eb062
commit
dfb1aba247
22 changed files with 66 additions and 64 deletions
10
crypto/aes.c
10
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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -14,6 +14,8 @@ int libp2p_record_message_handle(struct Libp2pPeer* peer, struct Libp2pMessage*
|
|||
switch (message->message_type) {
|
||||
case (MESSAGE_TYPE_PING):
|
||||
return libp2p_record_handler_ping(peer, message);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue