node:crypto: move Sign and Verify to c++#17692
Merged
Jarred-Sumner merged 51 commits intomainfrom Mar 1, 2025
Merged
Conversation
Collaborator
|
Updated 1:56 AM PT - Mar 1st, 2025
❌ @dylan-conway, your commit c863bf8 has some failures in 🧪 try this PR locally: bunx bun-pr 17692 |
There was a problem hiding this comment.
PR Overview
This PR moves the Sign implementation to C++ by integrating ncrypto, refactors related crypto API functions, and updates error codes.
- Updates test behavior for missing crypto support and OpenSSL version detection
- Refactors crypto.ts to create a new Sign class and update key processing functions
- Adds new error codes in ErrorCode.ts to support the new crypto functionality
Reviewed Changes
| File | Description |
|---|---|
| test/js/node/test/common/crypto.js | Wraps the crypto test skip logic in braces and adds OpenSSL version helpers |
| src/js/node/crypto.ts | Refactors crypto functions, adds a new Sign class, and updates key handling |
| src/bun.js/bindings/ErrorCode.ts | Introduces new error mappings for crypto sign and key compatibility |
Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/js/node/crypto.ts:231
- [nitpick] The optional parameter 'encoding' lacks an explicit type annotation, which may reduce type safety in a TypeScript context. Consider defining its type explicitly (e.g. encoding?: string).
function getArrayBufferOrView(buffer, name, encoding?) {
Comment on lines
+132
to
+133
| const { m, n, p } = process.versions.openssl.match(regexp).groups; | ||
| OPENSSL_VERSION_NUMBER = opensslVersionNumber(m, n, p); |
There was a problem hiding this comment.
The regex match on process.versions.openssl does not check for a null result, which could lead to a runtime error if the version string format changes. Consider adding a null check before destructuring the groups.
Suggested change
| const { m, n, p } = process.versions.openssl.match(regexp).groups; | |
| OPENSSL_VERSION_NUMBER = opensslVersionNumber(m, n, p); | |
| const match = process.versions.openssl.match(regexp); | |
| if (match) { | |
| const { m, n, p } = match.groups; | |
| OPENSSL_VERSION_NUMBER = opensslVersionNumber(m, n, p); | |
| } else { | |
| throw new Error('Invalid OpenSSL version format'); | |
| } |
Member
Author
There was a problem hiding this comment.
Do I need to make this change in other places in this file?
node:crypto: move Sign to c++node:crypto: move Sign and Verify to c++
This was referenced Mar 4, 2025
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.
What does this PR do?
Uses ncrypto for implementing
SignHow did you verify your code works?