From 095679c6a45bdec63832575f95d81ae4a3b9312c Mon Sep 17 00:00:00 2001 From: Dmitriy Musatkin Date: Fri, 6 Oct 2023 13:26:33 -0700 Subject: [PATCH] make type a string --- include/aws/io/pem.h | 4 ++-- source/pem.c | 8 ++++---- tests/pem_test.c | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/aws/io/pem.h b/include/aws/io/pem.h index ed9d5913a..0f2e7841f 100644 --- a/include/aws/io/pem.h +++ b/include/aws/io/pem.h @@ -49,11 +49,11 @@ enum aws_pem_object_type { * decoding for each object). * type will be set to object type or to AWS_PEM_TYPE_UNKNOWN if it could not * figure out type. - * type_buf are the types bytes, i.e. the string between -----BEGIN and ----- + * type_string is the string between -----BEGIN and ----- */ struct aws_pem_object { enum aws_pem_object_type type; - struct aws_byte_buf type_buf; + struct aws_string *type_string; struct aws_byte_buf data; }; diff --git a/source/pem.c b/source/pem.c index b1ac9ae4c..a2205c9d6 100644 --- a/source/pem.c +++ b/source/pem.c @@ -147,7 +147,7 @@ void aws_pem_objects_clean_up(struct aws_array_list *cert_chain) { if (pem_obj_ptr != NULL) { aws_byte_buf_clean_up_secure(&pem_obj_ptr->data); - aws_byte_buf_clean_up_secure(&pem_obj_ptr->type_buf); + aws_string_destroy(&pem_obj_ptr->type_string); } } @@ -312,10 +312,10 @@ static int s_convert_pem_to_raw_base64( aws_byte_buf_init(¤t_obj_buf, allocator, current_obj_len); } else { - struct aws_byte_buf type_buf; - aws_byte_buf_init_copy_from_cursor(&type_buf, allocator, current_obj_type_cur); struct aws_pem_object pem_object = { - .data = current_obj_buf, .type_buf = type_buf, .type = current_obj_type}; + .data = current_obj_buf, + .type_string = aws_string_new_from_cursor(allocator, ¤t_obj_type_cur), + .type = current_obj_type,}; if (aws_array_list_push_back(pem_objects, &pem_object)) { goto on_end_of_loop; diff --git a/tests/pem_test.c b/tests/pem_test.c index 8a4822828..12d4426ca 100644 --- a/tests/pem_test.c +++ b/tests/pem_test.c @@ -216,7 +216,7 @@ static int s_test_pem_cert_parse_from_file(struct aws_allocator *allocator, void struct aws_pem_object *pem_object = NULL; aws_array_list_get_at_ptr(&output_list, (void **)&pem_object, 0); ASSERT_BIN_ARRAYS_EQUALS(s_expected, sizeof(s_expected), pem_object->data.buffer, pem_object->data.len); - ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&pem_object->type_buf), "CERTIFICATE"); + ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_string(&pem_object->type_string), "CERTIFICATE"); ASSERT_INT_EQUALS(AWS_PEM_TYPE_X509, pem_object->type); aws_pem_objects_clean_up(&output_list); @@ -308,7 +308,7 @@ static int s_test_pem_private_key_parse_from_file(struct aws_allocator *allocato struct aws_pem_object *pem_object = NULL; aws_array_list_get_at_ptr(&output_list, (void **)&pem_object, 0); ASSERT_BIN_ARRAYS_EQUALS(s_expected, sizeof(s_expected), pem_object->data.buffer, pem_object->data.len); - ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&pem_object->type_buf), "RSA PRIVATE KEY"); + ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_string(&pem_object->type_string), "RSA PRIVATE KEY"); ASSERT_INT_EQUALS(AWS_PEM_TYPE_PRIVATE_RSA_PKCS1, pem_object->type); aws_pem_objects_clean_up(&output_list); @@ -386,7 +386,7 @@ static int s_test_pem_single_cert_parse(struct aws_allocator *allocator, void *c struct aws_pem_object *pem_object = NULL; aws_array_list_get_at_ptr(&output_list, (void **)&pem_object, 0); ASSERT_BIN_ARRAYS_EQUALS(s_expected, sizeof(s_expected), pem_object->data.buffer, pem_object->data.len); - ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&pem_object->type_buf), "CERTIFICATE"); + ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_string(&pem_object->type_string), "CERTIFICATE"); ASSERT_INT_EQUALS(AWS_PEM_TYPE_X509, pem_object->type); aws_pem_objects_clean_up(&output_list); @@ -601,16 +601,16 @@ static int s_test_pem_cert_chain_parse(struct aws_allocator *allocator, void *ct aws_array_list_get_at_ptr(&output_list, (void **)&pem_object, 0); ASSERT_BIN_ARRAYS_EQUALS( s_expected_intermediate_1, sizeof(s_expected_intermediate_1), pem_object->data.buffer, pem_object->data.len); - ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&pem_object->type_buf), "CERTIFICATE"); + ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_string(&pem_object->type_string), "CERTIFICATE"); ASSERT_INT_EQUALS(AWS_PEM_TYPE_X509, pem_object->type); aws_array_list_get_at_ptr(&output_list, (void **)&pem_object, 1); ASSERT_BIN_ARRAYS_EQUALS( s_expected_intermediate_2, sizeof(s_expected_intermediate_2), pem_object->data.buffer, pem_object->data.len); - ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&pem_object->type_buf), "CERTIFICATE"); + ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_string(&pem_object->type_string), "CERTIFICATE"); ASSERT_INT_EQUALS(AWS_PEM_TYPE_X509, pem_object->type); aws_array_list_get_at_ptr(&output_list, (void **)&pem_object, 2); ASSERT_BIN_ARRAYS_EQUALS(s_expected_leaf, sizeof(s_expected_leaf), pem_object->data.buffer, pem_object->data.len); - ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&pem_object->type_buf), "CERTIFICATE"); + ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_string(&pem_object->type_string), "CERTIFICATE"); ASSERT_INT_EQUALS(AWS_PEM_TYPE_X509, pem_object->type); aws_pem_objects_clean_up(&output_list); @@ -730,7 +730,7 @@ static int s_test_pem_private_key_parse(struct aws_allocator *allocator, void *c struct aws_pem_object *pem_object = NULL; aws_array_list_get_at_ptr(&output_list, (void **)&pem_object, 0); ASSERT_BIN_ARRAYS_EQUALS(s_expected, sizeof(s_expected), pem_object->data.buffer, pem_object->data.len); - ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&pem_object->type_buf), "RSA PRIVATE KEY"); + ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_string(&pem_object->type_string), "RSA PRIVATE KEY"); ASSERT_INT_EQUALS(AWS_PEM_TYPE_PRIVATE_RSA_PKCS1, pem_object->type); aws_pem_objects_clean_up(&output_list); @@ -961,16 +961,16 @@ static int s_test_pem_cert_chain_comments_and_whitespace(struct aws_allocator *a aws_array_list_get_at_ptr(&output_list, (void **)&pem_object, 0); ASSERT_BIN_ARRAYS_EQUALS( s_expected_intermediate_1, sizeof(s_expected_intermediate_1), pem_object->data.buffer, pem_object->data.len); - ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&pem_object->type_buf), "CERTIFICATE"); + ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_string(&pem_object->type_string), "CERTIFICATE"); ASSERT_INT_EQUALS(AWS_PEM_TYPE_X509, pem_object->type); aws_array_list_get_at_ptr(&output_list, (void **)&pem_object, 1); ASSERT_BIN_ARRAYS_EQUALS( s_expected_intermediate_2, sizeof(s_expected_intermediate_2), pem_object->data.buffer, pem_object->data.len); - ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&pem_object->type_buf), "CERTIFICATE"); + ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_string(&pem_object->type_string), "CERTIFICATE"); ASSERT_INT_EQUALS(AWS_PEM_TYPE_X509, pem_object->type); aws_array_list_get_at_ptr(&output_list, (void **)&pem_object, 2); ASSERT_BIN_ARRAYS_EQUALS(s_expected_leaf, sizeof(s_expected_leaf), pem_object->data.buffer, pem_object->data.len); - ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&pem_object->type_buf), "CERTIFICATE"); + ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_string(&pem_object->type_string), "CERTIFICATE"); ASSERT_INT_EQUALS(AWS_PEM_TYPE_X509, pem_object->type); aws_pem_objects_clean_up(&output_list);