-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Encrypt can accept null, and yet decrypt returns null on success or on failure. This is a bad design choice. There's no way to identify an error on null.
One of the following should happen:
- Make null unacceptable for encrypt(). That's what I currently do outside of the lib, but it would be better if the lib itself would throw if null is given.
- Make decrypt() throw an error on failure, instead of returning null. Contrary to the docs, decrypt() does throw an error on one occasion - if hmac verification is on, and the HMACs mismatch... Just extend that to also happen for input that can't be decrypted for any reason, not just HMAC mismatch.
Personally, I would prefer option 2, as it would also allow me to handle the error in a custom way. To make handling easier, perhaps a single error type can be thrown that wraps whatever internal error was thrown.
And on that note, if option 2 is to be done, maybe don't log the error to the console, but let the user log if they want to, wherever they want to.
Of course, I understand both of these are potential BC breaks, so a major version change would probably be a good idea.
AlexanderKozhevin
Metadata
Metadata
Assignees
Labels
No labels