Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyMusatkin committed Oct 6, 2023
1 parent f287efe commit 844611e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion include/aws/io/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ enum aws_io_errors {

AWS_IO_TLS_ERROR_READ_FAILURE,

AWS_ERROR_PEM_MALFORMED_OBJECT,
AWS_ERROR_PEM_MALFORMED,

AWS_IO_ERROR_END_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_IO_PACKAGE_ID),
AWS_IO_INVALID_FILE_HANDLE = AWS_ERROR_INVALID_FILE_HANDLE,
Expand Down
58 changes: 29 additions & 29 deletions include/aws/io/pem.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@
AWS_EXTERN_C_BEGIN

/*
* Naming follows OpenSSL convention for PEM types.
* Naming follows OpenSSL convention for PEM types.
* Refer to comment after each enum value for the type string it represents.
*/
*/
enum aws_pem_object_type {
AWS_PEM_TYPE_UNKNOWN = 0,
AWS_PEM_TYPE_X509_OLD, /* X509 CERTIFICATE */
AWS_PEM_TYPE_X509, /* CERTIFICATE */
AWS_PEM_TYPE_X509_TRUSTED, /* TRUSTED CERTIFICATE */
AWS_PEM_TYPE_X509_REQ_OLD, /* NEW CERTIFICATE REQUEST */
AWS_PEM_TYPE_X509_REQ, /* CERTIFICATE REQUEST */
AWS_PEM_TYPE_X509_CRL, /* X509 CRL */
AWS_PEM_TYPE_EVP_PKEY, /* ANY PRIVATE KEY */
AWS_PEM_TYPE_PUBLIC_PKCS8, /* PUBLIC KEY */
AWS_PEM_TYPE_PRIVATE_RSA_PKCS1, /* RSA PRIVATE KEY */
AWS_PEM_TYPE_PUBLIC_RSA_PKCS1, /* RSA PUBLIC KEY */
AWS_PEM_TYPE_PRIVATE_DSA_PKCS1, /* RSA PRIVATE KEY */
AWS_PEM_TYPE_PUBLIC_DSA_PKCS1, /* RSA PUBLIC KEY */
AWS_PEM_TYPE_PKCS7, /* PKCS7 */
AWS_PEM_TYPE_PKCS7_SIGNED_DATA, /* PKCS #7 SIGNED DATA */
AWS_PEM_TYPE_X509_OLD, /* X509 CERTIFICATE */
AWS_PEM_TYPE_X509, /* CERTIFICATE */
AWS_PEM_TYPE_X509_TRUSTED, /* TRUSTED CERTIFICATE */
AWS_PEM_TYPE_X509_REQ_OLD, /* NEW CERTIFICATE REQUEST */
AWS_PEM_TYPE_X509_REQ, /* CERTIFICATE REQUEST */
AWS_PEM_TYPE_X509_CRL, /* X509 CRL */
AWS_PEM_TYPE_EVP_PKEY, /* ANY PRIVATE KEY */
AWS_PEM_TYPE_PUBLIC_PKCS8, /* PUBLIC KEY */
AWS_PEM_TYPE_PRIVATE_RSA_PKCS1, /* RSA PRIVATE KEY */
AWS_PEM_TYPE_PUBLIC_RSA_PKCS1, /* RSA PUBLIC KEY */
AWS_PEM_TYPE_PRIVATE_DSA_PKCS1, /* RSA PRIVATE KEY */
AWS_PEM_TYPE_PUBLIC_DSA_PKCS1, /* RSA PUBLIC KEY */
AWS_PEM_TYPE_PKCS7, /* PKCS7 */
AWS_PEM_TYPE_PKCS7_SIGNED_DATA, /* PKCS #7 SIGNED DATA */
AWS_PEM_TYPE_PRIVATE_PKCS8_ENCRYPTED, /* ENCRYPTED PRIVATE KEY */
AWS_PEM_TYPE_PRIVATE_PKCS8, /* PRIVATE KEY */
AWS_PEM_TYPE_DH_PARAMETERS, /* X9.42 DH PARAMETERS */
AWS_PEM_TYPE_DH_PARAMETERS_X942, /* X9.42 DH PARAMETERS */
AWS_PEM_TYPE_SSL_SESSION_PARAMETERS, /* SSL SESSION PARAMETERS */
AWS_PEM_TYPE_DSA_PARAMETERS, /* DSA PARAMETERS */
AWS_PEM_TYPE_ECDSA_PUBLIC, /* ECDSA PUBLIC KEY */
AWS_PEM_TYPE_EC_PARAMETERS, /* EC PARAMETERS */
AWS_PEM_TYPE_EC_PRIVATE, /* EC PRIVATE KEY */
AWS_PEM_TYPE_PARAMETERS, /* PARAMETERS */
AWS_PEM_TYPE_CMS, /* CMS */
AWS_PEM_TYPE_SM2_PARAMETERS /* SM2 PARAMETERS */
AWS_PEM_TYPE_PRIVATE_PKCS8, /* PRIVATE KEY */
AWS_PEM_TYPE_DH_PARAMETERS, /* X9.42 DH PARAMETERS */
AWS_PEM_TYPE_DH_PARAMETERS_X942, /* X9.42 DH PARAMETERS */
AWS_PEM_TYPE_SSL_SESSION_PARAMETERS, /* SSL SESSION PARAMETERS */
AWS_PEM_TYPE_DSA_PARAMETERS, /* DSA PARAMETERS */
AWS_PEM_TYPE_ECDSA_PUBLIC, /* ECDSA PUBLIC KEY */
AWS_PEM_TYPE_EC_PARAMETERS, /* EC PARAMETERS */
AWS_PEM_TYPE_EC_PRIVATE, /* EC PRIVATE KEY */
AWS_PEM_TYPE_PARAMETERS, /* PARAMETERS */
AWS_PEM_TYPE_CMS, /* CMS */
AWS_PEM_TYPE_SM2_PARAMETERS /* SM2 PARAMETERS */
};

