1984not-GmbH / molch

An implementation of the axolotl ratchet based on libsodium.
Other
23 stars 3 forks source link

Conversion to C++ #100

Closed FSMaxB closed 7 years ago

FSMaxB commented 7 years ago

It turns out that C++ has a lot of features that can help with writing a library like molch, so lets use them.

For now it is kind of hard because I can't have any exceptions, can't use Constructors and the like, but I'll get there.

Especially converting the error handling might get hard.

FSMaxB commented 7 years ago

New Milestone: Exceptions are implemented in a way that they can be converted to return_status thereby allowing me to get away from return_status and to using exceptions from the bottom up (functions that are not calling any molch functions first and then up the tree until the external API is reached).

FSMaxB commented 7 years ago

Reasons why the switch is done:

  1. I've been working in an object oriented way anyways (many functions just take a pointer to a struct, so they're like classes).
  2. C++ has automatic cleanup at the end of a scope, so I can use RAII instead of the tedious cleanup I'm currently doing. The current cleanup means that I mustn't forget anything. Because if I do, some keys might still be in memory without being overwritten with zeroes. C++ does the cleanup automatically (once I've ported everything properly.
  3. I essentially implemented my own exceptions already, just with more runtime overhead, and there's almost more error checking code than code that does anything useful. Once RAII is working I can switch to exceptions and don't have to write that much error handling code.
  4. C++ already has good algorithm implementations and data structures, so no hand written, error prone linked lists anymore.
  5. Templates are quite useful in some places (e.g. bigendian/littleendian conversion for multiple integer types), but it's not that significant since there's not too many places where templates are useful.

Note: Rust would be much nicer, but porting would be much harder and getting rust to work on all the target platforms might also be difficult.

FSMaxB commented 7 years ago

I am happy with the current state. The API is currently still a C-API only though.