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
135 stars 47 forks source link

Error handling #78

Closed emartynov closed 4 years ago

emartynov commented 4 years ago

Hi people,

The new user question here coming from java crypto API. How does library report about errors?

If key can not be generated? Could encryption/decryption fail?

Kind Regards, Eugen

gurpreet- commented 4 years ago

Hi @emartynov,

Yes so nearly all methods in the Lazy interface will throw a SodiumException which you can catch if anything goes wrong in Lazysodium.

In the Native interface it is generally expected that the underlying libsodium library will throw all the relevant exceptions. The Native interface assumes the developer knows what they are doing as it is very low level.

As Lazysodium uses JNA for its bindings, see here for more details https://stackoverflow.com/questions/7231583/jna-catching-exceptions.

emartynov commented 4 years ago

So native exceptions will be wrapped with lazy sodium exception?

gurpreet- commented 4 years ago

Only for the Lazy interface. As it's the Lazy interface, Lazysodium tries to handle the exceptions and make them more suitable for developers.

For the Native interface it is up to the developer to handle exceptions.

emartynov commented 4 years ago

Perfect! Thank you!