paixaop / node-sodium

Port of the lib sodium encryption library to Node.js
MIT License
351 stars 126 forks source link

Rework crypto_hash_* bindings #142

Closed cakoose closed 5 years ago

cakoose commented 5 years ago

If underlying call fails, throw. Since failure is rare, and there's usually nothing the caller can do about it, I think an exception is better than a return value. This is a backwards-incompatible change, unfortunately.

Reuse state buffer instead of making a copy. The existing bindings made a copy of the state buffer on every update(). Not sure why.

Add tests for the init/update/final mode of operation. There weren't any tests for the init/update/final mode of operation and I believe it wasn't working correctly (#141). Things seem to work after these changes, but I didn't actually track down the bug in the original code.

paixaop commented 5 years ago

Thank you for the pull request. I've merged all the changes except the exception handling. It's a great idea, but for consistency it needs to be implemented for all exported functions.

I'm in the process of porting all the tests from Libsodium itself. Once I finish that i will migrate the rest of the biding to "throw"model you suggest. thanks again!

cakoose commented 5 years ago

Sounds good, thanks!