Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wolfssl: Avoid needing to leak keylogger callback
Box
We have to jump through a few hoops but it is possible for the callback to work only in terms of raw pointers and references without ever instantiating an actual `Box` or `Arc` and therefore having to worry about drop. In the absence of [strict provenance][] (nightly only unstable feature) we do still need the `Box` in order to make a thin pointer to the fat `dyn Tls13SecretCallbacks` which we need to access. (Aside: I think making `Session` generic over a `CB: Tls13SecretCallbacks` would avoid the box, as we do with `IOCB`, however for the keylogger debug facility we don't need to be quite so efficient and the generics get everywhere) However the `Box` should be part of `Self` so that the required lifetime is established. From that we can obtain a (thin) reference to the allocation within the `Box` which contains the `Arc<dyn...>` which contains a fat reference to the actual callback object. That thin reference from the `Box` can then be turned into a raw pointer (which a fat pointer cannot without strict provenance). The `&mut **self.secret_cb.as_mut().unwrap()` construct is tricky: - `self.secret_cb.as_mut().unwrap()` has type `&Box<Arc<dyn...>>`; - therefore `*...` is the `Box<Arc<dyn...>>` itself; - therefore `**...` is the allocation within the box i.e. `Arc<dyn...>>`; - finally `&**...` is a reference to that allocation i.e. the `&Arc<dyn...>` which we need. [strict provenance]: rust-lang/rust#95228
- Loading branch information