esp-rs / esp-mbedtls

mbedtls for ESP32 bare-metal
Apache License 2.0
21 stars 10 forks source link

Use a builder pattern for enabling hardware accelerated RSA #31

Closed AnthonyGrondin closed 3 months ago

AnthonyGrondin commented 3 months ago

Built on top of #30.

This PR refactors the way we pass the RSA peripheral to a Session, using the builder pattern. This also adds documentation detailing the usage of hardware accelerated RSA.

Whereas the older implementation is on a per session basis, it comes with the issue that only a single session can use the peripheral at the same time, even if we hold RSA statically. It would also be overwritten for every session, if one session is initialized with None.

This implementation is closer to the actual usage we do with the peripheral, where it is passed through the FFI with a static, hence it will be used for every session. The RSA is safely dropped of usage when the session using the peripheral is dropped.

It also improves simplicity, because with the change in #30, using None for RSA would require specifying the type with None::<esp_hal::peripherals::RSA>.