|
| 1 | +// Copyright 2020 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +/// Experimental JNI/JCA backend for the Android JCA exploration branch. |
| 16 | +/// |
| 17 | +/// During exploration the Android JCA branch may temporarily wire native builds |
| 18 | +/// directly to this backend. The final FFI-vs-JNI selection mechanism can be |
| 19 | +/// settled once enough primitives exist to compare behavior across backends. |
| 20 | +library; |
| 21 | + |
| 22 | +import 'dart:async'; |
| 23 | +import 'dart:typed_data'; |
| 24 | + |
| 25 | +import 'package:jni/jni.dart' as jni; |
| 26 | +import 'package:webcrypto/src/impl_interface/impl_interface.dart'; |
| 27 | + |
| 28 | +import '../third_party/jca/generated_bindings.dart'; |
| 29 | + |
| 30 | +part 'impl_jni.aescbc.dart'; |
| 31 | +part 'impl_jni.aesctr.dart'; |
| 32 | +part 'impl_jni.aesgcm.dart'; |
| 33 | +part 'impl_jni.hmac.dart'; |
| 34 | +part 'impl_jni.pbkdf2.dart'; |
| 35 | +part 'impl_jni.ecdh.dart'; |
| 36 | +part 'impl_jni.ecdsa.dart'; |
| 37 | +part 'impl_jni.rsaoaep.dart'; |
| 38 | +part 'impl_jni.hkdf.dart'; |
| 39 | +part 'impl_jni.rsapss.dart'; |
| 40 | +part 'impl_jni.rsassapkcs1v15.dart'; |
| 41 | +part 'impl_jni.digest.dart'; |
| 42 | +part 'impl_jni.random.dart'; |
| 43 | +part 'impl_jni.utils.dart'; |
| 44 | + |
| 45 | +const WebCryptoImpl webCryptImpl = _WebCryptoImpl(); |
| 46 | + |
| 47 | +final class _WebCryptoImpl implements WebCryptoImpl { |
| 48 | + const _WebCryptoImpl(); |
| 49 | + |
| 50 | + @override |
| 51 | + final aesCbcSecretKey = const _StaticAesCbcSecretKeyImpl(); |
| 52 | + |
| 53 | + @override |
| 54 | + final aesCtrSecretKey = const _StaticAesCtrSecretKeyImpl(); |
| 55 | + |
| 56 | + @override |
| 57 | + final aesGcmSecretKey = const _StaticAesGcmSecretKeyImpl(); |
| 58 | + |
| 59 | + @override |
| 60 | + final hmacSecretKey = const _StaticHmacSecretKeyImpl(); |
| 61 | + |
| 62 | + @override |
| 63 | + final pbkdf2SecretKey = const _StaticPbkdf2SecretKeyImpl(); |
| 64 | + |
| 65 | + @override |
| 66 | + final ecdhPrivateKey = const _StaticEcdhPrivateKeyImpl(); |
| 67 | + |
| 68 | + @override |
| 69 | + final ecdhPublicKey = const _StaticEcdhPublicKeyImpl(); |
| 70 | + |
| 71 | + @override |
| 72 | + final ecdsaPrivateKey = const _StaticEcdsaPrivateKeyImpl(); |
| 73 | + |
| 74 | + @override |
| 75 | + final ecdsaPublicKey = const _StaticEcdsaPublicKeyImpl(); |
| 76 | + |
| 77 | + @override |
| 78 | + final rsaOaepPrivateKey = const _StaticRsaOaepPrivateKeyImpl(); |
| 79 | + |
| 80 | + @override |
| 81 | + final rsaOaepPublicKey = const _StaticRsaOaepPublicKeyImpl(); |
| 82 | + |
| 83 | + @override |
| 84 | + final hkdfSecretKey = const _StaticHkdfSecretKeyImpl(); |
| 85 | + |
| 86 | + @override |
| 87 | + final rsaPssPrivateKey = const _StaticRsaPssPrivateKeyImpl(); |
| 88 | + |
| 89 | + @override |
| 90 | + final rsaPssPublicKey = const _StaticRsaPssPublicKeyImpl(); |
| 91 | + |
| 92 | + @override |
| 93 | + final rsaSsaPkcs1v15PrivateKey = const _StaticRsaSsaPkcs1V15PrivateKeyImpl(); |
| 94 | + |
| 95 | + @override |
| 96 | + final rsaSsaPkcs1v15PublicKey = const _StaticRsaSsaPkcs1V15PublicKeyImpl(); |
| 97 | + |
| 98 | + @override |
| 99 | + final sha1 = const _HashImpl('SHA-1'); |
| 100 | + |
| 101 | + @override |
| 102 | + final sha256 = const _HashImpl('SHA-256'); |
| 103 | + |
| 104 | + @override |
| 105 | + final sha384 = const _HashImpl('SHA-384'); |
| 106 | + |
| 107 | + @override |
| 108 | + final sha512 = const _HashImpl('SHA-512'); |
| 109 | + |
| 110 | + @override |
| 111 | + final random = const _RandomImpl(); |
| 112 | +} |
0 commit comments