feat(impl_jni): add JCA backend skeleton with opt-in digest path#296
feat(impl_jni): add JCA backend skeleton with opt-in digest path#296mfazrinizar wants to merge 3 commits into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
|
||
| import 'package:jnigen/jnigen.dart'; | ||
|
|
||
| Future<void> main() async { |
There was a problem hiding this comment.
Could we just use: a jnigen.yaml config file, see:
https://pub.dev/packages/jnigen#yaml-configuration-reference
Add it to:
https://github.com/google/webcrypto.dart/blob/master/tool/update-bindings.sh
Put the generated bindings in:
lib/
src/
third_party/
jca/
jnigen.yaml
generated_bindings.dart
Or something like that
There was a problem hiding this comment.
Agreed. We should use the config-driven generation approach. I’ll switch this to a config-based setup matching the existing bindings flow: add lib/src/third_party/jca/jnigen.yaml, wire it into tool/update-bindings.sh, and put the generated output under lib/src/third_party/jca/generated_bindings.dart. In this case, I’ll split the generated bindings into a separate PR first so this implementation PR only contains the backend/test code.
| /// `JByteArray.getRange` returns a typed list backed by a native buffer whose | ||
| /// lifetime is finalizer-driven. Copy once more before releasing the Java array | ||
| /// so webcrypto callers receive a normal Dart-managed [Uint8List]. | ||
| Uint8List _copyJByteArray(jni.JByteArray array) { |
There was a problem hiding this comment.
consider putting this in a util.dart library or similar...
consider using an extension method on JByteArray, so you can do myArray.copyToDart() or something like that :D
There was a problem hiding this comment.
Makes sense. I’ll move this into a small JNI util library and expose it as an extension method. I think probably something like copyToDartBytes(), so that the digest implementation stays focused on the crypto flow.
|
|
||
| @visibleForTesting | ||
| WebCryptoImpl selectNativeImplForTesting(String requestedBackend) => | ||
| requestedBackend == 'jni' ? jni.webCryptImpl : ffi.webCryptImpl; |
There was a problem hiding this comment.
what is this good for? probably don't need it :D
There was a problem hiding this comment.
This was only added to make the temporary selector easy to test because I wasn’t really sure the -D path would be reliable through package:test. But agreed, it is not important right now. I’ll remove it and keep the tests focused on direct JNI/JCA smoke coverage.
Summary
This PR adds the first Android JCA exploration slice on top of
android-jca-branch.It includes:
impl_jnibackend skeleton following the existingWebCryptoImplinterfacejava.security.MessageDigestimpl_native--dart-define=webcrypto.impl=jniThe stable native backend remains FFI/BoringSSL by default. The JNI/JCA backend is only selected when explicitly requested with:
Testing
Passed locally:
Android, inside example app directory: