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

Migrate lib/src/crypto_subtle.dart to use dart:js_interop #86

Merged
merged 11 commits into from
Feb 29, 2024

Conversation

koji-1009
Copy link
Contributor

Migrate web crypto api code to dart:js_interop.

I have added JS to class names, like JSWindow, to distinguish it from classes that are not related to dart:js_interop. But if this is unnecessary, please point it out in review comments.

close #83

@koji-1009 koji-1009 force-pushed the feat/js_interop branch 2 times, most recently from 1e992d3 to 22c5230 Compare February 25, 2024 13:50
Copy link
Member

@jonasfj jonasfj left a comment

Choose a reason for hiding this comment

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

Mostly just nits, a few dumb questions about exception handling.

But overall this looks good.

lib/src/crypto_subtle.dart Outdated Show resolved Hide resolved
lib/src/crypto_subtle.dart Outdated Show resolved Hide resolved
lib/src/crypto_subtle.dart Outdated Show resolved Hide resolved
lib/src/impl_js/impl_js.random.dart Show resolved Hide resolved
lib/src/impl_js/impl_js.utils.dart Show resolved Hide resolved
lib/src/crypto_subtle.dart Outdated Show resolved Hide resolved
Copy link
Member

@jonasfj jonasfj left a comment

Choose a reason for hiding this comment

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

I think this is good enough to ship!

r+

If you want to tweak the test things, feel free. Otherwise, I'll land this, and be happy to accept PRs improving tests.

Writing tests for crypto_subtle.dart actually makes sense. But it's a non-trivial amount of work, and certainly not something we should block this PR on.

@@ -0,0 +1,186 @@
@TestOn('chrome')
Copy link
Member

Choose a reason for hiding this comment

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

I imagine that the two files for Firefox and Chrome are quite similar.

Can we make this a single file.

Perhaps we can make detectedRuntime to handle different browsers differently.

If we only have a single file it's easier to spot the difference.

Comment on lines +20 to +22
import 'package:webcrypto/src/impl_js/impl_js.dart';
import 'package:webcrypto/src/crypto_subtle.dart';
import 'package:webcrypto/src/testing/webcrypto/random.dart';
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we should only be testing:
src/crypto_subtle.dart

And import it with import 'package:webcrypto/src/crypto_subtle.dart as subtle' as we do in impl_js.dart`.

Basically, we could call this crypto_subtle_test.dart, because it contains unit tests that the way we wrap the browsers API in crypto_subtle.dart is as we would expect.

(I don't really care that you import isAllZero that's fine, hehe)

Comment on lines +170 to +180
.having(
(e) => e.name,
'name',
'TypeError',
)
.having(
(e) => e.message,
'message',
contains(
'''Failed to execute 'generateKey' on 'SubtleCrypto': Algorithm: name: Missing or not a string''',
),
Copy link
Member

Choose a reason for hiding this comment

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

If we code it this specifically, then it'll never across browsers.

But we could say that we expect a JSDomException with e.name being oneOf('TypeError', 'SyntaxError') -- I'm not sure we should care about the difference.

@jonasfj jonasfj merged commit 91e80d9 into google:master Feb 29, 2024
6 checks passed
@jonasfj
Copy link
Member

jonasfj commented Feb 29, 2024

I'll get this out in the next release, feel free to file a PR preparing a release (bump version and update changelog), if you want it sooner.

@koji-1009
Copy link
Contributor Author

@jonasfj
Thanks for the review and advice!
I will work on improving the test over the weekend.

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.

Migrate lib/src/crypto_subtle.dart to use dart:js_interop
2 participants