openwsn-berkeley / lakers

EDHOC implemented in Rust, optimized for microcontrollers, with bindings for C and Python.
https://crates.io/crates/lakers
BSD 3-Clause "New" or "Revised" License
13 stars 10 forks source link

Typestatify part 2 #132

Closed chrysn closed 10 months ago

chrysn commented 11 months ago

Building on #128, this changes the low-level interfaces of edhoc.rs to also use typestating (albeit with a different style of typestating -- we could change it later, or I can even change to the one used with #128 in this PR still, but I think it makes sense at least initially this way, and it's easy to change later).

refactor: Typestating of edhoc.rs, removal of error codes

Primarily, this changes the State structs of edhoc.rs to use type state.
Unlike for the lib.rs interface in previous commits, this uses generics
and a marker trait instead of standalone types, mainly because there is
only little to be gained by adding and removing fields over time as they
become populated or consumed. (That change can also be made later with
way less refactoring impact).

As a result, functions that could only return the WrongState error (eg.
the edhoc_exporter function) now are infallible, and the WrongState
error variant is removed.

Changes to some of the functions led to minor rewrites (where State was
stored in the same mutable variable for its in and out form previously,
which is not possible any more here) and the Success error state could
be removed from them. That state was ever only used in locally mutable
errors, and never returned. The Success state was removed from the
EDHOCError enum, and all other functions that relied on mutable local
errors or states
chrysn commented 11 months ago

I think this is ready for more thorough review now.