drogue-iot / embedded-tls

An Rust TLS 1.3 implementation for embedded devices.
Apache License 2.0
168 stars 21 forks source link

Clean up and fix CryptoBuffer u24 encode issue #96

Closed bugadani closed 1 year ago

bugadani commented 1 year ago

u32::to_be_bytes returns an array where the 0th element is the most significant byte. When encoding a u24, this byte is 0, and we need to store bytes 1-3 instead of 0-2. This PR fixes this issue, and cleans up code by using less raw slice operations, and then some.

Commit c70f6b92aa391b5fa00b2bdb5557a0db794a20a0 is an experimental idea of which I'd like to hear your opinions. It abstracts the reserve-then-set-later pattern with a callback, so now we have a simple way to automate prepending length byte(s). There are more places it can be used if the idea gets a green light, otherwise it's easy enough to just drop the commit :)