Use pki_types to improve the interoperability with the rustls ecosystem #223
Conversation
|
Thanks for working on this! I would propose doing a smaller increment which preserves the use of the pem crate for parsing (but still uses the pki-types for DER-containing types in the public API). I also think it would be okay to add What do you think? |
c85822e to
4e3028a
Compare
|
Yes sure, let's do this step by step! |
To fix this task you'll need to update the cargo-check-external-types metadata to add Lines 47 to 51 in 747b5d8 The intent of |
4e3028a to
782ac0f
Compare
I see, thank you for the tip! |
cpu
left a comment
There was a problem hiding this comment.
Thanks for picking this up. It'll be nice to get this in with the other breaking changes in main before a release 👍
I flagged some nits but the overall meat of the work seems great as-is.
782ac0f to
8d9acc6
Compare
|
We're going to cut a pki-types release with the CSR type: rustls/pki-types#34 If you want to take a Cargo patch and switch this branch over we can probably have that release published before this PR is done with review saving a follow-up for that. |
f24d833 to
adf9b31
Compare
|
I've used a patch while waiting for the release 👍 I wonder if |
adf9b31 to
a172806
Compare
pki-types v1.3.0 is now available. |
78aa5d4 to
8d762ed
Compare
|
@est31 Do you think you'll have bandwidth to review this soon? Should we continue to hold merging? |
|
It needs a rebase, right? |
est31
left a comment
There was a problem hiding this comment.
I've always felt down when using these special types with crates like ring for example (the rust crypto ecosystem also uses them heavily), because you have to import an additional type to use the API, and maybe even an additional crate. Actually you don't but you need to first look up if there is a from impl, etc. You also need to figure out how to convert it into bytes again in the output. This makes interaction with such APIs way more expensive for developers.
At the least, we should make this interaction very clear in the docs, making sure that users know how to use rcgen without using the interop crate. I've pointed out all the locations in the comments.
It might indeed improve interopability with other libraries/crates that use these types, but I think that most users just want to convert from byte slices and back, because they get something from a network, or a file, or the other way round. So while improving the interopability with a minority of use cases, it hurts the interopability with the majority (or at least I believe). Vec and slices have conversions to the Bytes type for example, but I couldn't find anything about Bytes in the docs of PrivatePkcs8KeyDer. So you first have to convert the Bytes to a Vec or a slice and then to a PrivatePkcs8KeyDer.
The main advantage I see in DER specific types would be that it could take care of conversion to PEM, you'd just call a function .pem() on it. But when I look at the rustdocs of PrivatePkcs8KeyDer I don't see any explanation how to convert it to pem, nor is there an easy pem() that returns a string (or another wrapper).
Such types do have advantages as they carry more meaning than the byte slice type, and I'm definitely not advocating for adopting C where everything is a void* but one should be extremely careful to not stand in the way of users, and stuff like I/O is usually just byte slices.
db6b565 to
9daeee2
Compare
I do sympathize with these concerns, however in this case:
(I myself recently got confused and passed DER into an API that expected a
Yes, there is no PEM encoding code in the rustls project. I think we might want to change that going forward, and it would definitely make the case for this stronger. |
Fair point, and I personally also had some confusing experiences where one Rust crypto library provided a key in one format and the other library was reading the key in the other format. In these instances, the chosen format has always been underdocumented (it's already over a year ago and I don't remember the exact details any more). I think we can eventually merge this PR, if it documents the new API well, and by that I mean at each location where the new types are being used. You are right that it's very easy to convert these types to/from byte buffers but it needs to be documented how, one shouldn't need the docs of the interface crate for that. |
9daeee2 to
cc39754
Compare
cc39754 to
0c5da82
Compare
|
I've rebased on the latest main and add some comments as suggested in the review. |
67833ef to
4ed17c7
Compare
4ed17c7 to
657c615
Compare
|
Thanks for working on this, I'll just merge this now and might follow up with a PR with some nits. |
|
Nice work @Tudyx 👏 |
Use
pki_typesto improve the interoperability with therustlsecosystem and make types pretty clear, as suggested by #170 (comment).To fully get rid of the
pemdependency (by replacing it byrustls_pemfile), I think those further actions will be needed:CertificateSigningRequestDertopki_typesCsrvariant to rustls_pemfile::Item which is a newtype ofCertificateSigningRequestDerPlease let me know if I miss something and if you think this goes in the right direction.
I'm open to submit following PR for this.