Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add ncrypto dependency #3463

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Feb 4, 2025

Still very much a work in progress.

This is gonna be a big one.

@jasnell jasnell requested a review from anonrig February 4, 2025 23:18
@jasnell jasnell force-pushed the jasnell/start-adding-ncrypto branch 3 times, most recently from dc7c1a4 to b1546c4 Compare February 5, 2025 01:34
src/node/internal/crypto_keys.ts Show resolved Hide resolved
auto backing = jsg::BackingStore::alloc<v8::ArrayBuffer>(js, length);
ncrypto::Buffer<kj::byte> buf(backing.asArrayPtr().begin(), backing.size());
ncrypto::Buffer<const char> passbuf{
.data = reinterpret_cast<const char*>(pass.begin()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a method that just returns const char*? I remember something like asChars().begin()?

Comment on lines +30 to +33
ncrypto::Buffer<const char> buf{
.data = reinterpret_cast<const char*>(input.begin()),
.len = input.size(),
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Can we just have a conversion function or a static method that converts to ncrypto::Buffer? It seems there are lots of repetitions.

if (auto bio = ncrypto::ExportPublicKey(buf)) {
BUF_MEM* bptr = bio;
auto buf = jsg::BackingStore::alloc(js, bptr->length);
auto aptr = kj::arrayPtr(bptr->data, bptr->length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to check for length/emptiness for safety?

src/workerd/api/node/crypto-keys.c++ Outdated Show resolved Hide resolved
src/workerd/api/node/crypto.c++ Show resolved Hide resolved
@@ -252,3 +252,8 @@ class CryptoImpl final: public jsg::Object {
api::node::CryptoImpl::KeyExportOptions, api::node::CryptoImpl::GenerateKeyPairOptions, \
api::node::CryptoImpl::CreateAsymmetricKeyOptions, EW_CRYPTO_X509_ISOLATE_TYPES
} // namespace workerd::api::node

// Known todos
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Known todos
// TODO(soon): Known todos


inline void setToZero() {
KJ_IF_SOME(backing, maybeBackingStore) {
memset(backing.asArrayPtr().begin(), 0, backing.size());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also check for size here before calling memset.

@@ -208,6 +208,14 @@ class BackingStore {
return BackingStore(backingStore, byteLength, byteOffset, elementSize, ctor, integerType);
}

template <typename T = v8::Uint8Array>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Any particular reason for not using class?

Suggested change
template <typename T = v8::Uint8Array>
template <class T = v8::Uint8Array>

@jasnell jasnell force-pushed the jasnell/start-adding-ncrypto branch from 050b394 to 82287e0 Compare February 6, 2025 00:31
Copy link

github-actions bot commented Feb 6, 2025

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@jasnell jasnell force-pushed the jasnell/start-adding-ncrypto branch from 82287e0 to 6492b8c Compare February 6, 2025 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants