Skip to content

Split certificate module out of crate root #237

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

Merged
merged 1 commit into from
Mar 8, 2024
Merged

Split certificate module out of crate root #237

merged 1 commit into from
Mar 8, 2024

Conversation

djc
Copy link
Member

@djc djc commented Mar 7, 2024

Before this PR, lib.rs was 2258 lines long, and I found it quite hard to navigate. Here, I tried to split off a certificate module coming in at 1497 lines (1215 without tests), reducing lib.rs to 796 lines.

The new module also follows a top-down ordering, following the prevailing style in rustls projects. While some of the smaller modules seem to be top-down oriented, lib.rs so far was closer to bottom-up, but its lack of consistent ordering was definitely one of the reasons I've found it hard to navigate.

To build this, I took Certificate and CertificateParams and move them into a separate module. Any types that are mainly used via Certificate and CertificateParams are also moved. I have kept the OID definitions together (rather than moving the certificate-related ones to certificate) -- maybe we should move the ones that are only used in certificate?

At least for me, this will be much easier to navigate.

@djc djc requested review from cpu and est31 March 7, 2024 11:37
@djc djc force-pushed the certificate-mod branch from b51133f to bf9eec4 Compare March 7, 2024 11:38
@est31
Copy link
Member

est31 commented Mar 7, 2024

I have kept the OID definitions together (rather than moving the certificate-related ones to certificate) -- maybe we should move the ones that are only used in certificate?

I think this is better, let's have them all in one place, then one knows where to look it up.

write_distinguished_name, write_dt_utc_or_generalized, write_x509_authority_key_identifier,
write_x509_extension, DistinguishedName, Error, KeyIdMethod, KeyPair, KeyUsagePurpose, SanType,
SerialNumber, OID_BASIC_CONSTRAINTS, OID_COMMON_NAME, OID_COUNTRY_NAME,
OID_CRL_DISTRIBUTION_POINTS, OID_EXT_KEY_USAGE, OID_KEY_USAGE, OID_LOCALITY_NAME,
Copy link
Member

Choose a reason for hiding this comment

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

Imports with these many lines are an anti-pattern as their interaction with rustfmt and text reflow is prone to cause merge conflicts. If you removed the OID_ prefix from the oids and moved all the OID_ related stuff to a separate mod oid, contained inside lib.rs, and then used the OIDs e.g. via oid::BASIC_CONSTRAINTS, then the number of lines of the import would be greatly reduced.

Alternatively, one could have a star import use crate::oid::*. I generally dislike star imports but if everything in the module is prefixed with the OID_ name then it's pretty clear where the item is from.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call! There was actually already an oid module, I just failed to notice it. Imported the module only in the new certificate module to reduce the number of imports here.

Copy link
Member

@est31 est31 left a comment

Choose a reason for hiding this comment

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

ok except nit about import

@djc djc force-pushed the certificate-mod branch from bf9eec4 to 798f01f Compare March 8, 2024 08:31
@djc djc added this pull request to the merge queue Mar 8, 2024
Merged via the queue into main with commit 4125523 Mar 8, 2024
@djc djc deleted the certificate-mod branch March 8, 2024 08:51
@djc djc mentioned this pull request Mar 8, 2024
@cpu
Copy link
Member

cpu commented Mar 11, 2024

Thank you! I've also found lib.rs to be unwieldy to navigate in the past. This is a nice change.

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.

None yet

3 participants