Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor pem #605

Merged
merged 22 commits into from
Oct 9, 2023
Merged

refactor pem #605

merged 22 commits into from
Oct 9, 2023

Conversation

DmitriyMusatkin
Copy link
Contributor

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

codecov-commenter commented Oct 5, 2023

Codecov Report

Attention: 34 lines in your changes are missing coverage. Please review.

Comparison is base (a8d6360) 79.91% compared to head (45f7ef0) 79.72%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #605      +/-   ##
==========================================
- Coverage   79.91%   79.72%   -0.19%     
==========================================
  Files          28       27       -1     
  Lines        5854     5893      +39     
==========================================
+ Hits         4678     4698      +20     
- Misses       1176     1195      +19     
Files Coverage Δ
source/io.c 90.90% <ø> (ø)
source/pem.c 82.82% <82.82%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DmitriyMusatkin DmitriyMusatkin changed the title (wip) refactor pem refactor pem Oct 5, 2023
.vscode/settings.json Outdated Show resolved Hide resolved
Copy link
Contributor

@graebm graebm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed the public header

include/aws/io/pem.h Outdated Show resolved Hide resolved
include/aws/io/pem.h Outdated Show resolved Hide resolved
include/aws/io/pem.h Outdated Show resolved Hide resolved
include/aws/io/pem.h Show resolved Hide resolved
* This code is slow, and it allocates, so please try
* not to call this in the middle of something that needs to be fast or resource sensitive.
*/
AWS_IO_API int aws_read_and_decode_pem_file_to_object_list(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debatable: would it be simpler if these functions were alternate array-list initializers? I can't imagine this function ever being used without the user needing to initialize the list first. Like:

int aws_array_list_init_from_pem_file_contents(struct aws_array_list *list, struct aws_allocator, struct aws_byte_cursor pem_contents);

int aws_array_list_init_from_pem_file_path(struct aws_array_list *list, struct aws_allocator, const char *pem_path);

Or call it "pem_objects" instead of "array_list" (I like this idea best)?

int aws_pem_objects_init_from_file_contents(struct aws_array_list *pem_objects, struct aws_allocator, struct aws_byte_cursor pem_contents);

int aws_pem_objects_init_from_file_path(struct aws_array_list *pem_objects, struct aws_allocator, const char *pem_path);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current names were mostly based on existing names for internal function with a modification to refer to elements as pem objects instead of cert_or_key.
I like your suggestion of just naming it pem_objects_init. next commit switches to that.

I think original code wanted array to be initialized outside of the call because the caller might have better context on how many elements are there in the pem file. But in practice the answer to that is either probably just one or probably many, so initializing outside was not super helpful. Moved array init inside of the function.

include/aws/io/pem.h Show resolved Hide resolved
DmitriyMusatkin and others added 2 commits October 6, 2023 10:53
Co-authored-by: Michael Graeb <[email protected]>
Co-authored-by: Michael Graeb <[email protected]>
@@ -252,6 +252,8 @@ enum aws_io_errors {

AWS_IO_TLS_ERROR_READ_FAILURE,

AWS_ERROR_PEM_MALFORMED_OBJECT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you expect other systems to use a different error if the objects themselves are all valid, but the "document" itself is malformed due to missing required objects?

If we fear people will re-use this error-code for bad documents, give it a more generic name like AWS_ERROR_PEM_MALFORMED. But if you want distinct error-codes to be created for malformed documents of a specific type, then this is good

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me just make it generic AWS_ERROR_PEM_MALFORMED. i dont think its worth distinguishing that its individual objects that are malformed

include/aws/io/pem.h Outdated Show resolved Hide resolved
include/aws/io/pem.h Outdated Show resolved Hide resolved
include/aws/io/pem.h Outdated Show resolved Hide resolved
include/aws/io/pem.h Outdated Show resolved Hide resolved
@DmitriyMusatkin DmitriyMusatkin merged commit 029587f into main Oct 9, 2023
32 checks passed
@DmitriyMusatkin DmitriyMusatkin deleted the pem_update branch October 9, 2023 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants