terl / lazysodium-java

A Java implementation of the Libsodium crypto library. For the lazy dev.
https://github.com/terl/lazysodium-java/wiki
Mozilla Public License 2.0
136 stars 49 forks source link

Lazier detached functions please #14

Closed gurpreet- closed 6 years ago

gurpreet- commented 6 years ago

The "detached" variants return two items at a time.

For example, the function cryptoBoxDetached(cipher[], mac[], message[]...) populates a cipher[] and a mac[].

I suppose we could do something like:

cryptoBoxDetached(String cipher, String mac, String message...);
saveToDatabase(cipher);
saveToDatabase(mac);

But it's not clear what's happening, what's being manipulated and what you provide as initial values for cipher and mac.

Or we could do something like:

class Detached {
    byte[] cipher;
    byte[] mac;
}

Detached detached = cryptoBoxDetached(...);
detached.getCipher();
detached.getMac();

Which I believe is a lot better. Whichever one we choose, it will mean some breaking changes.

gurpreet- commented 6 years ago

This has been sorted in 83dc7d82bcaaefdc4a3ddd0bf3930f61924bd5cc, with the creation of DetachedDecrypt and DetachedEncrypt to manage the mac, cipher and message.