/*
Expand Down Expand Up @@ -68,7 +68,7 @@ AWS_IO_API void aws_pem_objects_clean_up(struct aws_array_list *pem_objects);
* If it comes across an object it cannot read, list of all object read until
* that point is returned.
* If no objects can be read PEM or objects could not be base 64 decoded,
* AWS_ERROR_PEM_MALFORMED_OBJECT is raised.
* AWS_ERROR_PEM_MALFORMED is raised.
* out_pem_objects stores aws_pem_object struct by value.
* Caller must initialize out_pem_objects before calling the function.
* This code is slow, and it allocates, so please try
Expand All @@ -84,7 +84,7 @@ AWS_IO_API int aws_decode_pem_to_object_list(
* If it comes across an object it cannot read, list of all object read until
* that point is returned.
* If no objects can be read PEM or objects could not be base 64 decoded,
* AWS_ERROR_PEM_MALFORMED_OBJECT is raised.
* AWS_ERROR_PEM_MALFORMED is raised.
* out_pem_objects stores aws_pem_object struct by value.
* Caller must initialize out_pem_objects before calling the function.
* This code is slow, and it allocates, so please try
Expand Down
2 changes: 1 addition & 1 deletion source/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ static struct aws_error_info s_errors[] = {
AWS_DEFINE_ERROR_INFO_IO(
AWS_IO_TLS_ERROR_READ_FAILURE,
"Failure during TLS read."),
AWS_DEFINE_ERROR_INFO_IO(AWS_ERROR_PEM_MALFORMED_OBJECT, "Malformed PEM object encountered."),
AWS_DEFINE_ERROR_INFO_IO(AWS_ERROR_PEM_MALFORMED, "Malformed PEM object encountered."),

};
/* clang-format on */
Expand Down
12 changes: 6 additions & 6 deletions source/pem.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static struct aws_byte_cursor s_delim_cur = AWS_BYTE_CUR_INIT_FROM_STRING_LITERA
int s_extract_header_type_cur(struct aws_byte_cursor cur, struct aws_byte_cursor *out) {
if (!aws_byte_cursor_starts_with(&cur, &s_begin_header_cur)) {
AWS_LOGF_ERROR(AWS_LS_IO_PEM, "Invalid PEM buffer: invalid begin token");
return aws_raise_error(AWS_ERROR_PEM_MALFORMED_OBJECT);
return aws_raise_error(AWS_ERROR_PEM_MALFORMED);
}

aws_byte_cursor_advance(&cur, s_begin_header_cur.len);
Expand All @@ -237,7 +237,7 @@ int s_extract_header_type_cur(struct aws_byte_cursor cur, struct aws_byte_cursor

if (!aws_byte_cursor_eq(&cur, &s_delim_cur)) {
AWS_LOGF_ERROR(AWS_LS_IO_PEM, "Invalid PEM buffer: invalid end token");
return aws_raise_error(AWS_ERROR_PEM_MALFORMED_OBJECT);
return aws_raise_error(AWS_ERROR_PEM_MALFORMED);
}

*out = type_cur;
Expand All @@ -257,7 +257,7 @@ static int s_convert_pem_to_raw_base64(
if (aws_byte_cursor_split_on_char(&pem, '\n', &split_buffers)) {
aws_array_list_clean_up(&split_buffers);
AWS_LOGF_ERROR(AWS_LS_IO_PEM, "Invalid PEM buffer: failed to split on newline");
return aws_raise_error(AWS_ERROR_PEM_MALFORMED_OBJECT);
return aws_raise_error(AWS_ERROR_PEM_MALFORMED);
}

enum aws_pem_parse_state state = BEGIN;
Expand Down Expand Up @@ -359,7 +359,7 @@ static int s_convert_pem_to_raw_base64(

AWS_LOGF_ERROR(AWS_LS_IO_PEM, "Invalid PEM buffer.");
aws_pem_objects_clean_up(pem_objects);
return aws_raise_error(AWS_ERROR_PEM_MALFORMED_OBJECT);
return aws_raise_error(AWS_ERROR_PEM_MALFORMED);
}

int aws_decode_pem_to_object_list(
Expand All @@ -382,7 +382,7 @@ int aws_decode_pem_to_object_list(
size_t decoded_len = 0;
if (aws_base64_compute_decoded_len(&byte_cur, &decoded_len)) {
AWS_LOGF_ERROR(AWS_LS_IO_PEM, "Failed to get length for decoded base64 pem object.");
aws_raise_error(AWS_ERROR_PEM_MALFORMED_OBJECT);
aws_raise_error(AWS_ERROR_PEM_MALFORMED);
goto on_error;
}

Expand All @@ -391,7 +391,7 @@ int aws_decode_pem_to_object_list(

if (aws_base64_decode(&byte_cur, &decoded_buffer)) {
AWS_LOGF_ERROR(AWS_LS_IO_PEM, "Failed to base 64 decode pem object.");
aws_raise_error(AWS_ERROR_PEM_MALFORMED_OBJECT);
aws_raise_error(AWS_ERROR_PEM_MALFORMED);
aws_byte_buf_clean_up_secure(&decoded_buffer);
goto on_error;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/pem_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ static int s_test_pem_invalid_parse(struct aws_allocator *allocator, void *ctx)
struct aws_array_list output_list;

ASSERT_SUCCESS(aws_array_list_init_dynamic(&output_list, allocator, 1, sizeof(struct aws_pem_object)));
ASSERT_ERROR(AWS_ERROR_PEM_MALFORMED_OBJECT, aws_decode_pem_to_object_list(allocator, pem_data, &output_list));
ASSERT_ERROR(AWS_ERROR_PEM_MALFORMED, aws_decode_pem_to_object_list(allocator, pem_data, &output_list));
ASSERT_UINT_EQUALS(0, aws_array_list_length(&output_list));

aws_array_list_clean_up(&output_list);
Expand Down Expand Up @@ -1037,7 +1037,7 @@ static int s_test_pem_valid_data_invalid_parse(struct aws_allocator *allocator,
struct aws_array_list output_list;

ASSERT_SUCCESS(aws_array_list_init_dynamic(&output_list, allocator, 1, sizeof(struct aws_pem_object)));
ASSERT_ERROR(AWS_ERROR_PEM_MALFORMED_OBJECT, aws_decode_pem_to_object_list(allocator, pem_data, &output_list));
ASSERT_ERROR(AWS_ERROR_PEM_MALFORMED, aws_decode_pem_to_object_list(allocator, pem_data, &output_list));
ASSERT_UINT_EQUALS(0, aws_array_list_length(&output_list));

aws_array_list_clean_up(&output_list);
Expand Down Expand Up @@ -1109,7 +1109,7 @@ static int s_test_pem_invalid_in_chain_parse(struct aws_allocator *allocator, vo
struct aws_array_list output_list;

ASSERT_SUCCESS(aws_array_list_init_dynamic(&output_list, allocator, 1, sizeof(struct aws_pem_object)));
ASSERT_ERROR(AWS_ERROR_PEM_MALFORMED_OBJECT, aws_decode_pem_to_object_list(allocator, pem_data, &output_list));
ASSERT_ERROR(AWS_ERROR_PEM_MALFORMED, aws_decode_pem_to_object_list(allocator, pem_data, &output_list));
ASSERT_UINT_EQUALS(0, aws_array_list_length(&output_list));

aws_array_list_clean_up(&output_list);
Expand Down

0 comments on commit 844611e

Please sign in to comment.