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

deps: rcgen 0.12 -> 0.13 #239

Merged
merged 6 commits into from
Apr 9, 2024
Merged

deps: rcgen 0.12 -> 0.13 #239

merged 6 commits into from
Apr 9, 2024

Conversation

cpu
Copy link
Member

@cpu cpu commented Mar 28, 2024

  • updates rcgen dev dependency to 0.13
  • fixes breaking upstream changes
  • also fixes an unrelated nightly clippy err in a separate commit

@cpu cpu self-assigned this Mar 28, 2024
Copy link

codecov bot commented Mar 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.22%. Comparing base (97f0364) to head (9a55677).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #239      +/-   ##
==========================================
+ Coverage   97.19%   97.22%   +0.02%     
==========================================
  Files          19       19              
  Lines        4065     4104      +39     
==========================================
+ Hits         3951     3990      +39     
  Misses        114      114              

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

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.

I think you can take more advantage of the impl From<Certificate> for CertificateDer<'static> that we have in rcgen... called out a bunch of places but it looks like there are a lot more.

src/verify_cert.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/end_entity.rs Outdated Show resolved Hide resolved
src/test_utils.rs Show resolved Hide resolved
src/verify_cert.rs Outdated Show resolved Hide resolved
src/verify_cert.rs Outdated Show resolved Hide resolved
src/verify_cert.rs Outdated Show resolved Hide resolved
src/verify_cert.rs Outdated Show resolved Hide resolved
@cpu

This comment was marked as resolved.

@djc
Copy link
Member

djc commented Mar 28, 2024

Oh, so we don't have ownership of the Certificate in all those places? Seems surprising.

@cpu
Copy link
Member Author

cpu commented Mar 28, 2024

Oh, so we don't have ownership of the Certificate in all those places?

We have ownership. I'll try again 🤔

@cpu
Copy link
Member Author

cpu commented Mar 28, 2024

I'll try again 🤔

I don't think there's any way to do this without clone or using to_owned instead of into_owned. Here's a minimal reproducer annotated with types. Everything is owned up until the DER we borrow from Certificate::der().

Code and error:
    #[test]
    fn test_it() {
        let cert_and_key: rcgen::CertifiedKey = make_issuer("Bogus Subject");
        let cert: rcgen::Certificate = cert_and_key.cert;
        let cert_der_borrowed: &CertificateDer<'static> = cert.der();
        let cert_der_owned: CertificateDer<'static> = cert_der_borrowed.into_owned();
    }
error[E0507]: cannot move out of `*cert_der_borrowed` which is behind a shared reference
   --> src/verify_cert.rs:789:50
    |
789 |         let cert_der_owned: CertificateDer<'_> = cert_der_borrowed.into_owned();
    |                                                  ^^^^^^^^^^^^^^^^^ ------------ `*cert_der_borrowed` moved due to this method call
    |                                                  |
    |                                                  move occurs because `*cert_der_borrowed` has type `rustls_pki_types::CertificateDer<'_>`, which does not implement the `Copy` trait
    |
note: `rustls_pki_types::CertificateDer::<'_>::into_owned` takes ownership of the receiver `self`, which moves `*cert_der_borrowed`
   --> /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-pki-types-1.4.1/src/lib.rs:498:23
    |
498 |     pub fn into_owned(self) -> CertificateDer<'static> {
    |                       ^^^^
help: you can `clone` the value and consume it, but this might not be your desired behavior
    |
789 |         let cert_der_owned: CertificateDer<'_> = <rustls_pki_types::CertificateDer<'_> as Clone>::clone(&cert_der_borrowed).into_owned();
    |                                                  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++                 +

@cpu cpu closed this Mar 28, 2024
@cpu cpu reopened this Mar 28, 2024
@cpu
Copy link
Member Author

cpu commented Mar 28, 2024

Maybe in rcgen Certificate::der() should be returning CertificateDer<'static> by cloning its owned CertificateDer<'static> member instead of returning a &CertificateDer<'static> borrow? That would probably be more ergonomic since it seems like most uses are going to need to clone it.

@cpu
Copy link
Member Author

cpu commented Mar 28, 2024

Maybe in rcgen Certificate::der() should be returning CertificateDer<'static> by cloning its owned CertificateDer<'static> member instead of returning a &CertificateDer<'static> borrow?

Or, maybe what we should have done was to return a CertificateDer<'a> from Certificate's owned CertificateDer<'static> copy:

