fix: migrate all throw to assert, remove optional chaining#241
Merged
Conversation
Signed-off-by: Tony Gorez <[email protected]>
tony-go
commented
Mar 5, 2026
| return binding.sodium_compare(a, b) | ||
| } | ||
|
|
||
| exports.sodium_is_zero = function (buffer, length) { | ||
| if (!buffer) throw new Error('invalid buffer') | ||
| assert(ArrayBuffer.isView(buffer), 'buffer must be a typed array') |
Contributor
Author
There was a problem hiding this comment.
I assumed that it was not tested as it did not break any tests... Maybe we could like to cover these? I am afraid that would be endless.
tony-go
commented
Mar 5, 2026
| @@ -1514,18 +1920,38 @@ exports.crypto_pwhash_scryptsalsa208sha256_str_needs_rehash = function ( | |||
| // crypto_kx | |||
|
|
|||
| exports.crypto_kx_keypair = function (pk, sk) { | |||
| if (pk?.byteLength !== binding.crypto_kx_PUBLICKEYBYTES) throw new Error('pk') | |||
Contributor
Author
There was a problem hiding this comment.
Happy we have more explicit error now 😆
tony-go
commented
Mar 5, 2026
| assert( | ||
| tx.byteLength === binding.crypto_kx_SESSIONKEYBYTES, | ||
| 'transmitting key buffer must be "crypto_kx_SESSIONKEYBYTES" bytes or null' |
Contributor
Author
There was a problem hiding this comment.
Not sure we want to remove the or null
Signed-off-by: Tony Gorez <[email protected]>
kasperisager
requested changes
Mar 5, 2026
Signed-off-by: Tony Gorez <[email protected]>
kasperisager
requested changes
Mar 5, 2026
Contributor
kasperisager
left a comment
There was a problem hiding this comment.
Never use ==, always use === to avoid coercion surprises. Missing arguments will have a value of undefined, not null, so all the checks should be:
if (value === undefined) value = default
Contributor
Author
Oh yeah! I thought we would have both. Which is wrong... |
Signed-off-by: Tony Gorez <[email protected]>
kasperisager
approved these changes
Mar 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.