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

load_certs_from_path #148

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

load_certs_from_path #148

wants to merge 1 commit into from

Conversation

0rphon
Copy link

@0rphon 0rphon commented Oct 30, 2024

This PR offers a solution for #147 by moving CertPaths::load to the public function load_certs_from_path

Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

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

This seems reasonable to me.

src/lib.rs Outdated
/// hash files contained in it must be loaded successfully,
/// subject to the rules outlined above for `file`. The directory is not
/// scanned recursively and may be empty.
pub fn load_certs_from_path<T: AsRef<Path>>(file: Option<T>, dir: Option<T>) -> CertificateResult {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe paths instead of path? Also I would spell this as file: Option<impl AsRef<Path>>, dir: Option<impl AsRef<Path>> since there is no reason to require that both types are the same.

Copy link
Author

@0rphon 0rphon Oct 30, 2024

Choose a reason for hiding this comment

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

If you use impl here then the caller has to manually specify a type any time they use None for one of the arguments. ie load_certs_from_path(None, Some("/tmp")) would need to be written like load_certs_from_path(Option::<&str>::None, Some("/tmp")), whereas using the same T generic for both means itll auto-resolve as long as at least one argument is Some. I figured that would be less annoying for the caller, but i agree it is more limiting and i can change this to use impl if you think its best!

(edit: accidentally said dyn instead of impl)

Copy link
Author

Choose a reason for hiding this comment

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

actually now that i think about it more, if the caller is using two different types that satisfy AsRef<T>, then they can just convert them to paths on their end before passing them. which i think is less of a hassle than having to always specify Option::<&str>::None

Copy link
Member

Choose a reason for hiding this comment

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

Given this, I'd suggest we just change them both to Option<&Path> and give up on coercion via AsRef. Personally I still don't like that we enforce the same type for both arguments because IMO this suggests something that really doesn't make sense (although it does work it if you just pass &Path, of course).

@cpu
Copy link
Member

cpu commented Oct 31, 2024

Thanks for the PR 👍

I think this docs failure in CI could use a fix:

error: unresolved link to `load_certs_from_path`
   --> src/lib.rs:237:[17](https://github.com/rustls/rustls-native-certs/actions/runs/11602445673/job/32333915939?pr=148#step:4:18)
    |
237 |     /// Calls [`load_certs_from_path`] with the given cert paths.
    |                 ^^^^^^^^^^^^^^^^^^^^ no item named `load_certs_from_path` in scope
    |
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
    = note: `-D rustdoc::broken-intra-doc-links` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(rustdoc::broken_intra_doc_links)]`

If you wouldn't mind it would also be nice to have the commits squashed down to 1 with a good commit message.

src/lib.rs Outdated Show resolved Hide resolved
change name to load_certs_from_paths

revert fn signature to use generic

forgot to change fn name CertPaths::load

address comments about docs
@0rphon
Copy link
Author

0rphon commented Nov 1, 2024

I believe i addressed everything. I'll let you guys merge this when you think its all good

Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

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