pub fn der<'a>(&'a self) -> CertificateDer<'a> {
    CertificateDer::from(self.der.as_ref())
}

Edit: Something like cpu/rcgen@2069697 (but probably added as a second fn since we don't want to make a 0.14...... 😭)

Edit 2: It ends up looking like this on our side: dc2d224 I think it's a big improvement. I just wish we noticed this before 0.13 😭 😭

@djc
Copy link
Member

djc commented Mar 28, 2024

That looks like you are not using the impl From<rcgen::Certificate> for CertificateDer<'static>...

@djc
Copy link
Member

djc commented Mar 28, 2024

(It's late here so my brain is too fried to go deep on this.)

@cpu
Copy link
Member Author

cpu commented Mar 29, 2024

That looks like you are not using the impl Fromrcgen::Certificate for CertificateDer<'static>...

I'm not sure what you mean, but in either case this would be separate from the problem I was trying to solve w.r.t der() since I can't get a CertificateDer<'static> from Certificate::der()'s &CertificateDer<'static> return as written without clone(), right?

How would you adjust the smaller snippet I shared if you don't think clone() is appropriate, and don't think the upstream Certificate should offer a CertificateDer<'a> return in addition to (or replacing) der() -> &CertificateDer<'static>?

@djc
Copy link
Member

djc commented Mar 29, 2024

Like this?

#[test]
fn test_it() {
    use pki_types::CertificateDer;
    let cert_and_key: rcgen::CertifiedKey = make_issuer("Bogus Subject");
    let cert: rcgen::Certificate = cert_and_key.cert;
    let cert_der_borrowed: &CertificateDer<'static> = cert.der();
    let cert_der_owned = CertificateDer::from(cert);
}

@cpu
Copy link
Member Author

cpu commented Mar 29, 2024

That looks like you are not using the impl Fromrcgen::Certificate for CertificateDer<'static>...
..
Like this?

Ohhhhh! I see, not using der() at all 💡 I'm not sure why this was so hard for me to get into my head but in either case thanks for making it explicit 😆

I'll rework this & rustls/rustls#1852 with my new understanding.

@djc
Copy link
Member

djc commented Mar 29, 2024

When I added the From impl in rcgen I debated whether it could/should (also?) be an into_der() method...

@cpu cpu force-pushed the cpu-rcgen-0.13 branch 2 times, most recently from 5aa738e to 4659b92 Compare March 29, 2024 22:00
@cpu
Copy link
Member Author

cpu commented Mar 29, 2024

I'll rework this

Updated to remove almost all of the clunky clone()'s. There are a couple that seem unavoidable I left comments justifying. I also had to rejig some of the test helpers to make the lifetimes work out nicer. It was a useful exercise because I managed to reduce a bit of duplication at the same time.

cpu added 4 commits April 7, 2024 12:38
```
warning: bound is defined in more than one place
   --> src/verify_cert.rs:553:35
    |
553 | fn loop_while_non_fatal_error<'a, V: 'a>(
    |                                   ^
...
559 |     V: IntoIterator,
    |     ^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations
    = note: `#[warn(clippy::multiple_bound_locations)]` on by default
```
* top-down
* tests before helpers
To support splitting off the "building" part we need to emphasize these
two fns are both building _and_ verifying paths.
benches/benchmark.rs Show resolved Hide resolved
src/test_utils.rs Outdated Show resolved Hide resolved
src/verify_cert.rs Show resolved Hide resolved
cpu added 2 commits April 8, 2024 11:25
* updates rcgen dev dependency to 0.13
* fixes breaking upstream changes
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.

Have some thoughts on further improvements, but let's get this in.

src/verify_cert.rs Show resolved Hide resolved
@cpu
Copy link
Member Author

cpu commented Apr 8, 2024

@ctz Is this a branch you'd like to review before it lands?

@cpu
Copy link
Member Author

cpu commented Apr 9, 2024

Since this is only touching test & support code I'm going to merge and if there's any more feedback I'll look at follow-up PRs.

Thanks!

@cpu cpu added this pull request to the merge queue Apr 9, 2024
Merged via the queue into rustls:main with commit 4e68ad2 Apr 9, 2024
30 checks passed
@cpu cpu deleted the cpu-rcgen-0.13 branch April 9, 2024 13:07
@djc djc mentioned this pull request Apr 9, 2024
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.

2 participants