From 265cc7fe4418cb119ef350be5ec41b2eee8e953a Mon Sep 17 00:00:00 2001 From: Dmitriy Musatkin Date: Fri, 6 Oct 2023 15:27:27 -0700 Subject: [PATCH] reorder fields --- include/aws/io/pem.h | 8 ++++---- source/darwin/darwin_pki_utils.c | 6 +++--- source/pem.c | 14 +++++++------- source/windows/windows_pki_utils.c | 6 +++--- tests/pem_test.c | 18 +++++++++--------- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/aws/io/pem.h b/include/aws/io/pem.h index ec76c6b61..5d17e285e 100644 --- a/include/aws/io/pem.h +++ b/include/aws/io/pem.h @@ -75,9 +75,9 @@ AWS_IO_API void aws_pem_objects_clean_up(struct aws_array_list *pem_objects); * not to call this in the middle of something that needs to be fast or resource sensitive. */ AWS_IO_API int aws_pem_objects_init_from_file_contents( + struct aws_array_list *pem_objects, struct aws_allocator *alloc, - struct aws_byte_cursor pem_cursor, - struct aws_array_list *out_pem_objects); + struct aws_byte_cursor pem_cursor); /** * Decodes PEM data from file and reads objects sequentially adding them to pem_objects. @@ -91,9 +91,9 @@ AWS_IO_API int aws_pem_objects_init_from_file_contents( * not to call this in the middle of something that needs to be fast or resource sensitive. */ AWS_IO_API int aws_pem_objects_init_from_file_path( + struct aws_array_list *pem_objects, struct aws_allocator *allocator, - const char *filename, - struct aws_array_list *out_pem_objects); + const char *filename); AWS_EXTERN_C_END #endif /* AWS_IO_PEM_H */ diff --git a/source/darwin/darwin_pki_utils.c b/source/darwin/darwin_pki_utils.c index f07aaa018..7b60bab2c 100644 --- a/source/darwin/darwin_pki_utils.c +++ b/source/darwin/darwin_pki_utils.c @@ -40,7 +40,7 @@ int aws_import_ecc_key_into_keychain( struct aws_array_list decoded_key_buffer_list; /* Decode PEM format file to DER format */ - if (aws_pem_objects_init_from_file_contents(alloc, *private_key, &decoded_key_buffer_list)) { + if (aws_pem_objects_init_from_file_contents(&decoded_key_buffer_list, alloc, *private_key)) { AWS_LOGF_ERROR(AWS_LS_IO_PKI, "static: Failed to decode PEM private key to DER format."); goto ecc_import_cleanup; } @@ -203,7 +203,7 @@ int aws_import_public_and_private_keys_to_identity( "Using key from Keychain instead of the one provided."); struct aws_array_list cert_chain_list; - if (aws_pem_objects_init_from_file_contents(alloc, *public_cert_chain, &cert_chain_list)) { + if (aws_pem_objects_init_from_file_contents(&cert_chain_list, alloc, *public_cert_chain)) { AWS_LOGF_ERROR(AWS_LS_IO_PKI, "static: decoding certificate PEM failed."); aws_pem_objects_clean_up(&cert_chain_list); result = AWS_OP_ERR; @@ -314,7 +314,7 @@ int aws_import_trusted_certificates( struct aws_array_list certificates; - if (aws_pem_objects_init_from_file_contents(alloc, *certificates_blob, &certificates)) { + if (aws_pem_objects_init_from_file_contents(&certificates, alloc, *certificates_blob)) { AWS_LOGF_ERROR(AWS_LS_IO_PKI, "static: decoding CA PEM failed."); aws_array_list_clean_up(&certificates); return AWS_OP_ERR; diff --git a/source/pem.c b/source/pem.c index ba0cfc9d7..dd8eaf56a 100644 --- a/source/pem.c +++ b/source/pem.c @@ -364,9 +364,9 @@ static int s_convert_pem_to_raw_base64( } int aws_pem_objects_init_from_file_contents( + struct aws_array_list *pem_objects, struct aws_allocator *allocator, - struct aws_byte_cursor pem_cursor, - struct aws_array_list *pem_objects) { + struct aws_byte_cursor pem_cursor) { AWS_PRECONDITION(allocator); AWS_PRECONDITION(pem_objects != NULL); @@ -413,19 +413,19 @@ int aws_pem_objects_init_from_file_contents( } int aws_pem_objects_init_from_file_path( - struct aws_allocator *alloc, - const char *filename, - struct aws_array_list *pem_objects) { + struct aws_array_list *pem_objects, + struct aws_allocator *allocator, + const char *filename) { struct aws_byte_buf raw_file_buffer; - if (aws_byte_buf_init_from_file(&raw_file_buffer, alloc, filename)) { + if (aws_byte_buf_init_from_file(&raw_file_buffer, allocator, filename)) { AWS_LOGF_ERROR(AWS_LS_IO_PEM, "Failed to read file %s.", filename); return AWS_OP_ERR; } AWS_ASSERT(raw_file_buffer.buffer); struct aws_byte_cursor file_cursor = aws_byte_cursor_from_buf(&raw_file_buffer); - if (aws_pem_objects_init_from_file_contents(alloc, file_cursor, pem_objects)) { + if (aws_pem_objects_init_from_file_contents(pem_objects, allocator, file_cursor)) { aws_byte_buf_clean_up_secure(&raw_file_buffer); AWS_LOGF_ERROR(AWS_LS_IO_PEM, "Failed to decode PEM file %s.", filename); return AWS_OP_ERR; diff --git a/source/windows/windows_pki_utils.c b/source/windows/windows_pki_utils.c index 1dbbfd3d4..e1c47d548 100644 --- a/source/windows/windows_pki_utils.c +++ b/source/windows/windows_pki_utils.c @@ -184,7 +184,7 @@ int aws_import_trusted_certificates( *cert_store = NULL; int result = AWS_OP_ERR; - if (aws_pem_objects_init_from_file_contents(alloc, *certificates_blob, &certificates)) { + if (aws_pem_objects_init_from_file_contents(&certificates, alloc, *certificates_blob)) { goto clean_up; } @@ -560,13 +560,13 @@ int aws_import_key_pair_to_cert_context( int result = AWS_OP_ERR; BYTE *key = NULL; - if (aws_pem_objects_init_from_file_contents(alloc, *public_cert_chain, &certificates)) { + if (aws_pem_objects_init_from_file_contents(&certificates, alloc, *public_cert_chain)) { AWS_LOGF_ERROR( AWS_LS_IO_PKI, "static: failed to decode cert pem to buffer list with error %d", (int)aws_last_error()); goto clean_up; } - if (aws_pem_objects_init_from_file_contents(alloc, *private_key, &private_keys)) { + if (aws_pem_objects_init_from_file_contents(&private_keys, alloc, *private_key)) { AWS_LOGF_ERROR( AWS_LS_IO_PKI, "static: failed to decode key pem to buffer list with error %d", (int)aws_last_error()); goto clean_up; diff --git a/tests/pem_test.c b/tests/pem_test.c index 45d97f468..767ef04a0 100644 --- a/tests/pem_test.c +++ b/tests/pem_test.c @@ -208,7 +208,7 @@ static int s_test_pem_cert_parse_from_file(struct aws_allocator *allocator, void }; struct aws_array_list output_list; - ASSERT_SUCCESS(aws_pem_objects_init_from_file_path(allocator, "testparse.crt", &output_list)); + ASSERT_SUCCESS(aws_pem_objects_init_from_file_path(&output_list, allocator, "testparse.crt")); ASSERT_UINT_EQUALS(1, aws_array_list_length(&output_list)); struct aws_pem_object *pem_object = NULL; @@ -298,7 +298,7 @@ static int s_test_pem_private_key_parse_from_file(struct aws_allocator *allocato struct aws_array_list output_list; - ASSERT_SUCCESS(aws_pem_objects_init_from_file_path(allocator, "unittests.key", &output_list)); + ASSERT_SUCCESS(aws_pem_objects_init_from_file_path(&output_list, allocator, "unittests.key")); ASSERT_UINT_EQUALS(1, aws_array_list_length(&output_list)); struct aws_pem_object *pem_object = NULL; @@ -374,7 +374,7 @@ static int s_test_pem_single_cert_parse(struct aws_allocator *allocator, void *c struct aws_byte_cursor pem_data = aws_byte_cursor_from_c_str(s_rsa_1024_sha224_client_crt_pem); struct aws_array_list output_list; - ASSERT_SUCCESS(aws_pem_objects_init_from_file_contents(allocator, pem_data, &output_list)); + ASSERT_SUCCESS(aws_pem_objects_init_from_file_contents(&output_list, allocator, pem_data)); ASSERT_UINT_EQUALS(1, aws_array_list_length(&output_list)); struct aws_pem_object *pem_object = NULL; @@ -586,7 +586,7 @@ static int s_test_pem_cert_chain_parse(struct aws_allocator *allocator, void *ct struct aws_byte_cursor pem_data = aws_byte_cursor_from_c_str(s_rsa_2048_pkcs1_crt_pem); struct aws_array_list output_list; - ASSERT_SUCCESS(aws_pem_objects_init_from_file_contents(allocator, pem_data, &output_list)); + ASSERT_SUCCESS(aws_pem_objects_init_from_file_contents(&output_list, allocator, pem_data)); ASSERT_UINT_EQUALS(3, aws_array_list_length(&output_list)); struct aws_pem_object *pem_object = NULL; @@ -714,7 +714,7 @@ static int s_test_pem_private_key_parse(struct aws_allocator *allocator, void *c struct aws_byte_cursor pem_data = aws_byte_cursor_from_c_str(s_private_key_pem); struct aws_array_list output_list; - ASSERT_SUCCESS(aws_pem_objects_init_from_file_contents(allocator, pem_data, &output_list)); + ASSERT_SUCCESS(aws_pem_objects_init_from_file_contents(&output_list, allocator, pem_data)); ASSERT_UINT_EQUALS(1, aws_array_list_length(&output_list)); struct aws_pem_object *pem_object = NULL; @@ -942,7 +942,7 @@ static int s_test_pem_cert_chain_comments_and_whitespace(struct aws_allocator *a struct aws_byte_cursor pem_data = aws_byte_cursor_from_c_str(s_pem_data_str); struct aws_array_list output_list; - ASSERT_SUCCESS(aws_pem_objects_init_from_file_contents(allocator, pem_data, &output_list)); + ASSERT_SUCCESS(aws_pem_objects_init_from_file_contents(&output_list, allocator, pem_data)); ASSERT_UINT_EQUALS(3, aws_array_list_length(&output_list)); struct aws_pem_object *pem_object = NULL; @@ -990,7 +990,7 @@ static int s_test_pem_invalid_parse(struct aws_allocator *allocator, void *ctx) struct aws_byte_cursor pem_data = aws_byte_cursor_from_c_str(s_invalid_pem); struct aws_array_list output_list; - ASSERT_ERROR(AWS_ERROR_PEM_MALFORMED, aws_pem_objects_init_from_file_contents(allocator, pem_data, &output_list)); + ASSERT_ERROR(AWS_ERROR_PEM_MALFORMED, aws_pem_objects_init_from_file_contents(&output_list, allocator, pem_data)); ASSERT_UINT_EQUALS(0, aws_array_list_length(&output_list)); aws_array_list_clean_up(&output_list); @@ -1022,7 +1022,7 @@ static int s_test_pem_valid_data_invalid_parse(struct aws_allocator *allocator, struct aws_byte_cursor pem_data = aws_byte_cursor_from_c_str(s_invalid_data); struct aws_array_list output_list; - ASSERT_ERROR(AWS_ERROR_PEM_MALFORMED, aws_pem_objects_init_from_file_contents(allocator, pem_data, &output_list)); + ASSERT_ERROR(AWS_ERROR_PEM_MALFORMED, aws_pem_objects_init_from_file_contents(&output_list, allocator, pem_data)); ASSERT_UINT_EQUALS(0, aws_array_list_length(&output_list)); aws_array_list_clean_up(&output_list); @@ -1093,7 +1093,7 @@ static int s_test_pem_invalid_in_chain_parse(struct aws_allocator *allocator, vo struct aws_byte_cursor pem_data = aws_byte_cursor_from_c_str(s_invalid_data); struct aws_array_list output_list; - ASSERT_ERROR(AWS_ERROR_PEM_MALFORMED, aws_pem_objects_init_from_file_contents(allocator, pem_data, &output_list)); + ASSERT_ERROR(AWS_ERROR_PEM_MALFORMED, aws_pem_objects_init_from_file_contents(&output_list, allocator, pem_data)); ASSERT_UINT_EQUALS(0, aws_array_list_length(&output_list)); aws_array_list_clean_up(&output_list);