Skip to content

Commit

Permalink
make type a string
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyMusatkin committed Oct 6, 2023
1 parent 844611e commit 095679c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions include/aws/io/pem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
8 changes: 4 additions & 4 deletions source/pem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -312,10 +312,10 @@ static int s_convert_pem_to_raw_base64(
aws_byte_buf_init(&current_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, &current_obj_type_cur),
.type = current_obj_type,};

if (aws_array_list_push_back(pem_objects, &pem_object)) {
goto on_end_of_loop;
Expand Down
20 changes: 10 additions & 10 deletions tests/pem_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 095679c

Please sign in to comment.