aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/tsi/transport_security_test_lib.cc
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-11-06 14:39:17 -0800
committerGravatar Yash Tibrewal <yashkt@google.com>2017-11-06 14:43:31 -0800
commit40422d5fa621624868280094efb2f01c2cd1352b (patch)
treecbb2baa955e11c03fa004e9e0f4f3037ba3d6150 /test/core/tsi/transport_security_test_lib.cc
parentaae4ca01a315a69fcf182d09aea1efdfcda13d48 (diff)
parente759d2ad7abdb0702970eeccc5f033ff4b2a4c7f (diff)
Merge master
Diffstat (limited to 'test/core/tsi/transport_security_test_lib.cc')
-rw-r--r--test/core/tsi/transport_security_test_lib.cc168
1 files changed, 84 insertions, 84 deletions
diff --git a/test/core/tsi/transport_security_test_lib.cc b/test/core/tsi/transport_security_test_lib.cc
index b98ab9ba05..af8316873e 100644
--- a/test/core/tsi/transport_security_test_lib.cc
+++ b/test/core/tsi/transport_security_test_lib.cc
@@ -27,14 +27,14 @@
#include "src/core/lib/security/transport/tsi_error.h"
#include "test/core/tsi/transport_security_test_lib.h"
-static void notification_signal(tsi_test_fixture *fixture) {
+static void notification_signal(tsi_test_fixture* fixture) {
gpr_mu_lock(&fixture->mu);
fixture->notified = true;
gpr_cv_signal(&fixture->cv);
gpr_mu_unlock(&fixture->mu);
}
-static void notification_wait(tsi_test_fixture *fixture) {
+static void notification_wait(tsi_test_fixture* fixture) {
gpr_mu_lock(&fixture->mu);
while (!fixture->notified) {
gpr_cv_wait(&fixture->cv, &fixture->mu, gpr_inf_future(GPR_CLOCK_REALTIME));
@@ -44,53 +44,53 @@ static void notification_wait(tsi_test_fixture *fixture) {
}
typedef struct handshaker_args {
- tsi_test_fixture *fixture;
- unsigned char *handshake_buffer;
+ tsi_test_fixture* fixture;
+ unsigned char* handshake_buffer;
size_t handshake_buffer_size;
bool is_client;
bool transferred_data;
bool appended_unused_bytes;
- grpc_error *error;
+ grpc_error* error;
} handshaker_args;
-static handshaker_args *handshaker_args_create(tsi_test_fixture *fixture,
+static handshaker_args* handshaker_args_create(tsi_test_fixture* fixture,
bool is_client) {
GPR_ASSERT(fixture != NULL);
GPR_ASSERT(fixture->config != NULL);
- handshaker_args *args =
- static_cast<handshaker_args *>(gpr_zalloc(sizeof(*args)));
+ handshaker_args* args =
+ static_cast<handshaker_args*>(gpr_zalloc(sizeof(*args)));
args->fixture = fixture;
args->handshake_buffer_size = fixture->handshake_buffer_size;
args->handshake_buffer =
- static_cast<unsigned char *>(gpr_zalloc(args->handshake_buffer_size));
+ static_cast<unsigned char*>(gpr_zalloc(args->handshake_buffer_size));
args->is_client = is_client;
args->error = GRPC_ERROR_NONE;
return args;
}
-static void handshaker_args_destroy(handshaker_args *args) {
+static void handshaker_args_destroy(handshaker_args* args) {
gpr_free(args->handshake_buffer);
GRPC_ERROR_UNREF(args->error);
gpr_free(args);
}
-static void do_handshaker_next(handshaker_args *args);
+static void do_handshaker_next(handshaker_args* args);
-static void setup_handshakers(tsi_test_fixture *fixture) {
+static void setup_handshakers(tsi_test_fixture* fixture) {
GPR_ASSERT(fixture != NULL);
GPR_ASSERT(fixture->vtable != NULL);
GPR_ASSERT(fixture->vtable->setup_handshakers != NULL);
fixture->vtable->setup_handshakers(fixture);
}
-static void check_unused_bytes(tsi_test_fixture *fixture) {
- tsi_handshaker_result *result_with_unused_bytes =
+static void check_unused_bytes(tsi_test_fixture* fixture) {
+ tsi_handshaker_result* result_with_unused_bytes =
fixture->has_client_finished_first ? fixture->server_result
: fixture->client_result;
- tsi_handshaker_result *result_without_unused_bytes =
+ tsi_handshaker_result* result_without_unused_bytes =
fixture->has_client_finished_first ? fixture->client_result
: fixture->server_result;
- const unsigned char *bytes = NULL;
+ const unsigned char* bytes = NULL;
size_t bytes_size = 0;
GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(
result_with_unused_bytes, &bytes, &bytes_size) == TSI_OK);
@@ -102,7 +102,7 @@ static void check_unused_bytes(tsi_test_fixture *fixture) {
GPR_ASSERT(bytes == NULL);
}
-static void check_handshake_results(tsi_test_fixture *fixture) {
+static void check_handshake_results(tsi_test_fixture* fixture) {
GPR_ASSERT(fixture != NULL);
GPR_ASSERT(fixture->vtable != NULL);
GPR_ASSERT(fixture->vtable->check_handshaker_peers != NULL);
@@ -120,15 +120,15 @@ static void check_handshake_results(tsi_test_fixture *fixture) {
}
}
-static void send_bytes_to_peer(tsi_test_fixture *fixture,
- const unsigned char *buf, size_t buf_size,
+static void send_bytes_to_peer(tsi_test_fixture* fixture,
+ const unsigned char* buf, size_t buf_size,
bool is_client) {
GPR_ASSERT(fixture != NULL);
GPR_ASSERT(buf != NULL);
- uint8_t *channel =
+ uint8_t* channel =
is_client ? fixture->server_channel : fixture->client_channel;
GPR_ASSERT(channel != NULL);
- size_t *bytes_written = is_client ? &fixture->bytes_written_to_server_channel
+ size_t* bytes_written = is_client ? &fixture->bytes_written_to_server_channel
: &fixture->bytes_written_to_client_channel;
GPR_ASSERT(bytes_written != NULL);
GPR_ASSERT(*bytes_written + buf_size <= TSI_TEST_DEFAULT_CHANNEL_SIZE);
@@ -137,13 +137,13 @@ static void send_bytes_to_peer(tsi_test_fixture *fixture,
*bytes_written += buf_size;
}
-static void maybe_append_unused_bytes(handshaker_args *args) {
+static void maybe_append_unused_bytes(handshaker_args* args) {
GPR_ASSERT(args != NULL);
GPR_ASSERT(args->fixture != NULL);
- tsi_test_fixture *fixture = args->fixture;
+ tsi_test_fixture* fixture = args->fixture;
if (fixture->test_unused_bytes && !args->appended_unused_bytes) {
args->appended_unused_bytes = true;
- send_bytes_to_peer(fixture, (const unsigned char *)TSI_TEST_UNUSED_BYTES,
+ send_bytes_to_peer(fixture, (const unsigned char*)TSI_TEST_UNUSED_BYTES,
strlen(TSI_TEST_UNUSED_BYTES), args->is_client);
if (fixture->client_result != NULL && fixture->server_result == NULL) {
fixture->has_client_finished_first = true;
@@ -151,18 +151,18 @@ static void maybe_append_unused_bytes(handshaker_args *args) {
}
}
-static void receive_bytes_from_peer(tsi_test_fixture *fixture,
- unsigned char **buf, size_t *buf_size,
+static void receive_bytes_from_peer(tsi_test_fixture* fixture,
+ unsigned char** buf, size_t* buf_size,
bool is_client) {
GPR_ASSERT(fixture != NULL);
GPR_ASSERT(*buf != NULL);
GPR_ASSERT(buf_size != NULL);
- uint8_t *channel =
+ uint8_t* channel =
is_client ? fixture->client_channel : fixture->server_channel;
GPR_ASSERT(channel != NULL);
- size_t *bytes_read = is_client ? &fixture->bytes_read_from_client_channel
+ size_t* bytes_read = is_client ? &fixture->bytes_read_from_client_channel
: &fixture->bytes_read_from_server_channel;
- size_t *bytes_written = is_client ? &fixture->bytes_written_to_client_channel
+ size_t* bytes_written = is_client ? &fixture->bytes_written_to_client_channel
: &fixture->bytes_written_to_server_channel;
GPR_ASSERT(bytes_read != NULL);
GPR_ASSERT(bytes_written != NULL);
@@ -175,22 +175,22 @@ static void receive_bytes_from_peer(tsi_test_fixture *fixture,
*bytes_read += to_read;
}
-static void send_message_to_peer(tsi_test_fixture *fixture,
- tsi_frame_protector *protector,
+static void send_message_to_peer(tsi_test_fixture* fixture,
+ tsi_frame_protector* protector,
bool is_client) {
/* Initialization. */
GPR_ASSERT(fixture != NULL);
GPR_ASSERT(fixture->config != NULL);
GPR_ASSERT(protector != NULL);
- tsi_test_frame_protector_config *config = fixture->config;
- unsigned char *protected_buffer =
- static_cast<unsigned char *>(gpr_zalloc(config->protected_buffer_size));
+ tsi_test_frame_protector_config* config = fixture->config;
+ unsigned char* protected_buffer =
+ static_cast<unsigned char*>(gpr_zalloc(config->protected_buffer_size));
size_t message_size =
is_client ? config->client_message_size : config->server_message_size;
- uint8_t *message =
+ uint8_t* message =
is_client ? config->client_message : config->server_message;
GPR_ASSERT(message != NULL);
- const unsigned char *message_bytes = (const unsigned char *)message;
+ const unsigned char* message_bytes = (const unsigned char*)message;
tsi_result result = TSI_OK;
/* Do protect and send protected data to peer. */
while (message_size > 0 && result == TSI_OK) {
@@ -225,25 +225,25 @@ static void send_message_to_peer(tsi_test_fixture *fixture,
gpr_free(protected_buffer);
}
-static void receive_message_from_peer(tsi_test_fixture *fixture,
- tsi_frame_protector *protector,
- unsigned char *message,
- size_t *bytes_received, bool is_client) {
+static void receive_message_from_peer(tsi_test_fixture* fixture,
+ tsi_frame_protector* protector,
+ unsigned char* message,
+ size_t* bytes_received, bool is_client) {
/* Initialization. */
GPR_ASSERT(fixture != NULL);
GPR_ASSERT(protector != NULL);
GPR_ASSERT(message != NULL);
GPR_ASSERT(bytes_received != NULL);
GPR_ASSERT(fixture->config != NULL);
- tsi_test_frame_protector_config *config = fixture->config;
+ tsi_test_frame_protector_config* config = fixture->config;
size_t read_offset = 0;
size_t message_offset = 0;
size_t read_from_peer_size = 0;
tsi_result result = TSI_OK;
bool done = false;
- unsigned char *read_buffer = static_cast<unsigned char *>(
+ unsigned char* read_buffer = static_cast<unsigned char*>(
gpr_zalloc(config->read_buffer_allocated_size));
- unsigned char *message_buffer = static_cast<unsigned char *>(
+ unsigned char* message_buffer = static_cast<unsigned char*>(
gpr_zalloc(config->message_buffer_allocated_size));
/* Do unprotect on data received from peer. */
while (!done && result == TSI_OK) {
@@ -282,15 +282,15 @@ static void receive_message_from_peer(tsi_test_fixture *fixture,
gpr_free(message_buffer);
}
-grpc_error *on_handshake_next_done(tsi_result result, void *user_data,
- const unsigned char *bytes_to_send,
+grpc_error* on_handshake_next_done(tsi_result result, void* user_data,
+ const unsigned char* bytes_to_send,
size_t bytes_to_send_size,
- tsi_handshaker_result *handshaker_result) {
- handshaker_args *args = (handshaker_args *)user_data;
+ tsi_handshaker_result* handshaker_result) {
+ handshaker_args* args = (handshaker_args*)user_data;
GPR_ASSERT(args != NULL);
GPR_ASSERT(args->fixture != NULL);
- tsi_test_fixture *fixture = args->fixture;
- grpc_error *error = GRPC_ERROR_NONE;
+ tsi_test_fixture* fixture = args->fixture;
+ grpc_error* error = GRPC_ERROR_NONE;
/* Read more data if we need to. */
if (result == TSI_INCOMPLETE_DATA) {
GPR_ASSERT(bytes_to_send_size == 0);
@@ -304,7 +304,7 @@ grpc_error *on_handshake_next_done(tsi_result result, void *user_data,
}
/* Update handshaker result. */
if (handshaker_result != NULL) {
- tsi_handshaker_result **result_to_write =
+ tsi_handshaker_result** result_to_write =
args->is_client ? &fixture->client_result : &fixture->server_result;
GPR_ASSERT(*result_to_write == NULL);
*result_to_write = handshaker_result;
@@ -323,17 +323,17 @@ grpc_error *on_handshake_next_done(tsi_result result, void *user_data,
}
static void on_handshake_next_done_wrapper(
- tsi_result result, void *user_data, const unsigned char *bytes_to_send,
- size_t bytes_to_send_size, tsi_handshaker_result *handshaker_result) {
- handshaker_args *args = (handshaker_args *)user_data;
+ tsi_result result, void* user_data, const unsigned char* bytes_to_send,
+ size_t bytes_to_send_size, tsi_handshaker_result* handshaker_result) {
+ handshaker_args* args = (handshaker_args*)user_data;
args->error = on_handshake_next_done(result, user_data, bytes_to_send,
bytes_to_send_size, handshaker_result);
}
-static bool is_handshake_finished_properly(handshaker_args *args) {
+static bool is_handshake_finished_properly(handshaker_args* args) {
GPR_ASSERT(args != NULL);
GPR_ASSERT(args->fixture != NULL);
- tsi_test_fixture *fixture = args->fixture;
+ tsi_test_fixture* fixture = args->fixture;
if ((args->is_client && fixture->client_result != NULL) ||
(!args->is_client && fixture->server_result != NULL)) {
return true;
@@ -341,18 +341,18 @@ static bool is_handshake_finished_properly(handshaker_args *args) {
return false;
}
-static void do_handshaker_next(handshaker_args *args) {
+static void do_handshaker_next(handshaker_args* args) {
/* Initialization. */
GPR_ASSERT(args != NULL);
GPR_ASSERT(args->fixture != NULL);
- tsi_test_fixture *fixture = args->fixture;
- tsi_handshaker *handshaker =
+ tsi_test_fixture* fixture = args->fixture;
+ tsi_handshaker* handshaker =
args->is_client ? fixture->client_handshaker : fixture->server_handshaker;
if (is_handshake_finished_properly(args)) {
return;
}
- tsi_handshaker_result *handshaker_result = NULL;
- unsigned char *bytes_to_send = NULL;
+ tsi_handshaker_result* handshaker_result = NULL;
+ unsigned char* bytes_to_send = NULL;
size_t bytes_to_send_size = 0;
tsi_result result = TSI_OK;
/* Receive data from peer, if available. */
@@ -365,7 +365,7 @@ static void do_handshaker_next(handshaker_args *args) {
}
/* Peform handshaker next. */
result = tsi_handshaker_next(handshaker, args->handshake_buffer, buf_size,
- (const unsigned char **)&bytes_to_send,
+ (const unsigned char**)&bytes_to_send,
&bytes_to_send_size, &handshaker_result,
&on_handshake_next_done_wrapper, args);
if (result != TSI_ASYNC) {
@@ -379,12 +379,12 @@ static void do_handshaker_next(handshaker_args *args) {
notification_wait(fixture);
}
-void tsi_test_do_handshake(tsi_test_fixture *fixture) {
+void tsi_test_do_handshake(tsi_test_fixture* fixture) {
/* Initializaiton. */
setup_handshakers(fixture);
- handshaker_args *client_args =
+ handshaker_args* client_args =
handshaker_args_create(fixture, true /* is_client */);
- handshaker_args *server_args =
+ handshaker_args* server_args =
handshaker_args_create(fixture, false /* is_client */);
/* Do handshake. */
do {
@@ -407,13 +407,13 @@ void tsi_test_do_handshake(tsi_test_fixture *fixture) {
handshaker_args_destroy(server_args);
}
-void tsi_test_do_round_trip(tsi_test_fixture *fixture) {
+void tsi_test_do_round_trip(tsi_test_fixture* fixture) {
/* Initialization. */
GPR_ASSERT(fixture != NULL);
GPR_ASSERT(fixture->config != NULL);
- tsi_test_frame_protector_config *config = fixture->config;
- tsi_frame_protector *client_frame_protector = NULL;
- tsi_frame_protector *server_frame_protector = NULL;
+ tsi_test_frame_protector_config* config = fixture->config;
+ tsi_frame_protector* client_frame_protector = NULL;
+ tsi_frame_protector* server_frame_protector = NULL;
/* Perform handshake. */
tsi_test_do_handshake(fixture);
/* Create frame protectors.*/
@@ -435,8 +435,8 @@ void tsi_test_do_round_trip(tsi_test_fixture *fixture) {
&server_frame_protector) == TSI_OK);
/* Client sends a message to server. */
send_message_to_peer(fixture, client_frame_protector, true /* is_client */);
- unsigned char *server_received_message =
- static_cast<unsigned char *>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE));
+ unsigned char* server_received_message =
+ static_cast<unsigned char*>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE));
size_t server_received_message_size = 0;
receive_message_from_peer(
fixture, server_frame_protector, server_received_message,
@@ -446,8 +446,8 @@ void tsi_test_do_round_trip(tsi_test_fixture *fixture) {
server_received_message_size) == 0);
/* Server sends a message to client. */
send_message_to_peer(fixture, server_frame_protector, false /* is_client */);
- unsigned char *client_received_message =
- static_cast<unsigned char *>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE));
+ unsigned char* client_received_message =
+ static_cast<unsigned char*>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE));
size_t client_received_message_size = 0;
receive_message_from_peer(
fixture, client_frame_protector, client_received_message,
@@ -462,18 +462,18 @@ void tsi_test_do_round_trip(tsi_test_fixture *fixture) {
gpr_free(client_received_message);
}
-static unsigned char *generate_random_message(size_t size) {
+static unsigned char* generate_random_message(size_t size) {
size_t i;
unsigned char chars[] = "abcdefghijklmnopqrstuvwxyz1234567890";
- unsigned char *output =
- static_cast<unsigned char *>(gpr_zalloc(sizeof(unsigned char) * size));
+ unsigned char* output =
+ static_cast<unsigned char*>(gpr_zalloc(sizeof(unsigned char) * size));
for (i = 0; i < size - 1; ++i) {
output[i] = chars[rand() % (int)(sizeof(chars) - 1)];
}
return output;
}
-tsi_test_frame_protector_config *tsi_test_frame_protector_config_create(
+tsi_test_frame_protector_config* tsi_test_frame_protector_config_create(
bool use_default_read_buffer_allocated_size,
bool use_default_message_buffer_allocated_size,
bool use_default_protected_buffer_size, bool use_default_client_message,
@@ -481,8 +481,8 @@ tsi_test_frame_protector_config *tsi_test_frame_protector_config_create(
bool use_default_client_max_output_protected_frame_size,
bool use_default_server_max_output_protected_frame_size,
bool use_default_handshake_buffer_size) {
- tsi_test_frame_protector_config *config =
- static_cast<tsi_test_frame_protector_config *>(
+ tsi_test_frame_protector_config* config =
+ static_cast<tsi_test_frame_protector_config*>(
gpr_zalloc(sizeof(*config)));
/* Set the value for read_buffer_allocated_size. */
config->read_buffer_allocated_size =
@@ -532,7 +532,7 @@ tsi_test_frame_protector_config *tsi_test_frame_protector_config_create(
}
void tsi_test_frame_protector_config_set_buffer_size(
- tsi_test_frame_protector_config *config, size_t read_buffer_allocated_size,
+ tsi_test_frame_protector_config* config, size_t read_buffer_allocated_size,
size_t message_buffer_allocated_size, size_t protected_buffer_size,
size_t client_max_output_protected_frame_size,
size_t server_max_output_protected_frame_size) {
@@ -547,21 +547,21 @@ void tsi_test_frame_protector_config_set_buffer_size(
}
void tsi_test_frame_protector_config_destroy(
- tsi_test_frame_protector_config *config) {
+ tsi_test_frame_protector_config* config) {
GPR_ASSERT(config != NULL);
gpr_free(config->client_message);
gpr_free(config->server_message);
gpr_free(config);
}
-void tsi_test_fixture_init(tsi_test_fixture *fixture) {
+void tsi_test_fixture_init(tsi_test_fixture* fixture) {
fixture->config = tsi_test_frame_protector_config_create(
true, true, true, true, true, true, true, true);
fixture->handshake_buffer_size = TSI_TEST_DEFAULT_BUFFER_SIZE;
fixture->client_channel =
- static_cast<uint8_t *>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE));
+ static_cast<uint8_t*>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE));
fixture->server_channel =
- static_cast<uint8_t *>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE));
+ static_cast<uint8_t*>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE));
fixture->bytes_written_to_client_channel = 0;
fixture->bytes_written_to_server_channel = 0;
fixture->bytes_read_from_client_channel = 0;
@@ -573,7 +573,7 @@ void tsi_test_fixture_init(tsi_test_fixture *fixture) {
fixture->notified = false;
}
-void tsi_test_fixture_destroy(tsi_test_fixture *fixture) {
+void tsi_test_fixture_destroy(tsi_test_fixture* fixture) {
GPR_ASSERT(fixture != NULL);
tsi_test_frame_protector_config_destroy(fixture->config);
tsi_handshaker_destroy(fixture->client_handshaker);