rustls / rustls-ffi

Use Rustls from any language
Other
132 stars 30 forks source link

Implement Acceptor API #243

Closed jsha closed 1 year ago

jsha commented 2 years ago

Fixes #155.

Since this relies on an "into" pattern (for the Accepted -> Connection transform), I've implemented the safer "into" pattern from #244: a rustls_acceptor always needs to be freed, whether its "into" method was called or not. This reduces the risk of double frees. I've introduced the new result code rustls_result::AlreadyUsed to cover the case when an accessor was called after the "into" method was called.

I've introduced another new result code rustls_result::AcceptorNotReady to cover the case when accept() returns Ok(None).

For convenience I've flattened the methods from ClientHello onto rustls_accepted, so you don't need to get a ClientHello pointer out of the rustls_accepted, you can call the accessors directly.

Since we now have an accessor returning a rustls_str (previously they were passed in callbacks), we needed a way to make the lifetime of a rustls_str longer than the function that made it, so I introduced an rustls_str::into_static method.

AlbertMarashi commented 2 years ago

Need this

jsha commented 2 years ago

I've rewritten this thanks to some very useful offline feedback from @djc. It now looks a lot more like the Rust API.

djc commented 2 years ago

Clippy says there's a redundant clone in src/acceptor.rs#L455. (Should we set CI to deny clippy warnings? I usually like to do that in other projects I maintain.)

jsha commented 2 years ago

Regarding clippy warnings, I filed a PR: https://github.com/rustls/rustls-ffi/pull/261

jsha commented 2 years ago

Also, in light of https://github.com/rustls/rustls/issues/1045, I removed rustls_acceptor_wants_read in the latest push and updated the rustls_acceptor comment to describe the reading flow without it.