Skip to content

Commit

Permalink
reorder fields
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyMusatkin committed Oct 6, 2023
1 parent c1e677a commit 265cc7f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions include/aws/io/pem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 */
6 changes: 3 additions & 3 deletions source/darwin/darwin_pki_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions source/pem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions source/windows/windows_pki_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand 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;
Expand Down
18 changes: 9 additions & 9 deletions tests/pem_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 265cc7f

Please sign in to comment.