diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index 8a2a4382..7c8e79b7 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -16,16 +16,6 @@ cmake_minimum_required(VERSION 3.6.0) enable_language(ASM) -# Set as required by ../third_party/dart-sdk/sources.cmake included below -set(DARTSDK_ROOT ../third_party/dart-sdk/) - -# Import sources generated by tool/update-dart-sdk.py -# This provides variables, and requires DARTSDK_ROOT to be set. -# - dart_dl_sources -include( - ../third_party/dart-sdk/sources.cmake -) - # Set as required by android-sources.cmake included below set(BORINGSSL_ROOT ../third_party/boringssl/) @@ -69,9 +59,7 @@ add_library( # Source files ../src/webcrypto.c - ../src/webcrypto_dart_dl.c ../src/symbols.generated.c - ${dart_dl_sources} ${crypto_sources} ${crypto_sources_ARCH} ) @@ -81,7 +69,6 @@ target_include_directories( PRIVATE - ../third_party/dart-sdk/src/runtime/ ../third_party/boringssl/src/include/ ) diff --git a/example/pubspec.lock b/example/pubspec.lock index 9111bbaa..bc932a5b 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,21 +7,21 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "46.0.0" + version: "47.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "4.6.0" + version: "4.7.0" archive: dependency: transitive description: name: archive url: "https://pub.dartlang.org" source: hosted - version: "3.1.11" + version: "3.3.0" args: dependency: transitive description: @@ -35,7 +35,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -49,21 +49,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.2.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: @@ -77,21 +70,21 @@ packages: name: convert url: "https://pub.dartlang.org" source: hosted - version: "3.0.2" + version: "3.1.1" coverage: dependency: transitive description: name: coverage url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.5.0" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "3.0.1" + version: "3.0.2" cupertino_icons: dependency: "direct main" description: @@ -105,7 +98,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" ffi: dependency: transitive description: @@ -172,7 +165,7 @@ packages: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "4.0.1" + version: "4.0.2" integration_test: dependency: "direct dev" description: flutter @@ -198,28 +191,28 @@ packages: name: logging url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "1.1.0" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" mime: dependency: transitive description: @@ -247,7 +240,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" platform: dependency: transitive description: @@ -275,14 +268,14 @@ packages: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.2" shelf: dependency: transitive description: name: shelf url: "https://pub.dartlang.org" source: hosted - version: "1.3.2" + version: "1.4.0" shelf_packages_handler: dependency: transitive description: @@ -329,7 +322,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -350,49 +343,49 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" sync_http: dependency: transitive description: name: sync_http url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.3.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test: dependency: "direct dev" description: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.21.1" + version: "1.21.4" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.12" test_core: dependency: transitive description: name: test_core url: "https://pub.dartlang.org" source: hosted - version: "0.4.13" + version: "0.4.16" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" vector_math: dependency: transitive description: @@ -406,14 +399,14 @@ packages: name: vm_service url: "https://pub.dartlang.org" source: hosted - version: "8.2.2" + version: "9.0.0" watcher: dependency: transitive description: name: watcher url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.0.2" web_socket_channel: dependency: transitive description: @@ -427,7 +420,7 @@ packages: path: ".." relative: true source: path - version: "0.5.3-dev" + version: "0.5.3" webdriver: dependency: transitive description: @@ -441,7 +434,7 @@ packages: name: webkit_inspection_protocol url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" yaml: dependency: transitive description: @@ -450,5 +443,5 @@ packages: source: hosted version: "3.1.1" sdks: - dart: ">=2.17.0 <3.0.0" + dart: ">=2.18.0 <3.0.0" flutter: ">=3.0.0" diff --git a/ios/Classes/include_webcrypto.c b/ios/Classes/include_webcrypto.c index 56310d68..b549aedb 100644 --- a/ios/Classes/include_webcrypto.c +++ b/ios/Classes/include_webcrypto.c @@ -22,4 +22,3 @@ #include "../../src/symbols.generated.c" #include "../../src/webcrypto.c" -#include "../../src/webcrypto_dart_dl.c" diff --git a/ios/webcrypto.podspec b/ios/webcrypto.podspec index 7545ef46..9856ded7 100644 --- a/ios/webcrypto.podspec +++ b/ios/webcrypto.podspec @@ -22,7 +22,6 @@ Pod::Spec.new do |s| # Since we can't embed source from ../third_party/, we have created files # in ios/third_party/... which simply use #include "../...". This is a hack! 'third_party/boringssl/**/*.{c,h}', - 'third_party/dart-sdk/**/*.{c,h}', ] s.compiler_flags = [ '-DOPENSSL_NO_ASM', @@ -35,7 +34,6 @@ Pod::Spec.new do |s| # Enable equivalent of '-Isrc/include' to make '#include ' work 'HEADER_SEARCH_PATHS' => [ '$(PODS_TARGET_SRCROOT)/../third_party/boringssl/src/include', - '$(PODS_TARGET_SRCROOT)/../third_party/dart-sdk/src/runtime', ], 'DEFINES_MODULE' => 'YES', # Flutter.framework does not contain a i386 slice. diff --git a/lib/src/boringssl/bindings/ffigen.yaml b/lib/src/boringssl/bindings/ffigen.yaml index d23cb991..90fbeec3 100644 --- a/lib/src/boringssl/bindings/ffigen.yaml +++ b/lib/src/boringssl/bindings/ffigen.yaml @@ -1,39 +1,26 @@ -name: WebCryptoDartDL -description: 'Bindings to src/webcrypto_dart_dl.h.' +name: WebCrypto +description: 'Bindings to src/webcrypto.h.' output: 'lib/src/boringssl/bindings/generated_bindings.dart' headers: entry-points: - - src/webcrypto_dart_dl.h - - src/webcrypto.c -compiler-opts: '-Ithird_party/dart-sdk/src/runtime/ -Ithird_party/boringssl/src/include' + - src/webcrypto.h comments: style: any length: full sort: true -typedef-map: - # TODO(dacoharkes): https://github.com/dart-lang/sdk/issues/42563 https://github.com/dart-lang/ffigen/issues/7 - size_t: IntPtr macros: - include: - - nothing + include: [] enums: - include: - - nothing + include: [] unnamed-enums: - include: - - nothing + include: [] globals: - include: - - nothing + include: [] structs: - include: - - nothing + include: [] dependency-only: opaque functions: include: - # Keep consistent with src/symbols.yaml. - - webcrypto_dart_dl_attach_finalizer - - webcrypto_dart_dl_initialize - webcrypto_lookup_symbol preamble: | // Copyright 2021 Google LLC @@ -51,4 +38,4 @@ preamble: | // limitations under the License. // // ignore_for_file: unused_element - + // ignore_for_file: non_constant_identifier_names diff --git a/lib/src/boringssl/bindings/generated_bindings.dart b/lib/src/boringssl/bindings/generated_bindings.dart index a54c690a..19733c60 100644 --- a/lib/src/boringssl/bindings/generated_bindings.dart +++ b/lib/src/boringssl/bindings/generated_bindings.dart @@ -13,78 +13,29 @@ // limitations under the License. // // ignore_for_file: unused_element +// ignore_for_file: non_constant_identifier_names // AUTO GENERATED FILE, DO NOT EDIT. // // Generated by `package:ffigen`. import 'dart:ffi' as ffi; -/// Bindings to src/webcrypto_dart_dl.h. -class WebCryptoDartDL { +/// Bindings to src/webcrypto.h. +class WebCrypto { /// Holds the symbol lookup function. final ffi.Pointer Function(String symbolName) _lookup; /// The symbols are looked up in [dynamicLibrary]. - WebCryptoDartDL(ffi.DynamicLibrary dynamicLibrary) + WebCrypto(ffi.DynamicLibrary dynamicLibrary) : _lookup = dynamicLibrary.lookup; /// The symbols are looked up with [lookup]. - WebCryptoDartDL.fromLookup( + WebCrypto.fromLookup( ffi.Pointer Function(String symbolName) lookup) : _lookup = lookup; - /// Attach a finalizer for pointer to object, such that `finalizer(pointer)` will - /// be called when `object` is collected by the Dart garbage collector. - /// - /// The external_allocation_size is used by the Dart garbage collector as a hint - /// about the size of the external allocation. - /// - /// Returns 1 on success. - int webcrypto_dart_dl_attach_finalizer( - Object object, - ffi.Pointer pointer, - ffi.Pointer> finalizer, - int external_allocation_size, - ) { - return _webcrypto_dart_dl_attach_finalizer( - object, - pointer, - finalizer, - external_allocation_size, - ); - } - - late final _webcrypto_dart_dl_attach_finalizer_ptr = - _lookup>( - 'webcrypto_dart_dl_attach_finalizer'); - late final _dart_webcrypto_dart_dl_attach_finalizer - _webcrypto_dart_dl_attach_finalizer = - _webcrypto_dart_dl_attach_finalizer_ptr - .asFunction<_dart_webcrypto_dart_dl_attach_finalizer>(); - - /// Initialize Dart API with dynamic linking. - /// - /// Must be called with `NativeApi.initializeApiDLData` from `dart:ffi`, before - /// using other functions. - /// - /// Returns 1 on success. - int webcrypto_dart_dl_initialize( - ffi.Pointer initialize_api_dl_data, - ) { - return _webcrypto_dart_dl_initialize( - initialize_api_dl_data, - ); - } - - late final _webcrypto_dart_dl_initialize_ptr = - _lookup>( - 'webcrypto_dart_dl_initialize'); - late final _dart_webcrypto_dart_dl_initialize _webcrypto_dart_dl_initialize = - _webcrypto_dart_dl_initialize_ptr - .asFunction<_dart_webcrypto_dart_dl_initialize>(); - /// Function to lookup BoringSSL symbols based on index in the Sym enum. /// See src/symbols.yaml for details. ffi.Pointer webcrypto_lookup_symbol( @@ -95,45 +46,9 @@ class WebCryptoDartDL { ); } - late final _webcrypto_lookup_symbol_ptr = - _lookup>( + late final _webcrypto_lookup_symbolPtr = + _lookup Function(ffi.Int32)>>( 'webcrypto_lookup_symbol'); - late final _dart_webcrypto_lookup_symbol _webcrypto_lookup_symbol = - _webcrypto_lookup_symbol_ptr.asFunction<_dart_webcrypto_lookup_symbol>(); + late final _webcrypto_lookup_symbol = _webcrypto_lookup_symbolPtr + .asFunction Function(int)>(); } - -class _Dart_Handle extends ffi.Opaque {} - -typedef webcrypto_finalizer_t = ffi.Void Function( - ffi.Pointer, -); - -typedef _c_webcrypto_dart_dl_attach_finalizer = ffi.Int32 Function( - ffi.Handle object, - ffi.Pointer pointer, - ffi.Pointer> finalizer, - ffi.IntPtr external_allocation_size, -); - -typedef _dart_webcrypto_dart_dl_attach_finalizer = int Function( - Object object, - ffi.Pointer pointer, - ffi.Pointer> finalizer, - int external_allocation_size, -); - -typedef _c_webcrypto_dart_dl_initialize = ffi.Int32 Function( - ffi.Pointer initialize_api_dl_data, -); - -typedef _dart_webcrypto_dart_dl_initialize = int Function( - ffi.Pointer initialize_api_dl_data, -); - -typedef _c_webcrypto_lookup_symbol = ffi.Pointer Function( - ffi.Int32 index, -); - -typedef _dart_webcrypto_lookup_symbol = ffi.Pointer Function( - int index, -); diff --git a/lib/src/boringssl/lookup/lookup.dart b/lib/src/boringssl/lookup/lookup.dart index 593fac13..e12c04e7 100644 --- a/lib/src/boringssl/lookup/lookup.dart +++ b/lib/src/boringssl/lookup/lookup.dart @@ -29,21 +29,18 @@ export 'symbols.generated.dart' show Sym; /// Dynamically load `webcrypto_lookup_symbol` function. final Pointer Function(String symbolName) lookup = () { try { - final library = Platform.isAndroid || Platform.isLinux + final library = Platform.isAndroid || Platform.isLinux || Platform.isMacOS ? DynamicLibrary.open('libwebcrypto.so') : DynamicLibrary.executable(); // Try to lookup the 'webcrypto_lookup_symbol' symbol. - final webcryptoDartDL = WebCryptoDartDL(library); - final webcrypto_lookup_symbol = webcryptoDartDL.webcrypto_lookup_symbol; + final webcrypto = WebCrypto(library); + final webcrypto_lookup_symbol = webcrypto.webcrypto_lookup_symbol; // Return a function from Sym to lookup using `webcrypto_lookup_symbol` Pointer lookup(String s) => webcrypto_lookup_symbol(symFromString(s).index).cast(); - // Initialize the dynamic linking with Dart. - initialize_dart_dl(lookup); - return lookup; } on ArgumentError { final lookup = lookupLibraryInDotDartTool(); @@ -65,9 +62,6 @@ final Pointer Function(String symbolName) /// Gives access to BoringSSL symbols. final BoringSsl ssl = BoringSsl.fromLookup(_cachedLookup); -/// Gives access to WebCrypto symbols. -final WebCryptoDartDL dl = WebCryptoDartDL.fromLookup(_cachedLookup); - /// ERR_GET_LIB returns the library code for the error. This is one of the /// ERR_LIB_* values. /// diff --git a/lib/src/boringssl/lookup/symbols.generated.dart b/lib/src/boringssl/lookup/symbols.generated.dart index 762fff1f..b5627c84 100644 --- a/lib/src/boringssl/lookup/symbols.generated.dart +++ b/lib/src/boringssl/lookup/symbols.generated.dart @@ -20,8 +20,6 @@ library symbols.generated; /// BoringSSL symbols used in `package:webcrypto`. enum Sym { - webcrypto_dart_dl_initialize, - webcrypto_dart_dl_attach_finalizer, BN_bin2bn, BN_bn2bin_padded, BN_free, @@ -161,8 +159,6 @@ enum Sym { } const _SymName = [ - 'webcrypto_dart_dl_initialize', - 'webcrypto_dart_dl_attach_finalizer', 'BN_bin2bn', 'BN_bn2bin_padded', 'BN_free', diff --git a/lib/src/boringssl/lookup/utils.dart b/lib/src/boringssl/lookup/utils.dart index 1bbfb6e2..261a30d1 100644 --- a/lib/src/boringssl/lookup/utils.dart +++ b/lib/src/boringssl/lookup/utils.dart @@ -38,8 +38,7 @@ String get libraryFileName { ); } -/// Look for the webcrypto binary library in the `.dart_tool/webcrypto/` folder, -/// and initialize it with [initialize_dart_dl]. +/// Look for the webcrypto binary library in the `.dart_tool/webcrypto/` folder. /// /// Returns `null` if it could not be found. Pointer Function(String symbolName)? @@ -56,40 +55,18 @@ Pointer Function(String symbolName)? final library = DynamicLibrary.open(libraryFile.path); // Try to lookup the 'webcrypto_lookup_symbol' symbol. - final webcryptoDartDL = WebCryptoDartDL(library); - final webcrypto_lookup_symbol = webcryptoDartDL.webcrypto_lookup_symbol; + final webcrypto = WebCrypto(library); + final webcrypto_lookup_symbol = webcrypto.webcrypto_lookup_symbol; // Return a function from Sym to lookup using `webcrypto_lookup_symbol` Pointer lookup(String s) => webcrypto_lookup_symbol(symFromString(s).index).cast(); - // Initialize library - initialize_dart_dl(lookup); - return lookup; } return null; } -/// Initialize library for use with Dart dynamic linking, by calling -/// `webcrypto_dart_dl_initialize`. -/// -/// This must be called before we start using the library. -void initialize_dart_dl( - Pointer Function(String) lookup) { - final webcrypto_dart_dl_initialize = - WebCryptoDartDL.fromLookup(lookup).webcrypto_dart_dl_initialize; - - if (webcrypto_dart_dl_initialize(NativeApi.initializeApiDLData) != 1) { - throw UnsupportedError( - 'package:webcrypto does not work with this version of the Dart DL API.' - 'Please update to a newer version of package:webcrypto. And ensure that' - 'you have rebuilt the current version with ' - '`flutter pub run webcrypt:setup` if running locally.', - ); - } -} - /// Find the `.dart_tool/` folder, returns `null` if unable to find it. Uri? _findDotDartTool() { // HACK: We have no good mechanism for finding the library created by: diff --git a/lib/src/impl_ffi/impl_ffi.aescbc.dart b/lib/src/impl_ffi/impl_ffi.aescbc.dart index 42c25434..d65e95b2 100644 --- a/lib/src/impl_ffi/impl_ffi.aescbc.dart +++ b/lib/src/impl_ffi/impl_ffi.aescbc.dart @@ -39,7 +39,7 @@ Stream _aesCbcEncryptOrDecrypt( assert(key.length == 16 || key.length == 32); final cipher = key.length == 16 ? ssl.EVP_aes_128_cbc() : ssl.EVP_aes_256_cbc(); - final blockSize = AES_BLOCK_SIZE; + const blockSize = AES_BLOCK_SIZE; final ivSize = ssl.EVP_CIPHER_iv_length(cipher); if (iv.length != ivSize) { @@ -68,7 +68,7 @@ Stream _aesCbcEncryptOrDecrypt( final outData = outBuf.asTypedList(bufSize + blockSize); // Allocate and output length integer - final outLen = scope(); + final outLen = scope(); // Process data from source await for (final data in source) { diff --git a/lib/src/impl_ffi/impl_ffi.aesctr.dart b/lib/src/impl_ffi/impl_ffi.aesctr.dart index a30801ac..bef57b22 100644 --- a/lib/src/impl_ffi/impl_ffi.aesctr.dart +++ b/lib/src/impl_ffi/impl_ffi.aesctr.dart @@ -113,7 +113,7 @@ Stream _aesCtrEncryptOrDecrypt( final outData = outBuf.asTypedList(bufSize + blockSize); // Allocate and output length integer - final outLen = scope(); + final outLen = scope(); // Process data from source var isBeforeWrapAround = true; diff --git a/lib/src/impl_ffi/impl_ffi.aesgcm.dart b/lib/src/impl_ffi/impl_ffi.aesgcm.dart index 07a73b8f..e1e934c0 100644 --- a/lib/src/impl_ffi/impl_ffi.aesgcm.dart +++ b/lib/src/impl_ffi/impl_ffi.aesgcm.dart @@ -74,7 +74,7 @@ Future _aesGcmEncryptDecrypt( ); if (isEncrypt) { - final outLen = scope(); + final outLen = scope(); final maxOut = data.length + ssl.EVP_AEAD_max_overhead(aead); return _withOutPointer(maxOut, (ffi.Pointer out) { _checkOpIsOne(ssl.EVP_AEAD_CTX_seal( @@ -91,7 +91,7 @@ Future _aesGcmEncryptDecrypt( )); }).sublist(0, outLen.value); } else { - final outLen = scope(); + final outLen = scope(); return _withOutPointer(data.length, (ffi.Pointer out) { _checkOpIsOne(ssl.EVP_AEAD_CTX_open( ctx, diff --git a/lib/src/impl_ffi/impl_ffi.dart b/lib/src/impl_ffi/impl_ffi.dart index 3c47d0d7..cd4e3778 100644 --- a/lib/src/impl_ffi/impl_ffi.dart +++ b/lib/src/impl_ffi/impl_ffi.dart @@ -26,8 +26,7 @@ import 'package:webcrypto/src/third_party/boringssl/generated_bindings.dart'; import '../jsonwebkey.dart' show JsonWebKey; import '../webcrypto/webcrypto.dart'; -import '../boringssl/lookup/lookup.dart' - show ssl, dl, ERR_GET_LIB, ERR_GET_REASON; +import '../boringssl/lookup/lookup.dart' show ssl, ERR_GET_LIB, ERR_GET_REASON; part 'impl_ffi.aescbc.dart'; part 'impl_ffi.aesctr.dart'; diff --git a/lib/src/impl_ffi/impl_ffi.ecdsa.dart b/lib/src/impl_ffi/impl_ffi.ecdsa.dart index 2dd2cad0..beeef71f 100644 --- a/lib/src/impl_ffi/impl_ffi.ecdsa.dart +++ b/lib/src/impl_ffi/impl_ffi.ecdsa.dart @@ -220,8 +220,8 @@ class _EcdsaPrivateKey implements EcdsaPrivateKey { )); await _streamToUpdate(data, ctx, ssl.EVP_DigestSignUpdate); - return _withAllocation(_sslAlloc(), - (ffi.Pointer len) { + return _withAllocation(_sslAlloc(), + (ffi.Pointer len) { len.value = 0; _checkOpIsOne(ssl.EVP_DigestSignFinal(ctx, ffi.nullptr, len)); return _withOutPointer(len.value, (ffi.Pointer p) { diff --git a/lib/src/impl_ffi/impl_ffi.hmac.dart b/lib/src/impl_ffi/impl_ffi.hmac.dart index b3a29e3b..248980e8 100644 --- a/lib/src/impl_ffi/impl_ffi.hmac.dart +++ b/lib/src/impl_ffi/impl_ffi.hmac.dart @@ -126,8 +126,8 @@ class _HmacSecretKey implements HmacSecretKey { final size = ssl.HMAC_size(ctx); _checkOp(size > 0); - return _withAllocation(_sslAlloc(), - (ffi.Pointer psize) async { + return _withAllocation(_sslAlloc(), + (ffi.Pointer psize) async { psize.value = size; return _withOutPointer(size, (ffi.Pointer p) { _checkOp(ssl.HMAC_Final(ctx, p, psize) == 1); diff --git a/lib/src/impl_ffi/impl_ffi.rsaoaep.dart b/lib/src/impl_ffi/impl_ffi.rsaoaep.dart index 2e56248f..9fa23772 100644 --- a/lib/src/impl_ffi/impl_ffi.rsaoaep.dart +++ b/lib/src/impl_ffi/impl_ffi.rsaoaep.dart @@ -112,7 +112,7 @@ Future _rsaOaepeEncryptOrDecryptBytes( int Function( ffi.Pointer, ffi.Pointer, - ffi.Pointer, + ffi.Pointer, ffi.Pointer, int, ) @@ -149,8 +149,8 @@ Future _rsaOaepeEncryptOrDecryptBytes( } return _withDataAsPointer(data, (ffi.Pointer input) { - return _withAllocation(_sslAlloc(), - (ffi.Pointer len) { + return _withAllocation(_sslAlloc(), + (ffi.Pointer len) { len.value = 0; _checkOpIsOne(encryptOrDecryptFn( ctx, diff --git a/lib/src/impl_ffi/impl_ffi.rsapss.dart b/lib/src/impl_ffi/impl_ffi.rsapss.dart index 01462646..df6779f8 100644 --- a/lib/src/impl_ffi/impl_ffi.rsapss.dart +++ b/lib/src/impl_ffi/impl_ffi.rsapss.dart @@ -137,8 +137,8 @@ class _RsaPssPrivateKey implements RsaPssPrivateKey { )); _checkDataIsOne(ssl.EVP_PKEY_CTX_set_rsa_mgf1_md(pctx.value, _hash.MD)); await _streamToUpdate(data, ctx, ssl.EVP_DigestSignUpdate); - return _withAllocation(_sslAlloc(), - (ffi.Pointer len) { + return _withAllocation(_sslAlloc(), + (ffi.Pointer len) { len.value = 0; _checkOpIsOne(ssl.EVP_DigestSignFinal(ctx, ffi.nullptr, len)); return _withOutPointer(len.value, (ffi.Pointer p) { diff --git a/lib/src/impl_ffi/impl_ffi.rsassapkcs1v15.dart b/lib/src/impl_ffi/impl_ffi.rsassapkcs1v15.dart index 5892cf39..ea616c1a 100644 --- a/lib/src/impl_ffi/impl_ffi.rsassapkcs1v15.dart +++ b/lib/src/impl_ffi/impl_ffi.rsassapkcs1v15.dart @@ -123,8 +123,8 @@ class _RsassaPkcs1V15PrivateKey implements RsassaPkcs1V15PrivateKey { ssl.EVP_PKEY_CTX_set_rsa_padding(pctx.value, RSA_PKCS1_PADDING), ); await _streamToUpdate(data, ctx, ssl.EVP_DigestSignUpdate); - return _withAllocation(_sslAlloc(), - (ffi.Pointer len) { + return _withAllocation(_sslAlloc(), + (ffi.Pointer len) { len.value = 0; _checkOpIsOne(ssl.EVP_DigestSignFinal(ctx, ffi.nullptr, len)); return _withOutPointer(len.value, (ffi.Pointer p) { diff --git a/lib/src/impl_ffi/impl_ffi.utils.dart b/lib/src/impl_ffi/impl_ffi.utils.dart index 540bbacb..58b0c468 100644 --- a/lib/src/impl_ffi/impl_ffi.utils.dart +++ b/lib/src/impl_ffi/impl_ffi.utils.dart @@ -14,27 +14,24 @@ part of impl_ffi; -/// Function that can't be inlined to be used for preventing [obj] from being -/// garbage collected. -@pragma('vm:never-inline') -Object _finalizerReachabilityFence(Object obj) { - return obj; -} +/// Wrapper around [EVP_PKEY] which attaches finalizer and ensure that the +/// [ffi.Finalizable] is kept in scope while the [EVP_PKEY] is used. +class _EvpPKey implements ffi.Finalizable { + /// We don't really have an estimate of how much space the EVP_PKEY structure + /// takes up, but if we make it some non-trivial size then hopefully the GC + /// will prioritize freeing them. + static const _externalSizeEstimate = 4096; + + static final _finalizer = + ffi.NativeFinalizer(ssl.addresses.EVP_PKEY_free.cast()); -/// Wrapper around [EVP_PKEY] which attaches finalizer and ensures that the -/// [_finalizerReachabilityFence] is used after usage. -/// -/// The [_finalizerReachabilityFence] ensures that the [_EvpPKey] is not garbage -/// collected while the wrapped key is use. Thus, we can be sure the finalizer -/// won't be called while the wrapped key is in use. -class _EvpPKey { final ffi.Pointer _pkey; /// Allocate new [EVP_PKEY], attach finalizer and return the wrapped key. factory _EvpPKey() { - final _pkey = ssl.EVP_PKEY_new(); - _checkOp(_pkey.address != 0, fallback: 'allocation failure'); - return _EvpPKey.wrap(_pkey); + final pkey = ssl.EVP_PKEY_new(); + _checkOp(pkey.address != 0, fallback: 'allocation failure'); + return _EvpPKey.wrap(pkey); } /// Wrap existing [EVP_PKEY], this will attach a finalizer. @@ -43,30 +40,13 @@ class _EvpPKey { /// [use]. Otherwise, the garbage collect may be calling the finalizer while /// the key is in use. _EvpPKey.wrap(this._pkey) { - final ret = dl.webcrypto_dart_dl_attach_finalizer( - this, - _pkey.cast(), - ssl.addresses.EVP_PKEY_free.cast(), - // We don't really have an estimate of how much space the EVP_PKEY structure - // takes up, but if we make it some non-trivial size then hopefully the GC - // will prioritize freeing them. - 4096, - ); - if (ret != 1) { - throw AssertionError('package:webcrypto failed to attached finalizer'); - } + _finalizer.attach(this, _pkey.cast(), externalSize: _externalSizeEstimate); } /// Use the wrapped [EVP_PKEY] in callback [fn]. /// /// Note. [fn] is not allowed to return a [Future]. - T use(T Function(ffi.Pointer pkey) fn) { - try { - return fn(_pkey); - } finally { - _finalizerReachabilityFence(this); - } - } + T use(T Function(ffi.Pointer pkey) fn) => fn(_pkey); } /// Extension of native function that takes a [EVP_PKEY], making it easy to call @@ -163,7 +143,7 @@ String? _extractError() { return null; } const N = 4096; // Max error message size - final data = _withOutPointer(N, (ffi.Pointer p) { + final data = _withOutPointer(N, (ffi.Pointer p) { ssl.ERR_error_string_n(err, p, N); }); // Take everything until '\0' diff --git a/lib/src/testing/utils/err_stack_ffi.dart b/lib/src/testing/utils/err_stack_ffi.dart index 9a553b71..b8cd4ce3 100644 --- a/lib/src/testing/utils/err_stack_ffi.dart +++ b/lib/src/testing/utils/err_stack_ffi.dart @@ -37,7 +37,7 @@ Future checkErrorStack(FutureOr Function() fn) async { return ret; } const N = 4096; // Max error message size - final p = ffi.calloc(N); + final p = ffi.calloc(N); try { ssl.ERR_error_string_n(err, p, N); final data = p.cast().asTypedList(N); diff --git a/lib/src/third_party/boringssl/ffigen.yaml b/lib/src/third_party/boringssl/ffigen.yaml index 29496119..d27705cc 100644 --- a/lib/src/third_party/boringssl/ffigen.yaml +++ b/lib/src/third_party/boringssl/ffigen.yaml @@ -1,17 +1,34 @@ name: BoringSsl description: 'Bindings to BoringSSL.' +language: c output: 'lib/src/third_party/boringssl/generated_bindings.dart' headers: entry-points: - - 'third_party/boringssl/src/include/openssl/*.h' + # bytestring.h MUST be the first header, otherwise structs are just left + # as opaque. + - 'third_party/boringssl/src/include/openssl/bytestring.h' + - 'third_party/boringssl/src/include/openssl/aead.h' + - 'third_party/boringssl/src/include/openssl/aes.h' + - 'third_party/boringssl/src/include/openssl/bn.h' + - 'third_party/boringssl/src/include/openssl/cipher.h' + - 'third_party/boringssl/src/include/openssl/crypto.h' + - 'third_party/boringssl/src/include/openssl/digest.h' + - 'third_party/boringssl/src/include/openssl/ec_key.h' + - 'third_party/boringssl/src/include/openssl/ec.h' + - 'third_party/boringssl/src/include/openssl/ecdh.h' + - 'third_party/boringssl/src/include/openssl/ecdsa.h' + - 'third_party/boringssl/src/include/openssl/err.h' + - 'third_party/boringssl/src/include/openssl/evp.h' + - 'third_party/boringssl/src/include/openssl/hkdf.h' + - 'third_party/boringssl/src/include/openssl/hmac.h' + - 'third_party/boringssl/src/include/openssl/mem.h' + - 'third_party/boringssl/src/include/openssl/rand.h' + - 'third_party/boringssl/src/include/openssl/rsa.h' compiler-opts: '-Ithird_party/boringssl/src/include' comments: style: any length: full sort: true -typedef-map: - # TODO(dacoharkes): https://github.com/dart-lang/sdk/issues/42563 https://github.com/dart-lang/ffigen/issues/7 - size_t: IntPtr macros: include: - AES_BLOCK_SIZE @@ -32,33 +49,9 @@ unnamed-enums: include: - ERR_LIB_HKDF structs: - include: - - 'nothing' - rename: - bignum_ctx: BN_CTX - bignum_st: BIGNUM - bn_blinding_st: BN_BLINDING - bn_gencb_st: BN_GENCB - bn_mont_ctx_st: BN_MONT_CTX - cbb_st: CBB - cbs_st: CBS - crypto_ex_data_st: CRYPTO_EX_DATA - ecdsa_sig_st: ECDSA_SIG - ec_group_st: EC_GROUP - ec_key_st: EC_KEY - ec_point_st: EC_POINT - engine_st: ENGINE - env_md_ctx_st: EVP_MD_CTX - env_md_st: EVP_MD - evp_aead_st: EVP_AEAD - evp_cipher_ctx_st: EVP_CIPHER_CTX - evp_cipher_st: EVP_CIPHER - evp_pkey_asn1_method_st: EVP_PKEY_ASN1_METHOD - evp_pkey_ctx_st: EVP_PKEY_CTX - evp_pkey_st: EVP_PKEY - hmac_ctx_st: HMAC_CTX - rsa_meth_st: RSA_METHOD - rsa_st: RSA + #include: + # - cbs_st + # - cbb_st dependency-only: opaque functions: include: @@ -262,4 +255,3 @@ preamble: | // ignore_for_file: non_constant_identifier_names // ignore_for_file: unused_element // ignore_for_file: unused_field - diff --git a/lib/src/third_party/boringssl/generated_bindings.dart b/lib/src/third_party/boringssl/generated_bindings.dart index cc8e3843..efe62dab 100644 --- a/lib/src/third_party/boringssl/generated_bindings.dart +++ b/lib/src/third_party/boringssl/generated_bindings.dart @@ -75,161 +75,6 @@ class BoringSsl { lookup) : _lookup = lookup; - late final ffi.Pointer _ACCESS_DESCRIPTION_it = - _lookup('ACCESS_DESCRIPTION_it'); - - ffi.Pointer get ACCESS_DESCRIPTION_it => _ACCESS_DESCRIPTION_it; - - late final ffi.Pointer _ASN1_ANY_it = - _lookup('ASN1_ANY_it'); - - ffi.Pointer get ASN1_ANY_it => _ASN1_ANY_it; - - late final ffi.Pointer _ASN1_BIT_STRING_it = - _lookup('ASN1_BIT_STRING_it'); - - ffi.Pointer get ASN1_BIT_STRING_it => _ASN1_BIT_STRING_it; - - late final ffi.Pointer _ASN1_BMPSTRING_it = - _lookup('ASN1_BMPSTRING_it'); - - ffi.Pointer get ASN1_BMPSTRING_it => _ASN1_BMPSTRING_it; - - late final ffi.Pointer _ASN1_BOOLEAN_it = - _lookup('ASN1_BOOLEAN_it'); - - ffi.Pointer get ASN1_BOOLEAN_it => _ASN1_BOOLEAN_it; - - late final ffi.Pointer _ASN1_ENUMERATED_it = - _lookup('ASN1_ENUMERATED_it'); - - ffi.Pointer get ASN1_ENUMERATED_it => _ASN1_ENUMERATED_it; - - late final ffi.Pointer _ASN1_FBOOLEAN_it = - _lookup('ASN1_FBOOLEAN_it'); - - ffi.Pointer get ASN1_FBOOLEAN_it => _ASN1_FBOOLEAN_it; - - late final ffi.Pointer _ASN1_GENERALIZEDTIME_it = - _lookup('ASN1_GENERALIZEDTIME_it'); - - ffi.Pointer get ASN1_GENERALIZEDTIME_it => - _ASN1_GENERALIZEDTIME_it; - - late final ffi.Pointer _ASN1_GENERALSTRING_it = - _lookup('ASN1_GENERALSTRING_it'); - - ffi.Pointer get ASN1_GENERALSTRING_it => _ASN1_GENERALSTRING_it; - - late final ffi.Pointer _ASN1_IA5STRING_it = - _lookup('ASN1_IA5STRING_it'); - - ffi.Pointer get ASN1_IA5STRING_it => _ASN1_IA5STRING_it; - - late final ffi.Pointer _ASN1_INTEGER_it = - _lookup('ASN1_INTEGER_it'); - - ffi.Pointer get ASN1_INTEGER_it => _ASN1_INTEGER_it; - - late final ffi.Pointer _ASN1_NULL_it = - _lookup('ASN1_NULL_it'); - - ffi.Pointer get ASN1_NULL_it => _ASN1_NULL_it; - - late final ffi.Pointer _ASN1_OBJECT_it = - _lookup('ASN1_OBJECT_it'); - - ffi.Pointer get ASN1_OBJECT_it => _ASN1_OBJECT_it; - - late final ffi.Pointer _ASN1_OCTET_STRING_NDEF_it = - _lookup('ASN1_OCTET_STRING_NDEF_it'); - - ffi.Pointer get ASN1_OCTET_STRING_NDEF_it => - _ASN1_OCTET_STRING_NDEF_it; - - late final ffi.Pointer _ASN1_OCTET_STRING_it = - _lookup('ASN1_OCTET_STRING_it'); - - ffi.Pointer get ASN1_OCTET_STRING_it => _ASN1_OCTET_STRING_it; - - late final ffi.Pointer _ASN1_PRINTABLESTRING_it = - _lookup('ASN1_PRINTABLESTRING_it'); - - ffi.Pointer get ASN1_PRINTABLESTRING_it => - _ASN1_PRINTABLESTRING_it; - - late final ffi.Pointer _ASN1_PRINTABLE_it = - _lookup('ASN1_PRINTABLE_it'); - - ffi.Pointer get ASN1_PRINTABLE_it => _ASN1_PRINTABLE_it; - - late final ffi.Pointer _ASN1_SEQUENCE_ANY_it = - _lookup('ASN1_SEQUENCE_ANY_it'); - - ffi.Pointer get ASN1_SEQUENCE_ANY_it => _ASN1_SEQUENCE_ANY_it; - - late final ffi.Pointer _ASN1_SEQUENCE_it = - _lookup('ASN1_SEQUENCE_it'); - - ffi.Pointer get ASN1_SEQUENCE_it => _ASN1_SEQUENCE_it; - - late final ffi.Pointer _ASN1_SET_ANY_it = - _lookup('ASN1_SET_ANY_it'); - - ffi.Pointer get ASN1_SET_ANY_it => _ASN1_SET_ANY_it; - - late final ffi.Pointer _ASN1_T61STRING_it = - _lookup('ASN1_T61STRING_it'); - - ffi.Pointer get ASN1_T61STRING_it => _ASN1_T61STRING_it; - - late final ffi.Pointer _ASN1_TBOOLEAN_it = - _lookup('ASN1_TBOOLEAN_it'); - - ffi.Pointer get ASN1_TBOOLEAN_it => _ASN1_TBOOLEAN_it; - - late final ffi.Pointer _ASN1_TIME_it = - _lookup('ASN1_TIME_it'); - - ffi.Pointer get ASN1_TIME_it => _ASN1_TIME_it; - - late final ffi.Pointer _ASN1_UNIVERSALSTRING_it = - _lookup('ASN1_UNIVERSALSTRING_it'); - - ffi.Pointer get ASN1_UNIVERSALSTRING_it => - _ASN1_UNIVERSALSTRING_it; - - late final ffi.Pointer _ASN1_UTCTIME_it = - _lookup('ASN1_UTCTIME_it'); - - ffi.Pointer get ASN1_UTCTIME_it => _ASN1_UTCTIME_it; - - late final ffi.Pointer _ASN1_UTF8STRING_it = - _lookup('ASN1_UTF8STRING_it'); - - ffi.Pointer get ASN1_UTF8STRING_it => _ASN1_UTF8STRING_it; - - late final ffi.Pointer _ASN1_VISIBLESTRING_it = - _lookup('ASN1_VISIBLESTRING_it'); - - ffi.Pointer get ASN1_VISIBLESTRING_it => _ASN1_VISIBLESTRING_it; - - late final ffi.Pointer _AUTHORITY_INFO_ACCESS_it = - _lookup('AUTHORITY_INFO_ACCESS_it'); - - ffi.Pointer get AUTHORITY_INFO_ACCESS_it => - _AUTHORITY_INFO_ACCESS_it; - - late final ffi.Pointer _AUTHORITY_KEYID_it = - _lookup('AUTHORITY_KEYID_it'); - - ffi.Pointer get AUTHORITY_KEYID_it => _AUTHORITY_KEYID_it; - - late final ffi.Pointer _BASIC_CONSTRAINTS_it = - _lookup('BASIC_CONSTRAINTS_it'); - - ffi.Pointer get BASIC_CONSTRAINTS_it => _BASIC_CONSTRAINTS_it; - /// BN_add sets |r| = |a| + |b|, where |r| may be the same pointer as either |a| /// or |b|. It returns one on success and zero on allocation failure. int BN_add( @@ -244,29 +89,37 @@ class BoringSsl { ); } - late final _BN_add_ptr = _lookup>('BN_add'); - late final _dart_BN_add _BN_add = _BN_add_ptr.asFunction<_dart_BN_add>(); + late final _BN_addPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>>('BN_add'); + late final _BN_add = _BN_addPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer, ffi.Pointer)>(); /// BN_bin2bn sets |*ret| to the value of |len| bytes from |in|, interpreted as /// a big-endian number, and returns |ret|. If |ret| is NULL then a fresh /// |BIGNUM| is allocated and returned. It returns NULL on allocation /// failure. ffi.Pointer BN_bin2bn( - ffi.Pointer in_1, + ffi.Pointer in1, int len, ffi.Pointer ret, ) { return _BN_bin2bn( - in_1, + in1, len, ret, ); } - late final _BN_bin2bn_ptr = - _lookup>('BN_bin2bn'); - late final _dart_BN_bin2bn _BN_bin2bn = - _BN_bin2bn_ptr.asFunction<_dart_BN_bin2bn>(); + late final _BN_bin2bnPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, ffi.Size, + ffi.Pointer)>>('BN_bin2bn'); + late final _BN_bin2bn = _BN_bin2bnPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int, ffi.Pointer)>(); /// BN_bn2bin_padded serialises the absolute value of |in| to |out| as a /// big-endian integer. The integer is padded with leading zeros up to size @@ -275,19 +128,21 @@ class BoringSsl { int BN_bn2bin_padded( ffi.Pointer out, int len, - ffi.Pointer in_1, + ffi.Pointer in1, ) { return _BN_bn2bin_padded( out, len, - in_1, + in1, ); } - late final _BN_bn2bin_padded_ptr = - _lookup>('BN_bn2bin_padded'); - late final _dart_BN_bn2bin_padded _BN_bn2bin_padded = - _BN_bn2bin_padded_ptr.asFunction<_dart_BN_bn2bin_padded>(); + late final _BN_bn2bin_paddedPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Size, + ffi.Pointer)>>('BN_bn2bin_padded'); + late final _BN_bn2bin_padded = _BN_bn2bin_paddedPtr.asFunction< + int Function(ffi.Pointer, int, ffi.Pointer)>(); /// BN_cmp returns a value less than, equal to or greater than zero if |a| is /// less than, equal to or greater than |b|, respectively. @@ -301,8 +156,12 @@ class BoringSsl { ); } - late final _BN_cmp_ptr = _lookup>('BN_cmp'); - late final _dart_BN_cmp _BN_cmp = _BN_cmp_ptr.asFunction<_dart_BN_cmp>(); + late final _BN_cmpPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, ffi.Pointer)>>('BN_cmp'); + late final _BN_cmp = _BN_cmpPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); /// BN_free frees the data referenced by |bn| and, if |bn| was originally /// allocated on the heap, frees |bn| also. @@ -314,8 +173,11 @@ class BoringSsl { ); } - late final _BN_free_ptr = _lookup>('BN_free'); - late final _dart_BN_free _BN_free = _BN_free_ptr.asFunction<_dart_BN_free>(); + late final _BN_freePtr = + _lookup)>>( + 'BN_free'); + late final _BN_free = + _BN_freePtr.asFunction)>(); /// BN_lshift sets |r| equal to |a| << n. The |a| and |r| arguments may be the /// same |BIGNUM|. It returns one on success and zero on allocation failure. @@ -331,18 +193,21 @@ class BoringSsl { ); } - late final _BN_lshift_ptr = - _lookup>('BN_lshift'); - late final _dart_BN_lshift _BN_lshift = - _BN_lshift_ptr.asFunction<_dart_BN_lshift>(); + late final _BN_lshiftPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, ffi.Pointer, ffi.Int)>>('BN_lshift'); + late final _BN_lshift = _BN_lshiftPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, int)>(); /// BN_new creates a new, allocated BIGNUM and initialises it. ffi.Pointer BN_new() { return _BN_new(); } - late final _BN_new_ptr = _lookup>('BN_new'); - late final _dart_BN_new _BN_new = _BN_new_ptr.asFunction<_dart_BN_new>(); + late final _BN_newPtr = + _lookup Function()>>('BN_new'); + late final _BN_new = _BN_newPtr.asFunction Function()>(); /// BN_num_bytes returns the minimum number of bytes needed to represent the /// absolute value of |bn|. @@ -354,10 +219,11 @@ class BoringSsl { ); } - late final _BN_num_bytes_ptr = - _lookup>('BN_num_bytes'); - late final _dart_BN_num_bytes _BN_num_bytes = - _BN_num_bytes_ptr.asFunction<_dart_BN_num_bytes>(); + late final _BN_num_bytesPtr = _lookup< + ffi.NativeFunction)>>( + 'BN_num_bytes'); + late final _BN_num_bytes = + _BN_num_bytesPtr.asFunction)>(); /// BN_set_word sets |bn| to |value|. It returns one on success or zero on /// allocation failure. @@ -371,10 +237,11 @@ class BoringSsl { ); } - late final _BN_set_word_ptr = - _lookup>('BN_set_word'); - late final _dart_BN_set_word _BN_set_word = - _BN_set_word_ptr.asFunction<_dart_BN_set_word>(); + late final _BN_set_wordPtr = _lookup< + ffi.NativeFunction, BN_ULONG)>>( + 'BN_set_word'); + late final _BN_set_word = + _BN_set_wordPtr.asFunction, int)>(); /// BN_sub sets |r| = |a| - |b|, where |r| may be the same pointer as either |a| /// or |b|. It returns one on success and zero on allocation failure. @@ -390,18 +257,24 @@ class BoringSsl { ); } - late final _BN_sub_ptr = _lookup>('BN_sub'); - late final _dart_BN_sub _BN_sub = _BN_sub_ptr.asFunction<_dart_BN_sub>(); + late final _BN_subPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>>('BN_sub'); + late final _BN_sub = _BN_subPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer, ffi.Pointer)>(); /// BN_value_one returns a static BIGNUM with value 1. ffi.Pointer BN_value_one() { return _BN_value_one(); } - late final _BN_value_one_ptr = - _lookup>('BN_value_one'); - late final _dart_BN_value_one _BN_value_one = - _BN_value_one_ptr.asFunction<_dart_BN_value_one>(); + late final _BN_value_onePtr = + _lookup Function()>>( + 'BN_value_one'); + late final _BN_value_one = + _BN_value_onePtr.asFunction Function()>(); /// BORINGSSL_self_test triggers the FIPS KAT-based self tests. It returns one on /// success and zero on error. @@ -409,11 +282,10 @@ class BoringSsl { return _BORINGSSL_self_test(); } - late final _BORINGSSL_self_test_ptr = - _lookup>( - 'BORINGSSL_self_test'); - late final _dart_BORINGSSL_self_test _BORINGSSL_self_test = - _BORINGSSL_self_test_ptr.asFunction<_dart_BORINGSSL_self_test>(); + late final _BORINGSSL_self_testPtr = + _lookup>('BORINGSSL_self_test'); + late final _BORINGSSL_self_test = + _BORINGSSL_self_testPtr.asFunction(); /// CBB_cleanup frees all resources owned by |cbb| and other |CBB| objects /// writing to the same buffer. This should be used in an error case where a @@ -430,10 +302,11 @@ class BoringSsl { ); } - late final _CBB_cleanup_ptr = - _lookup>('CBB_cleanup'); - late final _dart_CBB_cleanup _CBB_cleanup = - _CBB_cleanup_ptr.asFunction<_dart_CBB_cleanup>(); + late final _CBB_cleanupPtr = + _lookup)>>( + 'CBB_cleanup'); + late final _CBB_cleanup = + _CBB_cleanupPtr.asFunction)>(); /// CBB_data returns a pointer to the bytes written to |cbb|. It does not flush /// |cbb|. The pointer is valid until the next operation to |cbb|. @@ -448,10 +321,11 @@ class BoringSsl { ); } - late final _CBB_data_ptr = - _lookup>('CBB_data'); - late final _dart_CBB_data _CBB_data = - _CBB_data_ptr.asFunction<_dart_CBB_data>(); + late final _CBB_dataPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>('CBB_data'); + late final _CBB_data = _CBB_dataPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); /// CBB_flush causes any pending length prefixes to be written out and any child /// |CBB| objects of |cbb| to be invalidated. This allows |cbb| to continue to be @@ -466,10 +340,11 @@ class BoringSsl { ); } - late final _CBB_flush_ptr = - _lookup>('CBB_flush'); - late final _dart_CBB_flush _CBB_flush = - _CBB_flush_ptr.asFunction<_dart_CBB_flush>(); + late final _CBB_flushPtr = + _lookup)>>( + 'CBB_flush'); + late final _CBB_flush = + _CBB_flushPtr.asFunction)>(); /// CBB_init initialises |cbb| with |initial_capacity|. Since a |CBB| grows as /// needed, the |initial_capacity| is just a hint. It returns one on success or @@ -484,10 +359,11 @@ class BoringSsl { ); } - late final _CBB_init_ptr = - _lookup>('CBB_init'); - late final _dart_CBB_init _CBB_init = - _CBB_init_ptr.asFunction<_dart_CBB_init>(); + late final _CBB_initPtr = + _lookup, ffi.Size)>>( + 'CBB_init'); + late final _CBB_init = + _CBB_initPtr.asFunction, int)>(); /// CBB_len returns the number of bytes written to |cbb|. It does not flush /// |cbb|. @@ -502,8 +378,11 @@ class BoringSsl { ); } - late final _CBB_len_ptr = _lookup>('CBB_len'); - late final _dart_CBB_len _CBB_len = _CBB_len_ptr.asFunction<_dart_CBB_len>(); + late final _CBB_lenPtr = + _lookup)>>( + 'CBB_len'); + late final _CBB_len = + _CBB_lenPtr.asFunction)>(); /// CBB_zero sets an uninitialised |cbb| to the zero state. It must be /// initialised with |CBB_init| or |CBB_init_fixed| before use, but it is safe to @@ -517,10 +396,11 @@ class BoringSsl { ); } - late final _CBB_zero_ptr = - _lookup>('CBB_zero'); - late final _dart_CBB_zero _CBB_zero = - _CBB_zero_ptr.asFunction<_dart_CBB_zero>(); + late final _CBB_zeroPtr = + _lookup)>>( + 'CBB_zero'); + late final _CBB_zero = + _CBB_zeroPtr.asFunction)>(); /// CBS_init sets |cbs| to point to |data|. It does not take ownership of /// |data|. @@ -536,21 +416,12 @@ class BoringSsl { ); } - late final _CBS_init_ptr = - _lookup>('CBS_init'); - late final _dart_CBS_init _CBS_init = - _CBS_init_ptr.asFunction<_dart_CBS_init>(); - - late final ffi.Pointer _CERTIFICATEPOLICIES_it = - _lookup('CERTIFICATEPOLICIES_it'); - - ffi.Pointer get CERTIFICATEPOLICIES_it => - _CERTIFICATEPOLICIES_it; - - late final ffi.Pointer _CRL_DIST_POINTS_it = - _lookup('CRL_DIST_POINTS_it'); - - ffi.Pointer get CRL_DIST_POINTS_it => _CRL_DIST_POINTS_it; + late final _CBS_initPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, ffi.Pointer, ffi.Size)>>('CBS_init'); + late final _CBS_init = _CBS_initPtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer, int)>(); /// CRYPTO_memcmp returns zero iff the |len| bytes at |a| and |b| are equal. It /// takes an amount of time dependent on |len|, but independent of the contents @@ -569,30 +440,12 @@ class BoringSsl { ); } - late final _CRYPTO_memcmp_ptr = - _lookup>('CRYPTO_memcmp'); - late final _dart_CRYPTO_memcmp _CRYPTO_memcmp = - _CRYPTO_memcmp_ptr.asFunction<_dart_CRYPTO_memcmp>(); - - late final ffi.Pointer _DIRECTORYSTRING_it = - _lookup('DIRECTORYSTRING_it'); - - ffi.Pointer get DIRECTORYSTRING_it => _DIRECTORYSTRING_it; - - late final ffi.Pointer _DISPLAYTEXT_it = - _lookup('DISPLAYTEXT_it'); - - ffi.Pointer get DISPLAYTEXT_it => _DISPLAYTEXT_it; - - late final ffi.Pointer _DIST_POINT_NAME_it = - _lookup('DIST_POINT_NAME_it'); - - ffi.Pointer get DIST_POINT_NAME_it => _DIST_POINT_NAME_it; - - late final ffi.Pointer _DIST_POINT_it = - _lookup('DIST_POINT_it'); - - ffi.Pointer get DIST_POINT_it => _DIST_POINT_it; + late final _CRYPTO_memcmpPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Size)>>('CRYPTO_memcmp'); + late final _CRYPTO_memcmp = _CRYPTO_memcmpPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, int)>(); /// ECDH_compute_key calculates the shared key between |pub_key| and |priv_key|. /// If |kdf| is not NULL, then it is called with the bytes of the shared key and @@ -605,7 +458,11 @@ class BoringSsl { int outlen, ffi.Pointer pub_key, ffi.Pointer priv_key, - ffi.Pointer> kdf, + ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, ffi.Size, + ffi.Pointer, ffi.Pointer)>> + kdf, ) { return _ECDH_compute_key( out, @@ -616,10 +473,33 @@ class BoringSsl { ); } - late final _ECDH_compute_key_ptr = - _lookup>('ECDH_compute_key'); - late final _dart_ECDH_compute_key _ECDH_compute_key = - _ECDH_compute_key_ptr.asFunction<_dart_ECDH_compute_key>(); + late final _ECDH_compute_keyPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Pointer)>>)>>('ECDH_compute_key'); + late final _ECDH_compute_key = _ECDH_compute_keyPtr.asFunction< + int Function( + ffi.Pointer, + int, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Pointer)>>)>(); /// ECDSA_SIG_free frees |sig| its member |BIGNUM|s. void ECDSA_SIG_free( @@ -630,10 +510,11 @@ class BoringSsl { ); } - late final _ECDSA_SIG_free_ptr = - _lookup>('ECDSA_SIG_free'); - late final _dart_ECDSA_SIG_free _ECDSA_SIG_free = - _ECDSA_SIG_free_ptr.asFunction<_dart_ECDSA_SIG_free>(); + late final _ECDSA_SIG_freePtr = + _lookup)>>( + 'ECDSA_SIG_free'); + late final _ECDSA_SIG_free = + _ECDSA_SIG_freePtr.asFunction)>(); /// ECDSA_SIG_get0 sets |*out_r| and |*out_s|, if non-NULL, to the two /// components of |sig|. @@ -649,10 +530,15 @@ class BoringSsl { ); } - late final _ECDSA_SIG_get0_ptr = - _lookup>('ECDSA_SIG_get0'); - late final _dart_ECDSA_SIG_get0 _ECDSA_SIG_get0 = - _ECDSA_SIG_get0_ptr.asFunction<_dart_ECDSA_SIG_get0>(); + late final _ECDSA_SIG_get0Ptr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer>, + ffi.Pointer>)>>('ECDSA_SIG_get0'); + late final _ECDSA_SIG_get0 = _ECDSA_SIG_get0Ptr.asFunction< + void Function(ffi.Pointer, ffi.Pointer>, + ffi.Pointer>)>(); /// ECDSA_SIG_marshal marshals |sig| as a DER-encoded ECDSA-Sig-Value and appends /// the result to |cbb|. It returns one on success and zero on error. @@ -666,20 +552,23 @@ class BoringSsl { ); } - late final _ECDSA_SIG_marshal_ptr = - _lookup>('ECDSA_SIG_marshal'); - late final _dart_ECDSA_SIG_marshal _ECDSA_SIG_marshal = - _ECDSA_SIG_marshal_ptr.asFunction<_dart_ECDSA_SIG_marshal>(); + late final _ECDSA_SIG_marshalPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, ffi.Pointer)>>('ECDSA_SIG_marshal'); + late final _ECDSA_SIG_marshal = _ECDSA_SIG_marshalPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); /// ECDSA_SIG_new returns a fresh |ECDSA_SIG| structure or NULL on error. ffi.Pointer ECDSA_SIG_new() { return _ECDSA_SIG_new(); } - late final _ECDSA_SIG_new_ptr = - _lookup>('ECDSA_SIG_new'); - late final _dart_ECDSA_SIG_new _ECDSA_SIG_new = - _ECDSA_SIG_new_ptr.asFunction<_dart_ECDSA_SIG_new>(); + late final _ECDSA_SIG_newPtr = + _lookup Function()>>( + 'ECDSA_SIG_new'); + late final _ECDSA_SIG_new = + _ECDSA_SIG_newPtr.asFunction Function()>(); /// ECDSA_SIG_parse parses a DER-encoded ECDSA-Sig-Value structure from |cbs| and /// advances |cbs|. It returns a newly-allocated |ECDSA_SIG| or NULL on error. @@ -691,10 +580,12 @@ class BoringSsl { ); } - late final _ECDSA_SIG_parse_ptr = - _lookup>('ECDSA_SIG_parse'); - late final _dart_ECDSA_SIG_parse _ECDSA_SIG_parse = - _ECDSA_SIG_parse_ptr.asFunction<_dart_ECDSA_SIG_parse>(); + late final _ECDSA_SIG_parsePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('ECDSA_SIG_parse'); + late final _ECDSA_SIG_parse = _ECDSA_SIG_parsePtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); /// EC_GROUP_free releases a reference to |group|. void EC_GROUP_free( @@ -705,10 +596,11 @@ class BoringSsl { ); } - late final _EC_GROUP_free_ptr = - _lookup>('EC_GROUP_free'); - late final _dart_EC_GROUP_free _EC_GROUP_free = - _EC_GROUP_free_ptr.asFunction<_dart_EC_GROUP_free>(); + late final _EC_GROUP_freePtr = + _lookup)>>( + 'EC_GROUP_free'); + late final _EC_GROUP_free = + _EC_GROUP_freePtr.asFunction)>(); /// EC_GROUP_get0_order returns a pointer to the internal |BIGNUM| object in /// |group| that specifies the order of the group. @@ -720,11 +612,12 @@ class BoringSsl { ); } - late final _EC_GROUP_get0_order_ptr = - _lookup>( - 'EC_GROUP_get0_order'); - late final _dart_EC_GROUP_get0_order _EC_GROUP_get0_order = - _EC_GROUP_get0_order_ptr.asFunction<_dart_EC_GROUP_get0_order>(); + late final _EC_GROUP_get0_orderPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('EC_GROUP_get0_order'); + late final _EC_GROUP_get0_order = _EC_GROUP_get0_orderPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); /// EC_GROUP_get_curve_name returns a NID that identifies |group|. int EC_GROUP_get_curve_name( @@ -735,11 +628,11 @@ class BoringSsl { ); } - late final _EC_GROUP_get_curve_name_ptr = - _lookup>( + late final _EC_GROUP_get_curve_namePtr = + _lookup)>>( 'EC_GROUP_get_curve_name'); - late final _dart_EC_GROUP_get_curve_name _EC_GROUP_get_curve_name = - _EC_GROUP_get_curve_name_ptr.asFunction<_dart_EC_GROUP_get_curve_name>(); + late final _EC_GROUP_get_curve_name = _EC_GROUP_get_curve_namePtr.asFunction< + int Function(ffi.Pointer)>(); /// EC_GROUP_get_degree returns the number of bits needed to represent an /// element of the field underlying |group|. @@ -751,11 +644,11 @@ class BoringSsl { ); } - late final _EC_GROUP_get_degree_ptr = - _lookup>( - 'EC_GROUP_get_degree'); - late final _dart_EC_GROUP_get_degree _EC_GROUP_get_degree = - _EC_GROUP_get_degree_ptr.asFunction<_dart_EC_GROUP_get_degree>(); + late final _EC_GROUP_get_degreePtr = _lookup< + ffi.NativeFunction)>>( + 'EC_GROUP_get_degree'); + late final _EC_GROUP_get_degree = + _EC_GROUP_get_degreePtr.asFunction)>(); /// EC_GROUP_new_by_curve_name returns a fresh EC_GROUP object for the elliptic /// curve specified by |nid|, or NULL on unsupported NID or allocation failure. @@ -776,12 +669,11 @@ class BoringSsl { ); } - late final _EC_GROUP_new_by_curve_name_ptr = - _lookup>( + late final _EC_GROUP_new_by_curve_namePtr = + _lookup Function(ffi.Int)>>( 'EC_GROUP_new_by_curve_name'); - late final _dart_EC_GROUP_new_by_curve_name _EC_GROUP_new_by_curve_name = - _EC_GROUP_new_by_curve_name_ptr.asFunction< - _dart_EC_GROUP_new_by_curve_name>(); + late final _EC_GROUP_new_by_curve_name = _EC_GROUP_new_by_curve_namePtr + .asFunction Function(int)>(); /// EC_KEY_check_key performs several checks on |key| (possibly including an /// expensive check that the public key is in the primary subgroup). It returns @@ -795,10 +687,11 @@ class BoringSsl { ); } - late final _EC_KEY_check_key_ptr = - _lookup>('EC_KEY_check_key'); - late final _dart_EC_KEY_check_key _EC_KEY_check_key = - _EC_KEY_check_key_ptr.asFunction<_dart_EC_KEY_check_key>(); + late final _EC_KEY_check_keyPtr = + _lookup)>>( + 'EC_KEY_check_key'); + late final _EC_KEY_check_key = + _EC_KEY_check_keyPtr.asFunction)>(); /// EC_KEY_free frees all the data owned by |key| and |key| itself. void EC_KEY_free( @@ -809,10 +702,11 @@ class BoringSsl { ); } - late final _EC_KEY_free_ptr = - _lookup>('EC_KEY_free'); - late final _dart_EC_KEY_free _EC_KEY_free = - _EC_KEY_free_ptr.asFunction<_dart_EC_KEY_free>(); + late final _EC_KEY_freePtr = + _lookup)>>( + 'EC_KEY_free'); + late final _EC_KEY_free = + _EC_KEY_freePtr.asFunction)>(); /// EC_KEY_generate_key generates a random, private key, calculates the /// corresponding public key and stores both in |key|. It returns one on success @@ -825,11 +719,11 @@ class BoringSsl { ); } - late final _EC_KEY_generate_key_ptr = - _lookup>( + late final _EC_KEY_generate_keyPtr = + _lookup)>>( 'EC_KEY_generate_key'); - late final _dart_EC_KEY_generate_key _EC_KEY_generate_key = - _EC_KEY_generate_key_ptr.asFunction<_dart_EC_KEY_generate_key>(); + late final _EC_KEY_generate_key = + _EC_KEY_generate_keyPtr.asFunction)>(); /// EC_KEY_get0_group returns a pointer to the |EC_GROUP| object inside |key|. ffi.Pointer EC_KEY_get0_group( @@ -840,10 +734,12 @@ class BoringSsl { ); } - late final _EC_KEY_get0_group_ptr = - _lookup>('EC_KEY_get0_group'); - late final _dart_EC_KEY_get0_group _EC_KEY_get0_group = - _EC_KEY_get0_group_ptr.asFunction<_dart_EC_KEY_get0_group>(); + late final _EC_KEY_get0_groupPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('EC_KEY_get0_group'); + late final _EC_KEY_get0_group = _EC_KEY_get0_groupPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); /// EC_KEY_get0_private_key returns a pointer to the private key inside |key|. ffi.Pointer EC_KEY_get0_private_key( @@ -854,11 +750,12 @@ class BoringSsl { ); } - late final _EC_KEY_get0_private_key_ptr = - _lookup>( - 'EC_KEY_get0_private_key'); - late final _dart_EC_KEY_get0_private_key _EC_KEY_get0_private_key = - _EC_KEY_get0_private_key_ptr.asFunction<_dart_EC_KEY_get0_private_key>(); + late final _EC_KEY_get0_private_keyPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('EC_KEY_get0_private_key'); + late final _EC_KEY_get0_private_key = _EC_KEY_get0_private_keyPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); /// EC_KEY_get0_public_key returns a pointer to the public key point inside /// |key|. @@ -870,11 +767,12 @@ class BoringSsl { ); } - late final _EC_KEY_get0_public_key_ptr = - _lookup>( - 'EC_KEY_get0_public_key'); - late final _dart_EC_KEY_get0_public_key _EC_KEY_get0_public_key = - _EC_KEY_get0_public_key_ptr.asFunction<_dart_EC_KEY_get0_public_key>(); + late final _EC_KEY_get0_public_keyPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('EC_KEY_get0_public_key'); + late final _EC_KEY_get0_public_key = _EC_KEY_get0_public_keyPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); /// EC_KEY_get_enc_flags returns the encoding flags for |key|, which is a /// bitwise-OR of |EC_PKEY_*| values. @@ -886,11 +784,11 @@ class BoringSsl { ); } - late final _EC_KEY_get_enc_flags_ptr = - _lookup>( - 'EC_KEY_get_enc_flags'); - late final _dart_EC_KEY_get_enc_flags _EC_KEY_get_enc_flags = - _EC_KEY_get_enc_flags_ptr.asFunction<_dart_EC_KEY_get_enc_flags>(); + late final _EC_KEY_get_enc_flagsPtr = _lookup< + ffi.NativeFunction)>>( + 'EC_KEY_get_enc_flags'); + late final _EC_KEY_get_enc_flags = + _EC_KEY_get_enc_flagsPtr.asFunction)>(); /// EC_KEY_new_by_curve_name returns a fresh EC_KEY for group specified by |nid| /// or NULL on error. @@ -902,12 +800,11 @@ class BoringSsl { ); } - late final _EC_KEY_new_by_curve_name_ptr = - _lookup>( + late final _EC_KEY_new_by_curve_namePtr = + _lookup Function(ffi.Int)>>( 'EC_KEY_new_by_curve_name'); - late final _dart_EC_KEY_new_by_curve_name _EC_KEY_new_by_curve_name = - _EC_KEY_new_by_curve_name_ptr.asFunction< - _dart_EC_KEY_new_by_curve_name>(); + late final _EC_KEY_new_by_curve_name = _EC_KEY_new_by_curve_namePtr + .asFunction Function(int)>(); /// EC_KEY_set_enc_flags sets the encoding flags for |key|, which is a /// bitwise-OR of |EC_PKEY_*| values. @@ -921,11 +818,12 @@ class BoringSsl { ); } - late final _EC_KEY_set_enc_flags_ptr = - _lookup>( - 'EC_KEY_set_enc_flags'); - late final _dart_EC_KEY_set_enc_flags _EC_KEY_set_enc_flags = - _EC_KEY_set_enc_flags_ptr.asFunction<_dart_EC_KEY_set_enc_flags>(); + late final _EC_KEY_set_enc_flagsPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, ffi.UnsignedInt)>>('EC_KEY_set_enc_flags'); + late final _EC_KEY_set_enc_flags = _EC_KEY_set_enc_flagsPtr.asFunction< + void Function(ffi.Pointer, int)>(); /// EC_KEY_set_private_key sets the private key of |key| to |priv|. It returns /// one on success and zero otherwise. |key| must already have had a group @@ -940,11 +838,12 @@ class BoringSsl { ); } - late final _EC_KEY_set_private_key_ptr = - _lookup>( - 'EC_KEY_set_private_key'); - late final _dart_EC_KEY_set_private_key _EC_KEY_set_private_key = - _EC_KEY_set_private_key_ptr.asFunction<_dart_EC_KEY_set_private_key>(); + late final _EC_KEY_set_private_keyPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('EC_KEY_set_private_key'); + late final _EC_KEY_set_private_key = _EC_KEY_set_private_keyPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); /// EC_KEY_set_public_key sets the public key of |key| to |pub|, by copying it. /// It returns one on success and zero otherwise. |key| must already have had a @@ -960,11 +859,12 @@ class BoringSsl { ); } - late final _EC_KEY_set_public_key_ptr = - _lookup>( - 'EC_KEY_set_public_key'); - late final _dart_EC_KEY_set_public_key _EC_KEY_set_public_key = - _EC_KEY_set_public_key_ptr.asFunction<_dart_EC_KEY_set_public_key>(); + late final _EC_KEY_set_public_keyPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('EC_KEY_set_public_key'); + late final _EC_KEY_set_public_key = _EC_KEY_set_public_keyPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); /// EC_KEY_set_public_key_affine_coordinates sets the public key in |key| to /// (|x|, |y|). It returns one on success and zero on error. It's considered an @@ -981,13 +881,15 @@ class BoringSsl { ); } - late final _EC_KEY_set_public_key_affine_coordinates_ptr = - _lookup>( - 'EC_KEY_set_public_key_affine_coordinates'); - late final _dart_EC_KEY_set_public_key_affine_coordinates - _EC_KEY_set_public_key_affine_coordinates = - _EC_KEY_set_public_key_affine_coordinates_ptr.asFunction< - _dart_EC_KEY_set_public_key_affine_coordinates>(); + late final _EC_KEY_set_public_key_affine_coordinatesPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>>( + 'EC_KEY_set_public_key_affine_coordinates'); + late final _EC_KEY_set_public_key_affine_coordinates = + _EC_KEY_set_public_key_affine_coordinatesPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer, ffi.Pointer)>(); /// EC_POINT_free frees |point| and the data that it points to. void EC_POINT_free( @@ -998,10 +900,11 @@ class BoringSsl { ); } - late final _EC_POINT_free_ptr = - _lookup>('EC_POINT_free'); - late final _dart_EC_POINT_free _EC_POINT_free = - _EC_POINT_free_ptr.asFunction<_dart_EC_POINT_free>(); + late final _EC_POINT_freePtr = + _lookup)>>( + 'EC_POINT_free'); + late final _EC_POINT_free = + _EC_POINT_freePtr.asFunction)>(); /// EC_POINT_get_affine_coordinates_GFp sets |x| and |y| to the affine value of /// |point| using |ctx|, if it's not NULL. It returns one on success and zero @@ -1025,13 +928,18 @@ class BoringSsl { ); } - late final _EC_POINT_get_affine_coordinates_GFp_ptr = - _lookup>( - 'EC_POINT_get_affine_coordinates_GFp'); - late final _dart_EC_POINT_get_affine_coordinates_GFp - _EC_POINT_get_affine_coordinates_GFp = - _EC_POINT_get_affine_coordinates_GFp_ptr.asFunction< - _dart_EC_POINT_get_affine_coordinates_GFp>(); + late final _EC_POINT_get_affine_coordinates_GFpPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('EC_POINT_get_affine_coordinates_GFp'); + late final _EC_POINT_get_affine_coordinates_GFp = + _EC_POINT_get_affine_coordinates_GFpPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer, ffi.Pointer, ffi.Pointer)>(); /// EC_POINT_new returns a fresh |EC_POINT| object in the given group, or NULL /// on error. @@ -1043,10 +951,12 @@ class BoringSsl { ); } - late final _EC_POINT_new_ptr = - _lookup>('EC_POINT_new'); - late final _dart_EC_POINT_new _EC_POINT_new = - _EC_POINT_new_ptr.asFunction<_dart_EC_POINT_new>(); + late final _EC_POINT_newPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('EC_POINT_new'); + late final _EC_POINT_new = _EC_POINT_newPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); /// EC_POINT_oct2point sets |point| from |len| bytes of X9.62 format /// serialisation in |buf|. It returns one on success and zero on error. The @@ -1068,10 +978,17 @@ class BoringSsl { ); } - late final _EC_POINT_oct2point_ptr = - _lookup>('EC_POINT_oct2point'); - late final _dart_EC_POINT_oct2point _EC_POINT_oct2point = - _EC_POINT_oct2point_ptr.asFunction<_dart_EC_POINT_oct2point>(); + late final _EC_POINT_oct2pointPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Size, + ffi.Pointer)>>('EC_POINT_oct2point'); + late final _EC_POINT_oct2point = _EC_POINT_oct2pointPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer, int, ffi.Pointer)>(); /// EC_POINT_point2cbb behaves like |EC_POINT_point2oct| but appends the /// serialised point to |cbb|. It returns one on success and zero on error. @@ -1091,25 +1008,27 @@ class BoringSsl { ); } - late final _EC_POINT_point2cbb_ptr = - _lookup>('EC_POINT_point2cbb'); - late final _dart_EC_POINT_point2cbb _EC_POINT_point2cbb = - _EC_POINT_point2cbb_ptr.asFunction<_dart_EC_POINT_point2cbb>(); - - late final ffi.Pointer _EDIPARTYNAME_it = - _lookup('EDIPARTYNAME_it'); - - ffi.Pointer get EDIPARTYNAME_it => _EDIPARTYNAME_it; + late final _EC_POINT_point2cbbPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Int32, + ffi.Pointer)>>('EC_POINT_point2cbb'); + late final _EC_POINT_point2cbb = _EC_POINT_point2cbbPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer, int, ffi.Pointer)>(); /// ERR_clear_error clears the error queue for the current thread. void ERR_clear_error() { return _ERR_clear_error(); } - late final _ERR_clear_error_ptr = - _lookup>('ERR_clear_error'); - late final _dart_ERR_clear_error _ERR_clear_error = - _ERR_clear_error_ptr.asFunction<_dart_ERR_clear_error>(); + late final _ERR_clear_errorPtr = + _lookup>('ERR_clear_error'); + late final _ERR_clear_error = + _ERR_clear_errorPtr.asFunction(); /// ERR_error_string_n generates a human-readable string representing /// |packed_error|, places it at |buf|, and returns |buf|. It writes at most @@ -1122,9 +1041,9 @@ class BoringSsl { /// /// error code is an 8 digit hexadecimal number; library name and reason string /// are ASCII text. - ffi.Pointer ERR_error_string_n( + ffi.Pointer ERR_error_string_n( int packed_error, - ffi.Pointer buf, + ffi.Pointer buf, int len, ) { return _ERR_error_string_n( @@ -1134,10 +1053,12 @@ class BoringSsl { ); } - late final _ERR_error_string_n_ptr = - _lookup>('ERR_error_string_n'); - late final _dart_ERR_error_string_n _ERR_error_string_n = - _ERR_error_string_n_ptr.asFunction<_dart_ERR_error_string_n>(); + late final _ERR_error_string_nPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Uint32, ffi.Pointer, + ffi.Size)>>('ERR_error_string_n'); + late final _ERR_error_string_n = _ERR_error_string_nPtr.asFunction< + ffi.Pointer Function(int, ffi.Pointer, int)>(); /// ERR_get_error gets the packed error code for the least recent error and /// removes that error from the queue. If there are no errors in the queue then @@ -1146,10 +1067,9 @@ class BoringSsl { return _ERR_get_error(); } - late final _ERR_get_error_ptr = - _lookup>('ERR_get_error'); - late final _dart_ERR_get_error _ERR_get_error = - _ERR_get_error_ptr.asFunction<_dart_ERR_get_error>(); + late final _ERR_get_errorPtr = + _lookup>('ERR_get_error'); + late final _ERR_get_error = _ERR_get_errorPtr.asFunction(); /// The "peek" functions act like the |ERR_get_error| functions, above, but they /// do not remove the error from the queue. @@ -1157,10 +1077,9 @@ class BoringSsl { return _ERR_peek_error(); } - late final _ERR_peek_error_ptr = - _lookup>('ERR_peek_error'); - late final _dart_ERR_peek_error _ERR_peek_error = - _ERR_peek_error_ptr.asFunction<_dart_ERR_peek_error>(); + late final _ERR_peek_errorPtr = + _lookup>('ERR_peek_error'); + late final _ERR_peek_error = _ERR_peek_errorPtr.asFunction(); /// EVP_AEAD_CTX_free calls |EVP_AEAD_CTX_cleanup| and |OPENSSL_free| on /// |ctx|. @@ -1172,10 +1091,11 @@ class BoringSsl { ); } - late final _EVP_AEAD_CTX_free_ptr = - _lookup>('EVP_AEAD_CTX_free'); - late final _dart_EVP_AEAD_CTX_free _EVP_AEAD_CTX_free = - _EVP_AEAD_CTX_free_ptr.asFunction<_dart_EVP_AEAD_CTX_free>(); + late final _EVP_AEAD_CTX_freePtr = + _lookup)>>( + 'EVP_AEAD_CTX_free'); + late final _EVP_AEAD_CTX_free = _EVP_AEAD_CTX_freePtr.asFunction< + void Function(ffi.Pointer)>(); /// EVP_AEAD_CTX_new allocates an |EVP_AEAD_CTX|, calls |EVP_AEAD_CTX_init| and /// returns the |EVP_AEAD_CTX|, or NULL on error. @@ -1193,10 +1113,13 @@ class BoringSsl { ); } - late final _EVP_AEAD_CTX_new_ptr = - _lookup>('EVP_AEAD_CTX_new'); - late final _dart_EVP_AEAD_CTX_new _EVP_AEAD_CTX_new = - _EVP_AEAD_CTX_new_ptr.asFunction<_dart_EVP_AEAD_CTX_new>(); + late final _EVP_AEAD_CTX_newPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer, ffi.Size, ffi.Size)>>('EVP_AEAD_CTX_new'); + late final _EVP_AEAD_CTX_new = _EVP_AEAD_CTX_newPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer, int, int)>(); /// EVP_AEAD_CTX_open authenticates |in_len| bytes from |in| and |ad_len| bytes /// from |ad| and decrypts at most |in_len| bytes into |out|. It returns one on @@ -1220,11 +1143,11 @@ class BoringSsl { int EVP_AEAD_CTX_open( ffi.Pointer ctx, ffi.Pointer out, - ffi.Pointer out_len, + ffi.Pointer out_len, int max_out_len, ffi.Pointer nonce, int nonce_len, - ffi.Pointer in_1, + ffi.Pointer in1, int in_len, ffi.Pointer ad, int ad_len, @@ -1236,17 +1159,38 @@ class BoringSsl { max_out_len, nonce, nonce_len, - in_1, + in1, in_len, ad, ad_len, ); } - late final _EVP_AEAD_CTX_open_ptr = - _lookup>('EVP_AEAD_CTX_open'); - late final _dart_EVP_AEAD_CTX_open _EVP_AEAD_CTX_open = - _EVP_AEAD_CTX_open_ptr.asFunction<_dart_EVP_AEAD_CTX_open>(); + late final _EVP_AEAD_CTX_openPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Size)>>('EVP_AEAD_CTX_open'); + late final _EVP_AEAD_CTX_open = _EVP_AEAD_CTX_openPtr.asFunction< + int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + int, + ffi.Pointer, + int, + ffi.Pointer, + int, + ffi.Pointer, + int)>(); /// EVP_AEAD_CTX_seal encrypts and authenticates |in_len| bytes from |in| and /// authenticates |ad_len| bytes from |ad| and writes the result to |out|. It @@ -1271,11 +1215,11 @@ class BoringSsl { int EVP_AEAD_CTX_seal( ffi.Pointer ctx, ffi.Pointer out, - ffi.Pointer out_len, + ffi.Pointer out_len, int max_out_len, ffi.Pointer nonce, int nonce_len, - ffi.Pointer in_1, + ffi.Pointer in1, int in_len, ffi.Pointer ad, int ad_len, @@ -1287,17 +1231,38 @@ class BoringSsl { max_out_len, nonce, nonce_len, - in_1, + in1, in_len, ad, ad_len, ); } - late final _EVP_AEAD_CTX_seal_ptr = - _lookup>('EVP_AEAD_CTX_seal'); - late final _dart_EVP_AEAD_CTX_seal _EVP_AEAD_CTX_seal = - _EVP_AEAD_CTX_seal_ptr.asFunction<_dart_EVP_AEAD_CTX_seal>(); + late final _EVP_AEAD_CTX_sealPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Size)>>('EVP_AEAD_CTX_seal'); + late final _EVP_AEAD_CTX_seal = _EVP_AEAD_CTX_sealPtr.asFunction< + int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + int, + ffi.Pointer, + int, + ffi.Pointer, + int, + ffi.Pointer, + int)>(); /// EVP_AEAD_key_length returns the length, in bytes, of the keys used by /// |aead|. @@ -1309,11 +1274,11 @@ class BoringSsl { ); } - late final _EVP_AEAD_key_length_ptr = - _lookup>( + late final _EVP_AEAD_key_lengthPtr = + _lookup)>>( 'EVP_AEAD_key_length'); - late final _dart_EVP_AEAD_key_length _EVP_AEAD_key_length = - _EVP_AEAD_key_length_ptr.asFunction<_dart_EVP_AEAD_key_length>(); + late final _EVP_AEAD_key_length = + _EVP_AEAD_key_lengthPtr.asFunction)>(); /// EVP_AEAD_max_overhead returns the maximum number of additional bytes added /// by the act of sealing data with |aead|. @@ -1325,11 +1290,11 @@ class BoringSsl { ); } - late final _EVP_AEAD_max_overhead_ptr = - _lookup>( + late final _EVP_AEAD_max_overheadPtr = + _lookup)>>( 'EVP_AEAD_max_overhead'); - late final _dart_EVP_AEAD_max_overhead _EVP_AEAD_max_overhead = - _EVP_AEAD_max_overhead_ptr.asFunction<_dart_EVP_AEAD_max_overhead>(); + late final _EVP_AEAD_max_overhead = _EVP_AEAD_max_overheadPtr.asFunction< + int Function(ffi.Pointer)>(); /// EVP_AEAD_max_tag_len returns the maximum tag length when using |aead|. This /// is the largest value that can be passed as |tag_len| to @@ -1342,11 +1307,11 @@ class BoringSsl { ); } - late final _EVP_AEAD_max_tag_len_ptr = - _lookup>( + late final _EVP_AEAD_max_tag_lenPtr = + _lookup)>>( 'EVP_AEAD_max_tag_len'); - late final _dart_EVP_AEAD_max_tag_len _EVP_AEAD_max_tag_len = - _EVP_AEAD_max_tag_len_ptr.asFunction<_dart_EVP_AEAD_max_tag_len>(); + late final _EVP_AEAD_max_tag_len = _EVP_AEAD_max_tag_lenPtr.asFunction< + int Function(ffi.Pointer)>(); /// EVP_AEAD_nonce_length returns the length, in bytes, of the per-message nonce /// for |aead|. @@ -1358,11 +1323,11 @@ class BoringSsl { ); } - late final _EVP_AEAD_nonce_length_ptr = - _lookup>( + late final _EVP_AEAD_nonce_lengthPtr = + _lookup)>>( 'EVP_AEAD_nonce_length'); - late final _dart_EVP_AEAD_nonce_length _EVP_AEAD_nonce_length = - _EVP_AEAD_nonce_length_ptr.asFunction<_dart_EVP_AEAD_nonce_length>(); + late final _EVP_AEAD_nonce_length = _EVP_AEAD_nonce_lengthPtr.asFunction< + int Function(ffi.Pointer)>(); /// EVP_CIPHER_CTX_free calls |EVP_CIPHER_CTX_cleanup| on |ctx| and then frees /// |ctx| itself. @@ -1374,11 +1339,11 @@ class BoringSsl { ); } - late final _EVP_CIPHER_CTX_free_ptr = - _lookup>( - 'EVP_CIPHER_CTX_free'); - late final _dart_EVP_CIPHER_CTX_free _EVP_CIPHER_CTX_free = - _EVP_CIPHER_CTX_free_ptr.asFunction<_dart_EVP_CIPHER_CTX_free>(); + late final _EVP_CIPHER_CTX_freePtr = _lookup< + ffi.NativeFunction)>>( + 'EVP_CIPHER_CTX_free'); + late final _EVP_CIPHER_CTX_free = _EVP_CIPHER_CTX_freePtr.asFunction< + void Function(ffi.Pointer)>(); /// EVP_CIPHER_CTX_new allocates a fresh |EVP_CIPHER_CTX|, calls /// |EVP_CIPHER_CTX_init| and returns it, or NULL on allocation failure. @@ -1386,10 +1351,11 @@ class BoringSsl { return _EVP_CIPHER_CTX_new(); } - late final _EVP_CIPHER_CTX_new_ptr = - _lookup>('EVP_CIPHER_CTX_new'); - late final _dart_EVP_CIPHER_CTX_new _EVP_CIPHER_CTX_new = - _EVP_CIPHER_CTX_new_ptr.asFunction<_dart_EVP_CIPHER_CTX_new>(); + late final _EVP_CIPHER_CTX_newPtr = + _lookup Function()>>( + 'EVP_CIPHER_CTX_new'); + late final _EVP_CIPHER_CTX_new = _EVP_CIPHER_CTX_newPtr.asFunction< + ffi.Pointer Function()>(); /// EVP_CIPHER_block_size returns the block size, in bytes, for |cipher|, or one /// if |cipher| is a stream cipher. @@ -1401,11 +1367,12 @@ class BoringSsl { ); } - late final _EVP_CIPHER_block_size_ptr = - _lookup>( - 'EVP_CIPHER_block_size'); - late final _dart_EVP_CIPHER_block_size _EVP_CIPHER_block_size = - _EVP_CIPHER_block_size_ptr.asFunction<_dart_EVP_CIPHER_block_size>(); + late final _EVP_CIPHER_block_sizePtr = _lookup< + ffi.NativeFunction< + ffi.UnsignedInt Function( + ffi.Pointer)>>('EVP_CIPHER_block_size'); + late final _EVP_CIPHER_block_size = _EVP_CIPHER_block_sizePtr.asFunction< + int Function(ffi.Pointer)>(); /// EVP_CIPHER_iv_length returns the IV size, in bytes, of |cipher|, or zero if /// |cipher| doesn't take an IV. @@ -1417,18 +1384,19 @@ class BoringSsl { ); } - late final _EVP_CIPHER_iv_length_ptr = - _lookup>( - 'EVP_CIPHER_iv_length'); - late final _dart_EVP_CIPHER_iv_length _EVP_CIPHER_iv_length = - _EVP_CIPHER_iv_length_ptr.asFunction<_dart_EVP_CIPHER_iv_length>(); + late final _EVP_CIPHER_iv_lengthPtr = _lookup< + ffi.NativeFunction< + ffi.UnsignedInt Function( + ffi.Pointer)>>('EVP_CIPHER_iv_length'); + late final _EVP_CIPHER_iv_length = _EVP_CIPHER_iv_lengthPtr.asFunction< + int Function(ffi.Pointer)>(); /// EVP_CipherFinal_ex calls either |EVP_EncryptFinal_ex| or /// |EVP_DecryptFinal_ex| depending on how |ctx| has been setup. int EVP_CipherFinal_ex( ffi.Pointer ctx, ffi.Pointer out, - ffi.Pointer out_len, + ffi.Pointer out_len, ) { return _EVP_CipherFinal_ex( ctx, @@ -1437,10 +1405,13 @@ class BoringSsl { ); } - late final _EVP_CipherFinal_ex_ptr = - _lookup>('EVP_CipherFinal_ex'); - late final _dart_EVP_CipherFinal_ex _EVP_CipherFinal_ex = - _EVP_CipherFinal_ex_ptr.asFunction<_dart_EVP_CipherFinal_ex>(); + late final _EVP_CipherFinal_exPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>>('EVP_CipherFinal_ex'); + late final _EVP_CipherFinal_ex = _EVP_CipherFinal_exPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); /// EVP_CipherInit_ex configures |ctx| for a fresh encryption (or decryption, if /// |enc| is zero) operation using |cipher|. If |ctx| has been previously @@ -1467,40 +1438,60 @@ class BoringSsl { ); } - late final _EVP_CipherInit_ex_ptr = - _lookup>('EVP_CipherInit_ex'); - late final _dart_EVP_CipherInit_ex _EVP_CipherInit_ex = - _EVP_CipherInit_ex_ptr.asFunction<_dart_EVP_CipherInit_ex>(); + late final _EVP_CipherInit_exPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Int)>>('EVP_CipherInit_ex'); + late final _EVP_CipherInit_ex = _EVP_CipherInit_exPtr.asFunction< + int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + int)>(); /// EVP_CipherUpdate calls either |EVP_EncryptUpdate| or |EVP_DecryptUpdate| /// depending on how |ctx| has been setup. int EVP_CipherUpdate( ffi.Pointer ctx, ffi.Pointer out, - ffi.Pointer out_len, - ffi.Pointer in_1, + ffi.Pointer out_len, + ffi.Pointer in1, int in_len, ) { return _EVP_CipherUpdate( ctx, out, out_len, - in_1, + in1, in_len, ); } - late final _EVP_CipherUpdate_ptr = - _lookup>('EVP_CipherUpdate'); - late final _dart_EVP_CipherUpdate _EVP_CipherUpdate = - _EVP_CipherUpdate_ptr.asFunction<_dart_EVP_CipherUpdate>(); + late final _EVP_CipherUpdatePtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Int)>>('EVP_CipherUpdate'); + late final _EVP_CipherUpdate = _EVP_CipherUpdatePtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer, ffi.Pointer, int)>(); /// EVP_DigestFinal acts like |EVP_DigestFinal_ex| except that /// |EVP_MD_CTX_cleanup| is called on |ctx| before returning. int EVP_DigestFinal( ffi.Pointer ctx, ffi.Pointer md_out, - ffi.Pointer out_size, + ffi.Pointer out_size, ) { return _EVP_DigestFinal( ctx, @@ -1509,10 +1500,13 @@ class BoringSsl { ); } - late final _EVP_DigestFinal_ptr = - _lookup>('EVP_DigestFinal'); - late final _dart_EVP_DigestFinal _EVP_DigestFinal = - _EVP_DigestFinal_ptr.asFunction<_dart_EVP_DigestFinal>(); + late final _EVP_DigestFinalPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>>('EVP_DigestFinal'); + late final _EVP_DigestFinal = _EVP_DigestFinalPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); /// EVP_DigestInit acts like |EVP_DigestInit_ex| except that |ctx| is /// initialised before use. @@ -1526,10 +1520,12 @@ class BoringSsl { ); } - late final _EVP_DigestInit_ptr = - _lookup>('EVP_DigestInit'); - late final _dart_EVP_DigestInit _EVP_DigestInit = - _EVP_DigestInit_ptr.asFunction<_dart_EVP_DigestInit>(); + late final _EVP_DigestInitPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, ffi.Pointer)>>('EVP_DigestInit'); + late final _EVP_DigestInit = _EVP_DigestInitPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); /// EVP_DigestSignFinal signs the data that has been included by one or more /// calls to |EVP_DigestSignUpdate|. If |out_sig| is NULL then |*out_sig_len| is @@ -1546,7 +1542,7 @@ class BoringSsl { int EVP_DigestSignFinal( ffi.Pointer ctx, ffi.Pointer out_sig, - ffi.Pointer out_sig_len, + ffi.Pointer out_sig_len, ) { return _EVP_DigestSignFinal( ctx, @@ -1555,11 +1551,13 @@ class BoringSsl { ); } - late final _EVP_DigestSignFinal_ptr = - _lookup>( - 'EVP_DigestSignFinal'); - late final _dart_EVP_DigestSignFinal _EVP_DigestSignFinal = - _EVP_DigestSignFinal_ptr.asFunction<_dart_EVP_DigestSignFinal>(); + late final _EVP_DigestSignFinalPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>>('EVP_DigestSignFinal'); + late final _EVP_DigestSignFinal = _EVP_DigestSignFinalPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); /// EVP_DigestSignInit sets up |ctx| for a signing operation with |type| and /// |pkey|. The |ctx| argument must have been initialised with @@ -1591,10 +1589,21 @@ class BoringSsl { ); } - late final _EVP_DigestSignInit_ptr = - _lookup>('EVP_DigestSignInit'); - late final _dart_EVP_DigestSignInit _EVP_DigestSignInit = - _EVP_DigestSignInit_ptr.asFunction<_dart_EVP_DigestSignInit>(); + late final _EVP_DigestSignInitPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('EVP_DigestSignInit'); + late final _EVP_DigestSignInit = _EVP_DigestSignInitPtr.asFunction< + int Function( + ffi.Pointer, + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>(); /// EVP_DigestSignUpdate appends |len| bytes from |data| to the data which will /// be signed in |EVP_DigestSignFinal|. It returns one. @@ -1614,11 +1623,12 @@ class BoringSsl { ); } - late final _EVP_DigestSignUpdate_ptr = - _lookup>( - 'EVP_DigestSignUpdate'); - late final _dart_EVP_DigestSignUpdate _EVP_DigestSignUpdate = - _EVP_DigestSignUpdate_ptr.asFunction<_dart_EVP_DigestSignUpdate>(); + late final _EVP_DigestSignUpdatePtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Size)>>('EVP_DigestSignUpdate'); + late final _EVP_DigestSignUpdate = _EVP_DigestSignUpdatePtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, int)>(); /// EVP_DigestUpdate hashes |len| bytes from |data| into the hashing operation /// in |ctx|. It returns one. @@ -1634,10 +1644,12 @@ class BoringSsl { ); } - late final _EVP_DigestUpdate_ptr = - _lookup>('EVP_DigestUpdate'); - late final _dart_EVP_DigestUpdate _EVP_DigestUpdate = - _EVP_DigestUpdate_ptr.asFunction<_dart_EVP_DigestUpdate>(); + late final _EVP_DigestUpdatePtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Size)>>('EVP_DigestUpdate'); + late final _EVP_DigestUpdate = _EVP_DigestUpdatePtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, int)>(); /// EVP_DigestVerifyFinal verifies that |sig_len| bytes of |sig| are a valid /// signature for the data that has been included by one or more calls to @@ -1658,11 +1670,12 @@ class BoringSsl { ); } - late final _EVP_DigestVerifyFinal_ptr = - _lookup>( - 'EVP_DigestVerifyFinal'); - late final _dart_EVP_DigestVerifyFinal _EVP_DigestVerifyFinal = - _EVP_DigestVerifyFinal_ptr.asFunction<_dart_EVP_DigestVerifyFinal>(); + late final _EVP_DigestVerifyFinalPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Size)>>('EVP_DigestVerifyFinal'); + late final _EVP_DigestVerifyFinal = _EVP_DigestVerifyFinalPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, int)>(); /// EVP_DigestVerifyInit sets up |ctx| for a signature verification operation /// with |type| and |pkey|. The |ctx| argument must have been initialised with @@ -1694,11 +1707,21 @@ class BoringSsl { ); } - late final _EVP_DigestVerifyInit_ptr = - _lookup>( - 'EVP_DigestVerifyInit'); - late final _dart_EVP_DigestVerifyInit _EVP_DigestVerifyInit = - _EVP_DigestVerifyInit_ptr.asFunction<_dart_EVP_DigestVerifyInit>(); + late final _EVP_DigestVerifyInitPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('EVP_DigestVerifyInit'); + late final _EVP_DigestVerifyInit = _EVP_DigestVerifyInitPtr.asFunction< + int Function( + ffi.Pointer, + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>(); /// EVP_DigestVerifyUpdate appends |len| bytes from |data| to the data which /// will be verified by |EVP_DigestVerifyFinal|. It returns one. @@ -1718,11 +1741,12 @@ class BoringSsl { ); } - late final _EVP_DigestVerifyUpdate_ptr = - _lookup>( - 'EVP_DigestVerifyUpdate'); - late final _dart_EVP_DigestVerifyUpdate _EVP_DigestVerifyUpdate = - _EVP_DigestVerifyUpdate_ptr.asFunction<_dart_EVP_DigestVerifyUpdate>(); + late final _EVP_DigestVerifyUpdatePtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Size)>>('EVP_DigestVerifyUpdate'); + late final _EVP_DigestVerifyUpdate = _EVP_DigestVerifyUpdatePtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, int)>(); /// EVP_MD_CTX_free calls |EVP_MD_CTX_cleanup| and then frees |ctx| itself. void EVP_MD_CTX_free( @@ -1733,10 +1757,11 @@ class BoringSsl { ); } - late final _EVP_MD_CTX_free_ptr = - _lookup>('EVP_MD_CTX_free'); - late final _dart_EVP_MD_CTX_free _EVP_MD_CTX_free = - _EVP_MD_CTX_free_ptr.asFunction<_dart_EVP_MD_CTX_free>(); + late final _EVP_MD_CTX_freePtr = + _lookup)>>( + 'EVP_MD_CTX_free'); + late final _EVP_MD_CTX_free = + _EVP_MD_CTX_freePtr.asFunction)>(); /// EVP_MD_CTX_new allocates and initialises a fresh |EVP_MD_CTX| and returns /// it, or NULL on allocation failure. The caller must use |EVP_MD_CTX_free| to @@ -1745,10 +1770,11 @@ class BoringSsl { return _EVP_MD_CTX_new(); } - late final _EVP_MD_CTX_new_ptr = - _lookup>('EVP_MD_CTX_new'); - late final _dart_EVP_MD_CTX_new _EVP_MD_CTX_new = - _EVP_MD_CTX_new_ptr.asFunction<_dart_EVP_MD_CTX_new>(); + late final _EVP_MD_CTX_newPtr = + _lookup Function()>>( + 'EVP_MD_CTX_new'); + late final _EVP_MD_CTX_new = + _EVP_MD_CTX_newPtr.asFunction Function()>(); /// EVP_MD_CTX_size returns the digest size of |ctx|, in bytes. It /// will crash if a digest hasn't been set on |ctx|. @@ -1760,10 +1786,11 @@ class BoringSsl { ); } - late final _EVP_MD_CTX_size_ptr = - _lookup>('EVP_MD_CTX_size'); - late final _dart_EVP_MD_CTX_size _EVP_MD_CTX_size = - _EVP_MD_CTX_size_ptr.asFunction<_dart_EVP_MD_CTX_size>(); + late final _EVP_MD_CTX_sizePtr = + _lookup)>>( + 'EVP_MD_CTX_size'); + late final _EVP_MD_CTX_size = + _EVP_MD_CTX_sizePtr.asFunction)>(); /// EVP_MD_size returns the digest size of |md|, in bytes. int EVP_MD_size( @@ -1774,10 +1801,11 @@ class BoringSsl { ); } - late final _EVP_MD_size_ptr = - _lookup>('EVP_MD_size'); - late final _dart_EVP_MD_size _EVP_MD_size = - _EVP_MD_size_ptr.asFunction<_dart_EVP_MD_size>(); + late final _EVP_MD_sizePtr = + _lookup)>>( + 'EVP_MD_size'); + late final _EVP_MD_size = + _EVP_MD_sizePtr.asFunction)>(); /// EVP_PKEY_CTX_free frees |ctx| and the data it owns. void EVP_PKEY_CTX_free( @@ -1788,10 +1816,11 @@ class BoringSsl { ); } - late final _EVP_PKEY_CTX_free_ptr = - _lookup>('EVP_PKEY_CTX_free'); - late final _dart_EVP_PKEY_CTX_free _EVP_PKEY_CTX_free = - _EVP_PKEY_CTX_free_ptr.asFunction<_dart_EVP_PKEY_CTX_free>(); + late final _EVP_PKEY_CTX_freePtr = + _lookup)>>( + 'EVP_PKEY_CTX_free'); + late final _EVP_PKEY_CTX_free = _EVP_PKEY_CTX_freePtr.asFunction< + void Function(ffi.Pointer)>(); /// EVP_PKEY_CTX_new allocates a fresh |EVP_PKEY_CTX| for use with |pkey|. It /// returns the context or NULL on error. @@ -1805,10 +1834,13 @@ class BoringSsl { ); } - late final _EVP_PKEY_CTX_new_ptr = - _lookup>('EVP_PKEY_CTX_new'); - late final _dart_EVP_PKEY_CTX_new _EVP_PKEY_CTX_new = - _EVP_PKEY_CTX_new_ptr.asFunction<_dart_EVP_PKEY_CTX_new>(); + late final _EVP_PKEY_CTX_newPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer)>>('EVP_PKEY_CTX_new'); + late final _EVP_PKEY_CTX_new = _EVP_PKEY_CTX_newPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer)>(); /// EVP_PKEY_CTX_set0_rsa_oaep_label sets |label_len| bytes from |label| as the /// label used in OAEP. DANGER: On success, this call takes ownership of |label| @@ -1827,15 +1859,21 @@ class BoringSsl { ); } - late final _EVP_PKEY_CTX_set0_rsa_oaep_label_ptr = - _lookup>( - 'EVP_PKEY_CTX_set0_rsa_oaep_label'); - late final _dart_EVP_PKEY_CTX_set0_rsa_oaep_label - _EVP_PKEY_CTX_set0_rsa_oaep_label = _EVP_PKEY_CTX_set0_rsa_oaep_label_ptr - .asFunction<_dart_EVP_PKEY_CTX_set0_rsa_oaep_label>(); + late final _EVP_PKEY_CTX_set0_rsa_oaep_labelPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Size)>>('EVP_PKEY_CTX_set0_rsa_oaep_label'); + late final _EVP_PKEY_CTX_set0_rsa_oaep_label = + _EVP_PKEY_CTX_set0_rsa_oaep_labelPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer, int)>(); /// EVP_PKEY_CTX_set_rsa_mgf1_md sets |md| as the digest used in MGF1. Returns /// one on success or zero on error. + /// + /// If unset, the default is the signing hash for |RSA_PKCS1_PSS_PADDING| and the + /// OAEP hash for |RSA_PKCS1_OAEP_PADDING|. Callers are recommended to use this + /// default and not call this function. int EVP_PKEY_CTX_set_rsa_mgf1_md( ffi.Pointer ctx, ffi.Pointer md, @@ -1846,15 +1884,19 @@ class BoringSsl { ); } - late final _EVP_PKEY_CTX_set_rsa_mgf1_md_ptr = - _lookup>( - 'EVP_PKEY_CTX_set_rsa_mgf1_md'); - late final _dart_EVP_PKEY_CTX_set_rsa_mgf1_md _EVP_PKEY_CTX_set_rsa_mgf1_md = - _EVP_PKEY_CTX_set_rsa_mgf1_md_ptr.asFunction< - _dart_EVP_PKEY_CTX_set_rsa_mgf1_md>(); + late final _EVP_PKEY_CTX_set_rsa_mgf1_mdPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('EVP_PKEY_CTX_set_rsa_mgf1_md'); + late final _EVP_PKEY_CTX_set_rsa_mgf1_md = + _EVP_PKEY_CTX_set_rsa_mgf1_mdPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); /// EVP_PKEY_CTX_set_rsa_oaep_md sets |md| as the digest used in OAEP padding. - /// Returns one on success or zero on error. + /// Returns one on success or zero on error. If unset, the default is SHA-1. + /// Callers are recommended to overwrite this default. + /// + /// TODO(davidben): Remove the default and require callers specify this. int EVP_PKEY_CTX_set_rsa_oaep_md( ffi.Pointer ctx, ffi.Pointer md, @@ -1865,15 +1907,17 @@ class BoringSsl { ); } - late final _EVP_PKEY_CTX_set_rsa_oaep_md_ptr = - _lookup>( - 'EVP_PKEY_CTX_set_rsa_oaep_md'); - late final _dart_EVP_PKEY_CTX_set_rsa_oaep_md _EVP_PKEY_CTX_set_rsa_oaep_md = - _EVP_PKEY_CTX_set_rsa_oaep_md_ptr.asFunction< - _dart_EVP_PKEY_CTX_set_rsa_oaep_md>(); + late final _EVP_PKEY_CTX_set_rsa_oaep_mdPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('EVP_PKEY_CTX_set_rsa_oaep_md'); + late final _EVP_PKEY_CTX_set_rsa_oaep_md = + _EVP_PKEY_CTX_set_rsa_oaep_mdPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); /// EVP_PKEY_CTX_set_rsa_padding sets the padding type to use. It should be one - /// of the |RSA_*_PADDING| values. Returns one on success or zero on error. + /// of the |RSA_*_PADDING| values. Returns one on success or zero on error. By + /// default, the padding is |RSA_PKCS1_PADDING|. int EVP_PKEY_CTX_set_rsa_padding( ffi.Pointer ctx, int padding, @@ -1884,12 +1928,12 @@ class BoringSsl { ); } - late final _EVP_PKEY_CTX_set_rsa_padding_ptr = - _lookup>( - 'EVP_PKEY_CTX_set_rsa_padding'); - late final _dart_EVP_PKEY_CTX_set_rsa_padding _EVP_PKEY_CTX_set_rsa_padding = - _EVP_PKEY_CTX_set_rsa_padding_ptr.asFunction< - _dart_EVP_PKEY_CTX_set_rsa_padding>(); + late final _EVP_PKEY_CTX_set_rsa_paddingPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Int)>>('EVP_PKEY_CTX_set_rsa_padding'); + late final _EVP_PKEY_CTX_set_rsa_padding = _EVP_PKEY_CTX_set_rsa_paddingPtr + .asFunction, int)>(); /// EVP_PKEY_CTX_set_rsa_pss_saltlen sets the length of the salt in a PSS-padded /// signature. A value of -1 cause the salt to be the same length as the digest @@ -1900,6 +1944,8 @@ class BoringSsl { /// If unsure, use -1. /// /// Returns one on success or zero on error. + /// + /// TODO(davidben): The default is currently -2. Switch it to -1. int EVP_PKEY_CTX_set_rsa_pss_saltlen( ffi.Pointer ctx, int salt_len, @@ -1910,12 +1956,13 @@ class BoringSsl { ); } - late final _EVP_PKEY_CTX_set_rsa_pss_saltlen_ptr = - _lookup>( - 'EVP_PKEY_CTX_set_rsa_pss_saltlen'); - late final _dart_EVP_PKEY_CTX_set_rsa_pss_saltlen - _EVP_PKEY_CTX_set_rsa_pss_saltlen = _EVP_PKEY_CTX_set_rsa_pss_saltlen_ptr - .asFunction<_dart_EVP_PKEY_CTX_set_rsa_pss_saltlen>(); + late final _EVP_PKEY_CTX_set_rsa_pss_saltlenPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Int)>>('EVP_PKEY_CTX_set_rsa_pss_saltlen'); + late final _EVP_PKEY_CTX_set_rsa_pss_saltlen = + _EVP_PKEY_CTX_set_rsa_pss_saltlenPtr.asFunction< + int Function(ffi.Pointer, int)>(); /// EVP_PKEY_decrypt decrypts |in_len| bytes from |in|. If |out| is NULL, the /// maximum size of the plaintext is written to |out_len|. Otherwise, |*out_len| @@ -1930,23 +1977,30 @@ class BoringSsl { int EVP_PKEY_decrypt( ffi.Pointer ctx, ffi.Pointer out, - ffi.Pointer out_len, - ffi.Pointer in_1, + ffi.Pointer out_len, + ffi.Pointer in1, int in_len, ) { return _EVP_PKEY_decrypt( ctx, out, out_len, - in_1, + in1, in_len, ); } - late final _EVP_PKEY_decrypt_ptr = - _lookup>('EVP_PKEY_decrypt'); - late final _dart_EVP_PKEY_decrypt _EVP_PKEY_decrypt = - _EVP_PKEY_decrypt_ptr.asFunction<_dart_EVP_PKEY_decrypt>(); + late final _EVP_PKEY_decryptPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Size)>>('EVP_PKEY_decrypt'); + late final _EVP_PKEY_decrypt = _EVP_PKEY_decryptPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer, ffi.Pointer, int)>(); /// EVP_PKEY_decrypt_init initialises an |EVP_PKEY_CTX| for a decryption /// operation. It should be called before |EVP_PKEY_decrypt|. @@ -1960,11 +2014,11 @@ class BoringSsl { ); } - late final _EVP_PKEY_decrypt_init_ptr = - _lookup>( + late final _EVP_PKEY_decrypt_initPtr = + _lookup)>>( 'EVP_PKEY_decrypt_init'); - late final _dart_EVP_PKEY_decrypt_init _EVP_PKEY_decrypt_init = - _EVP_PKEY_decrypt_init_ptr.asFunction<_dart_EVP_PKEY_decrypt_init>(); + late final _EVP_PKEY_decrypt_init = _EVP_PKEY_decrypt_initPtr.asFunction< + int Function(ffi.Pointer)>(); /// EVP_PKEY_encrypt encrypts |in_len| bytes from |in|. If |out| is NULL, the /// maximum size of the ciphertext is written to |out_len|. Otherwise, |*out_len| @@ -1979,23 +2033,30 @@ class BoringSsl { int EVP_PKEY_encrypt( ffi.Pointer ctx, ffi.Pointer out, - ffi.Pointer out_len, - ffi.Pointer in_1, + ffi.Pointer out_len, + ffi.Pointer in1, int in_len, ) { return _EVP_PKEY_encrypt( ctx, out, out_len, - in_1, + in1, in_len, ); } - late final _EVP_PKEY_encrypt_ptr = - _lookup>('EVP_PKEY_encrypt'); - late final _dart_EVP_PKEY_encrypt _EVP_PKEY_encrypt = - _EVP_PKEY_encrypt_ptr.asFunction<_dart_EVP_PKEY_encrypt>(); + late final _EVP_PKEY_encryptPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Size)>>('EVP_PKEY_encrypt'); + late final _EVP_PKEY_encrypt = _EVP_PKEY_encryptPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer, ffi.Pointer, int)>(); /// EVP_PKEY_encrypt_init initialises an |EVP_PKEY_CTX| for an encryption /// operation. It should be called before |EVP_PKEY_encrypt|. @@ -2009,11 +2070,11 @@ class BoringSsl { ); } - late final _EVP_PKEY_encrypt_init_ptr = - _lookup>( + late final _EVP_PKEY_encrypt_initPtr = + _lookup)>>( 'EVP_PKEY_encrypt_init'); - late final _dart_EVP_PKEY_encrypt_init _EVP_PKEY_encrypt_init = - _EVP_PKEY_encrypt_init_ptr.asFunction<_dart_EVP_PKEY_encrypt_init>(); + late final _EVP_PKEY_encrypt_init = _EVP_PKEY_encrypt_initPtr.asFunction< + int Function(ffi.Pointer)>(); /// EVP_PKEY_free frees all data referenced by |pkey| and then frees |pkey| /// itself. @@ -2025,10 +2086,11 @@ class BoringSsl { ); } - late final _EVP_PKEY_free_ptr = - _lookup>('EVP_PKEY_free'); - late final _dart_EVP_PKEY_free _EVP_PKEY_free = - _EVP_PKEY_free_ptr.asFunction<_dart_EVP_PKEY_free>(); + late final _EVP_PKEY_freePtr = + _lookup)>>( + 'EVP_PKEY_free'); + late final _EVP_PKEY_free = + _EVP_PKEY_freePtr.asFunction)>(); ffi.Pointer EVP_PKEY_get1_EC_KEY( ffi.Pointer pkey, @@ -2038,11 +2100,12 @@ class BoringSsl { ); } - late final _EVP_PKEY_get1_EC_KEY_ptr = - _lookup>( - 'EVP_PKEY_get1_EC_KEY'); - late final _dart_EVP_PKEY_get1_EC_KEY _EVP_PKEY_get1_EC_KEY = - _EVP_PKEY_get1_EC_KEY_ptr.asFunction<_dart_EVP_PKEY_get1_EC_KEY>(); + late final _EVP_PKEY_get1_EC_KEYPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('EVP_PKEY_get1_EC_KEY'); + late final _EVP_PKEY_get1_EC_KEY = _EVP_PKEY_get1_EC_KEYPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); ffi.Pointer EVP_PKEY_get1_RSA( ffi.Pointer pkey, @@ -2052,10 +2115,11 @@ class BoringSsl { ); } - late final _EVP_PKEY_get1_RSA_ptr = - _lookup>('EVP_PKEY_get1_RSA'); - late final _dart_EVP_PKEY_get1_RSA _EVP_PKEY_get1_RSA = - _EVP_PKEY_get1_RSA_ptr.asFunction<_dart_EVP_PKEY_get1_RSA>(); + late final _EVP_PKEY_get1_RSAPtr = _lookup< + ffi.NativeFunction Function(ffi.Pointer)>>( + 'EVP_PKEY_get1_RSA'); + late final _EVP_PKEY_get1_RSA = _EVP_PKEY_get1_RSAPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); /// EVP_PKEY_id returns the type of |pkey|, which is one of the |EVP_PKEY_*| /// values. @@ -2067,10 +2131,11 @@ class BoringSsl { ); } - late final _EVP_PKEY_id_ptr = - _lookup>('EVP_PKEY_id'); - late final _dart_EVP_PKEY_id _EVP_PKEY_id = - _EVP_PKEY_id_ptr.asFunction<_dart_EVP_PKEY_id>(); + late final _EVP_PKEY_idPtr = + _lookup)>>( + 'EVP_PKEY_id'); + late final _EVP_PKEY_id = + _EVP_PKEY_idPtr.asFunction)>(); /// EVP_PKEY_new creates a new, empty public-key object and returns it or NULL /// on allocation failure. @@ -2078,10 +2143,11 @@ class BoringSsl { return _EVP_PKEY_new(); } - late final _EVP_PKEY_new_ptr = - _lookup>('EVP_PKEY_new'); - late final _dart_EVP_PKEY_new _EVP_PKEY_new = - _EVP_PKEY_new_ptr.asFunction<_dart_EVP_PKEY_new>(); + late final _EVP_PKEY_newPtr = + _lookup Function()>>( + 'EVP_PKEY_new'); + late final _EVP_PKEY_new = + _EVP_PKEY_newPtr.asFunction Function()>(); int EVP_PKEY_set1_EC_KEY( ffi.Pointer pkey, @@ -2093,11 +2159,12 @@ class BoringSsl { ); } - late final _EVP_PKEY_set1_EC_KEY_ptr = - _lookup>( - 'EVP_PKEY_set1_EC_KEY'); - late final _dart_EVP_PKEY_set1_EC_KEY _EVP_PKEY_set1_EC_KEY = - _EVP_PKEY_set1_EC_KEY_ptr.asFunction<_dart_EVP_PKEY_set1_EC_KEY>(); + late final _EVP_PKEY_set1_EC_KEYPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('EVP_PKEY_set1_EC_KEY'); + late final _EVP_PKEY_set1_EC_KEY = _EVP_PKEY_set1_EC_KEYPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); /// Getting and setting concrete public key types. /// @@ -2123,10 +2190,12 @@ class BoringSsl { ); } - late final _EVP_PKEY_set1_RSA_ptr = - _lookup>('EVP_PKEY_set1_RSA'); - late final _dart_EVP_PKEY_set1_RSA _EVP_PKEY_set1_RSA = - _EVP_PKEY_set1_RSA_ptr.asFunction<_dart_EVP_PKEY_set1_RSA>(); + late final _EVP_PKEY_set1_RSAPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, ffi.Pointer)>>('EVP_PKEY_set1_RSA'); + late final _EVP_PKEY_set1_RSA = _EVP_PKEY_set1_RSAPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); /// EVP_PKEY_set_type sets the type of |pkey| to |type|. It returns one if /// successful or zero if the |type| argument is not one of the |EVP_PKEY_*| @@ -2141,10 +2210,11 @@ class BoringSsl { ); } - late final _EVP_PKEY_set_type_ptr = - _lookup>('EVP_PKEY_set_type'); - late final _dart_EVP_PKEY_set_type _EVP_PKEY_set_type = - _EVP_PKEY_set_type_ptr.asFunction<_dart_EVP_PKEY_set_type>(); + late final _EVP_PKEY_set_typePtr = _lookup< + ffi.NativeFunction, ffi.Int)>>( + 'EVP_PKEY_set_type'); + late final _EVP_PKEY_set_type = _EVP_PKEY_set_typePtr.asFunction< + int Function(ffi.Pointer, int)>(); /// EVP_aead_aes_128_gcm is AES-128 in Galois Counter Mode. /// @@ -2157,11 +2227,11 @@ class BoringSsl { return _EVP_aead_aes_128_gcm(); } - late final _EVP_aead_aes_128_gcm_ptr = - _lookup>( + late final _EVP_aead_aes_128_gcmPtr = + _lookup Function()>>( 'EVP_aead_aes_128_gcm'); - late final _dart_EVP_aead_aes_128_gcm _EVP_aead_aes_128_gcm = - _EVP_aead_aes_128_gcm_ptr.asFunction<_dart_EVP_aead_aes_128_gcm>(); + late final _EVP_aead_aes_128_gcm = + _EVP_aead_aes_128_gcmPtr.asFunction Function()>(); /// EVP_aead_aes_256_gcm is AES-256 in Galois Counter Mode. /// @@ -2174,47 +2244,51 @@ class BoringSsl { return _EVP_aead_aes_256_gcm(); } - late final _EVP_aead_aes_256_gcm_ptr = - _lookup>( + late final _EVP_aead_aes_256_gcmPtr = + _lookup Function()>>( 'EVP_aead_aes_256_gcm'); - late final _dart_EVP_aead_aes_256_gcm _EVP_aead_aes_256_gcm = - _EVP_aead_aes_256_gcm_ptr.asFunction<_dart_EVP_aead_aes_256_gcm>(); + late final _EVP_aead_aes_256_gcm = + _EVP_aead_aes_256_gcmPtr.asFunction Function()>(); ffi.Pointer EVP_aes_128_cbc() { return _EVP_aes_128_cbc(); } - late final _EVP_aes_128_cbc_ptr = - _lookup>('EVP_aes_128_cbc'); - late final _dart_EVP_aes_128_cbc _EVP_aes_128_cbc = - _EVP_aes_128_cbc_ptr.asFunction<_dart_EVP_aes_128_cbc>(); + late final _EVP_aes_128_cbcPtr = + _lookup Function()>>( + 'EVP_aes_128_cbc'); + late final _EVP_aes_128_cbc = + _EVP_aes_128_cbcPtr.asFunction Function()>(); ffi.Pointer EVP_aes_128_ctr() { return _EVP_aes_128_ctr(); } - late final _EVP_aes_128_ctr_ptr = - _lookup>('EVP_aes_128_ctr'); - late final _dart_EVP_aes_128_ctr _EVP_aes_128_ctr = - _EVP_aes_128_ctr_ptr.asFunction<_dart_EVP_aes_128_ctr>(); + late final _EVP_aes_128_ctrPtr = + _lookup Function()>>( + 'EVP_aes_128_ctr'); + late final _EVP_aes_128_ctr = + _EVP_aes_128_ctrPtr.asFunction Function()>(); ffi.Pointer EVP_aes_256_cbc() { return _EVP_aes_256_cbc(); } - late final _EVP_aes_256_cbc_ptr = - _lookup>('EVP_aes_256_cbc'); - late final _dart_EVP_aes_256_cbc _EVP_aes_256_cbc = - _EVP_aes_256_cbc_ptr.asFunction<_dart_EVP_aes_256_cbc>(); + late final _EVP_aes_256_cbcPtr = + _lookup Function()>>( + 'EVP_aes_256_cbc'); + late final _EVP_aes_256_cbc = + _EVP_aes_256_cbcPtr.asFunction Function()>(); ffi.Pointer EVP_aes_256_ctr() { return _EVP_aes_256_ctr(); } - late final _EVP_aes_256_ctr_ptr = - _lookup>('EVP_aes_256_ctr'); - late final _dart_EVP_aes_256_ctr _EVP_aes_256_ctr = - _EVP_aes_256_ctr_ptr.asFunction<_dart_EVP_aes_256_ctr>(); + late final _EVP_aes_256_ctrPtr = + _lookup Function()>>( + 'EVP_aes_256_ctr'); + late final _EVP_aes_256_ctr = + _EVP_aes_256_ctrPtr.asFunction Function()>(); /// EVP_marshal_private_key marshals |key| as a DER-encoded PrivateKeyInfo /// structure (RFC 5208) and appends the result to |cbb|. It returns one on @@ -2229,11 +2303,12 @@ class BoringSsl { ); } - late final _EVP_marshal_private_key_ptr = - _lookup>( - 'EVP_marshal_private_key'); - late final _dart_EVP_marshal_private_key _EVP_marshal_private_key = - _EVP_marshal_private_key_ptr.asFunction<_dart_EVP_marshal_private_key>(); + late final _EVP_marshal_private_keyPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('EVP_marshal_private_key'); + late final _EVP_marshal_private_key = _EVP_marshal_private_keyPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); /// EVP_marshal_public_key marshals |key| as a DER-encoded SubjectPublicKeyInfo /// structure (RFC 5280) and appends the result to |cbb|. It returns one on @@ -2248,11 +2323,12 @@ class BoringSsl { ); } - late final _EVP_marshal_public_key_ptr = - _lookup>( - 'EVP_marshal_public_key'); - late final _dart_EVP_marshal_public_key _EVP_marshal_public_key = - _EVP_marshal_public_key_ptr.asFunction<_dart_EVP_marshal_public_key>(); + late final _EVP_marshal_public_keyPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, + ffi.Pointer)>>('EVP_marshal_public_key'); + late final _EVP_marshal_public_key = _EVP_marshal_public_keyPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer)>(); /// EVP_parse_private_key decodes a DER-encoded PrivateKeyInfo structure (RFC /// 5208) from |cbs| and advances |cbs|. It returns a newly-allocated |EVP_PKEY| @@ -2260,7 +2336,9 @@ class BoringSsl { /// /// The caller must check the type of the parsed private key to ensure it is /// suitable and validate other desired key properties such as RSA modulus size - /// or EC curve. + /// or EC curve. In particular, RSA private key operations scale cubicly, so + /// applications accepting RSA private keys from external sources may need to + /// bound key sizes (use |EVP_PKEY_bits| or |RSA_bits|) to avoid a DoS vector. /// /// A PrivateKeyInfo ends with an optional set of attributes. These are not /// processed and so this function will silently ignore any trailing data in the @@ -2273,11 +2351,11 @@ class BoringSsl { ); } - late final _EVP_parse_private_key_ptr = - _lookup>( - 'EVP_parse_private_key'); - late final _dart_EVP_parse_private_key _EVP_parse_private_key = - _EVP_parse_private_key_ptr.asFunction<_dart_EVP_parse_private_key>(); + late final _EVP_parse_private_keyPtr = _lookup< + ffi.NativeFunction Function(ffi.Pointer)>>( + 'EVP_parse_private_key'); + late final _EVP_parse_private_key = _EVP_parse_private_keyPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); /// EVP_parse_public_key decodes a DER-encoded SubjectPublicKeyInfo structure /// (RFC 5280) from |cbs| and advances |cbs|. It returns a newly-allocated @@ -2295,67 +2373,47 @@ class BoringSsl { ); } - late final _EVP_parse_public_key_ptr = - _lookup>( - 'EVP_parse_public_key'); - late final _dart_EVP_parse_public_key _EVP_parse_public_key = - _EVP_parse_public_key_ptr.asFunction<_dart_EVP_parse_public_key>(); + late final _EVP_parse_public_keyPtr = _lookup< + ffi.NativeFunction Function(ffi.Pointer)>>( + 'EVP_parse_public_key'); + late final _EVP_parse_public_key = _EVP_parse_public_keyPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); ffi.Pointer EVP_sha1() { return _EVP_sha1(); } - late final _EVP_sha1_ptr = - _lookup>('EVP_sha1'); - late final _dart_EVP_sha1 _EVP_sha1 = - _EVP_sha1_ptr.asFunction<_dart_EVP_sha1>(); + late final _EVP_sha1Ptr = + _lookup Function()>>('EVP_sha1'); + late final _EVP_sha1 = + _EVP_sha1Ptr.asFunction Function()>(); ffi.Pointer EVP_sha256() { return _EVP_sha256(); } - late final _EVP_sha256_ptr = - _lookup>('EVP_sha256'); - late final _dart_EVP_sha256 _EVP_sha256 = - _EVP_sha256_ptr.asFunction<_dart_EVP_sha256>(); + late final _EVP_sha256Ptr = + _lookup Function()>>('EVP_sha256'); + late final _EVP_sha256 = + _EVP_sha256Ptr.asFunction Function()>(); ffi.Pointer EVP_sha384() { return _EVP_sha384(); } - late final _EVP_sha384_ptr = - _lookup>('EVP_sha384'); - late final _dart_EVP_sha384 _EVP_sha384 = - _EVP_sha384_ptr.asFunction<_dart_EVP_sha384>(); + late final _EVP_sha384Ptr = + _lookup Function()>>('EVP_sha384'); + late final _EVP_sha384 = + _EVP_sha384Ptr.asFunction Function()>(); ffi.Pointer EVP_sha512() { return _EVP_sha512(); } - late final _EVP_sha512_ptr = - _lookup>('EVP_sha512'); - late final _dart_EVP_sha512 _EVP_sha512 = - _EVP_sha512_ptr.asFunction<_dart_EVP_sha512>(); - - late final ffi.Pointer _EXTENDED_KEY_USAGE_it = - _lookup('EXTENDED_KEY_USAGE_it'); - - ffi.Pointer get EXTENDED_KEY_USAGE_it => _EXTENDED_KEY_USAGE_it; - - late final ffi.Pointer _GENERAL_NAMES_it = - _lookup('GENERAL_NAMES_it'); - - ffi.Pointer get GENERAL_NAMES_it => _GENERAL_NAMES_it; - - late final ffi.Pointer _GENERAL_NAME_it = - _lookup('GENERAL_NAME_it'); - - ffi.Pointer get GENERAL_NAME_it => _GENERAL_NAME_it; - - late final ffi.Pointer _GENERAL_SUBTREE_it = - _lookup('GENERAL_SUBTREE_it'); - - ffi.Pointer get GENERAL_SUBTREE_it => _GENERAL_SUBTREE_it; + late final _EVP_sha512Ptr = + _lookup Function()>>('EVP_sha512'); + late final _EVP_sha512 = + _EVP_sha512Ptr.asFunction Function()>(); /// HKDF computes HKDF (as specified by RFC 5869) of initial keying material /// |secret| with |salt| and |info| using |digest|, and outputs |out_len| bytes @@ -2388,8 +2446,29 @@ class BoringSsl { ); } - late final _HKDF_ptr = _lookup>('HKDF'); - late final _dart_HKDF _HKDF = _HKDF_ptr.asFunction<_dart_HKDF>(); + late final _HKDFPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Size)>>('HKDF'); + late final _HKDF = _HKDFPtr.asFunction< + int Function( + ffi.Pointer, + int, + ffi.Pointer, + ffi.Pointer, + int, + ffi.Pointer, + int, + ffi.Pointer, + int)>(); /// HMAC_CTX_free calls |HMAC_CTX_cleanup| and then frees |ctx| itself. void HMAC_CTX_free( @@ -2400,10 +2479,11 @@ class BoringSsl { ); } - late final _HMAC_CTX_free_ptr = - _lookup>('HMAC_CTX_free'); - late final _dart_HMAC_CTX_free _HMAC_CTX_free = - _HMAC_CTX_free_ptr.asFunction<_dart_HMAC_CTX_free>(); + late final _HMAC_CTX_freePtr = + _lookup)>>( + 'HMAC_CTX_free'); + late final _HMAC_CTX_free = + _HMAC_CTX_freePtr.asFunction)>(); /// HMAC_CTX_new allocates and initialises a new |HMAC_CTX| and returns it, or /// NULL on allocation failure. The caller must use |HMAC_CTX_free| to release @@ -2412,10 +2492,11 @@ class BoringSsl { return _HMAC_CTX_new(); } - late final _HMAC_CTX_new_ptr = - _lookup>('HMAC_CTX_new'); - late final _dart_HMAC_CTX_new _HMAC_CTX_new = - _HMAC_CTX_new_ptr.asFunction<_dart_HMAC_CTX_new>(); + late final _HMAC_CTX_newPtr = + _lookup Function()>>( + 'HMAC_CTX_new'); + late final _HMAC_CTX_new = + _HMAC_CTX_newPtr.asFunction Function()>(); /// HMAC_Final completes the HMAC operation in |ctx| and writes the result to /// |out| and the sets |*out_len| to the length of the result. On entry, |out| @@ -2425,7 +2506,7 @@ class BoringSsl { int HMAC_Final( ffi.Pointer ctx, ffi.Pointer out, - ffi.Pointer out_len, + ffi.Pointer out_len, ) { return _HMAC_Final( ctx, @@ -2434,10 +2515,13 @@ class BoringSsl { ); } - late final _HMAC_Final_ptr = - _lookup>('HMAC_Final'); - late final _dart_HMAC_Final _HMAC_Final = - _HMAC_Final_ptr.asFunction<_dart_HMAC_Final>(); + late final _HMAC_FinalPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>>('HMAC_Final'); + late final _HMAC_Final = _HMAC_FinalPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); /// HMAC_Init_ex sets up an initialised |HMAC_CTX| to use |md| as the hash /// function and |key| as the key. For a non-initial call, |md| may be NULL, in @@ -2464,10 +2548,17 @@ class BoringSsl { ); } - late final _HMAC_Init_ex_ptr = - _lookup>('HMAC_Init_ex'); - late final _dart_HMAC_Init_ex _HMAC_Init_ex = - _HMAC_Init_ex_ptr.asFunction<_dart_HMAC_Init_ex>(); + late final _HMAC_Init_exPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Pointer)>>('HMAC_Init_ex'); + late final _HMAC_Init_ex = _HMAC_Init_exPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, int, + ffi.Pointer, ffi.Pointer)>(); /// HMAC_Update hashes |data_len| bytes from |data| into the current HMAC /// operation in |ctx|. It returns one. @@ -2483,10 +2574,12 @@ class BoringSsl { ); } - late final _HMAC_Update_ptr = - _lookup>('HMAC_Update'); - late final _dart_HMAC_Update _HMAC_Update = - _HMAC_Update_ptr.asFunction<_dart_HMAC_Update>(); + late final _HMAC_UpdatePtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Size)>>('HMAC_Update'); + late final _HMAC_Update = _HMAC_UpdatePtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, int)>(); /// HMAC_size returns the size, in bytes, of the HMAC that will be produced by /// |ctx|. On entry, |ctx| must have been setup with |HMAC_Init_ex|. @@ -2498,35 +2591,11 @@ class BoringSsl { ); } - late final _HMAC_size_ptr = - _lookup>('HMAC_size'); - late final _dart_HMAC_size _HMAC_size = - _HMAC_size_ptr.asFunction<_dart_HMAC_size>(); - - late final ffi.Pointer _ISSUING_DIST_POINT_it = - _lookup('ISSUING_DIST_POINT_it'); - - ffi.Pointer get ISSUING_DIST_POINT_it => _ISSUING_DIST_POINT_it; - - late final ffi.Pointer _NAME_CONSTRAINTS_it = - _lookup('NAME_CONSTRAINTS_it'); - - ffi.Pointer get NAME_CONSTRAINTS_it => _NAME_CONSTRAINTS_it; - - late final ffi.Pointer _NETSCAPE_SPKAC_it = - _lookup('NETSCAPE_SPKAC_it'); - - ffi.Pointer get NETSCAPE_SPKAC_it => _NETSCAPE_SPKAC_it; - - late final ffi.Pointer _NETSCAPE_SPKI_it = - _lookup('NETSCAPE_SPKI_it'); - - ffi.Pointer get NETSCAPE_SPKI_it => _NETSCAPE_SPKI_it; - - late final ffi.Pointer _NOTICEREF_it = - _lookup('NOTICEREF_it'); - - ffi.Pointer get NOTICEREF_it => _NOTICEREF_it; + late final _HMAC_sizePtr = + _lookup)>>( + 'HMAC_size'); + late final _HMAC_size = + _HMAC_sizePtr.asFunction)>(); /// OPENSSL_free does nothing if |ptr| is NULL. Otherwise it zeros out the /// memory allocated at |ptr| and frees it. @@ -2538,37 +2607,11 @@ class BoringSsl { ); } - late final _OPENSSL_free_ptr = - _lookup>('OPENSSL_free'); - late final _dart_OPENSSL_free _OPENSSL_free = - _OPENSSL_free_ptr.asFunction<_dart_OPENSSL_free>(); - - /// OPENSSL_ia32cap_P contains the Intel CPUID bits when running on an x86 or - /// x86-64 system. - /// - /// Index 0: - /// EDX for CPUID where EAX = 1 - /// Bit 20 is always zero - /// Bit 28 is adjusted to reflect whether the data cache is shared between - /// multiple logical cores - /// Bit 30 is used to indicate an Intel CPU - /// Index 1: - /// ECX for CPUID where EAX = 1 - /// Bit 11 is used to indicate AMD XOP support, not SDBG - /// Index 2: - /// EBX for CPUID where EAX = 7 - /// Index 3: - /// ECX for CPUID where EAX = 7 - /// - /// Note: the CPUID bits are pre-adjusted for the OSXSAVE bit and the YMM and XMM - /// bits in XCR0, so it is not necessary to check those. - late final ffi.Pointer> _OPENSSL_ia32cap_P = - _lookup>('OPENSSL_ia32cap_P'); - - ffi.Pointer get OPENSSL_ia32cap_P => _OPENSSL_ia32cap_P.value; - - set OPENSSL_ia32cap_P(ffi.Pointer value) => - _OPENSSL_ia32cap_P.value = value; + late final _OPENSSL_freePtr = + _lookup)>>( + 'OPENSSL_free'); + late final _OPENSSL_free = + _OPENSSL_freePtr.asFunction)>(); /// OPENSSL_malloc acts like a regular |malloc|. ffi.Pointer OPENSSL_malloc( @@ -2579,10 +2622,11 @@ class BoringSsl { ); } - late final _OPENSSL_malloc_ptr = - _lookup>('OPENSSL_malloc'); - late final _dart_OPENSSL_malloc _OPENSSL_malloc = - _OPENSSL_malloc_ptr.asFunction<_dart_OPENSSL_malloc>(); + late final _OPENSSL_mallocPtr = + _lookup Function(ffi.Size)>>( + 'OPENSSL_malloc'); + late final _OPENSSL_malloc = + _OPENSSL_mallocPtr.asFunction Function(int)>(); /// OPENSSL_memdup returns an allocated, duplicate of |size| bytes from |data| or /// NULL on allocation failure. @@ -2596,21 +2640,18 @@ class BoringSsl { ); } - late final _OPENSSL_memdup_ptr = - _lookup>('OPENSSL_memdup'); - late final _dart_OPENSSL_memdup _OPENSSL_memdup = - _OPENSSL_memdup_ptr.asFunction<_dart_OPENSSL_memdup>(); - - late final ffi.Pointer _OTHERNAME_it = - _lookup('OTHERNAME_it'); - - ffi.Pointer get OTHERNAME_it => _OTHERNAME_it; + late final _OPENSSL_memdupPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Size)>>('OPENSSL_memdup'); + late final _OPENSSL_memdup = _OPENSSL_memdupPtr.asFunction< + ffi.Pointer Function(ffi.Pointer, int)>(); /// PKCS5_PBKDF2_HMAC computes |iterations| iterations of PBKDF2 of |password| /// and |salt|, using |digest|, and outputs |key_len| bytes to |out_key|. It /// returns one on success and zero on allocation failure or if iterations is 0. int PKCS5_PBKDF2_HMAC( - ffi.Pointer password, + ffi.Pointer password, int password_len, ffi.Pointer salt, int salt_len, @@ -2631,57 +2672,20 @@ class BoringSsl { ); } - late final _PKCS5_PBKDF2_HMAC_ptr = - _lookup>('PKCS5_PBKDF2_HMAC'); - late final _dart_PKCS5_PBKDF2_HMAC _PKCS5_PBKDF2_HMAC = - _PKCS5_PBKDF2_HMAC_ptr.asFunction<_dart_PKCS5_PBKDF2_HMAC>(); - - late final ffi.Pointer _PKCS8_PRIV_KEY_INFO_it = - _lookup('PKCS8_PRIV_KEY_INFO_it'); - - ffi.Pointer get PKCS8_PRIV_KEY_INFO_it => - _PKCS8_PRIV_KEY_INFO_it; - - late final ffi.Pointer _PKEY_USAGE_PERIOD_it = - _lookup('PKEY_USAGE_PERIOD_it'); - - ffi.Pointer get PKEY_USAGE_PERIOD_it => _PKEY_USAGE_PERIOD_it; - - late final ffi.Pointer _POLICYINFO_it = - _lookup('POLICYINFO_it'); - - ffi.Pointer get POLICYINFO_it => _POLICYINFO_it; - - late final ffi.Pointer _POLICYQUALINFO_it = - _lookup('POLICYQUALINFO_it'); - - ffi.Pointer get POLICYQUALINFO_it => _POLICYQUALINFO_it; - - late final ffi.Pointer _POLICY_CONSTRAINTS_it = - _lookup('POLICY_CONSTRAINTS_it'); - - ffi.Pointer get POLICY_CONSTRAINTS_it => _POLICY_CONSTRAINTS_it; - - late final ffi.Pointer _POLICY_MAPPINGS_it = - _lookup('POLICY_MAPPINGS_it'); - - ffi.Pointer get POLICY_MAPPINGS_it => _POLICY_MAPPINGS_it; - - late final ffi.Pointer _POLICY_MAPPING_it = - _lookup('POLICY_MAPPING_it'); - - ffi.Pointer get POLICY_MAPPING_it => _POLICY_MAPPING_it; - - late final ffi.Pointer _PROXY_CERT_INFO_EXTENSION_it = - _lookup('PROXY_CERT_INFO_EXTENSION_it'); - - ffi.Pointer get PROXY_CERT_INFO_EXTENSION_it => - _PROXY_CERT_INFO_EXTENSION_it; - - late final ffi.Pointer _PROXY_POLICY_it = - _lookup('PROXY_POLICY_it'); - - ffi.Pointer get PROXY_POLICY_it => _PROXY_POLICY_it; + late final _PKCS5_PBKDF2_HMACPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Size, + ffi.UnsignedInt, + ffi.Pointer, + ffi.Size, + ffi.Pointer)>>('PKCS5_PBKDF2_HMAC'); + late final _PKCS5_PBKDF2_HMAC = _PKCS5_PBKDF2_HMACPtr.asFunction< + int Function(ffi.Pointer, int, ffi.Pointer, int, int, + ffi.Pointer, int, ffi.Pointer)>(); /// RAND_bytes writes |len| bytes of random data to |buf| and returns one. int RAND_bytes( @@ -2694,10 +2698,11 @@ class BoringSsl { ); } - late final _RAND_bytes_ptr = - _lookup>('RAND_bytes'); - late final _dart_RAND_bytes _RAND_bytes = - _RAND_bytes_ptr.asFunction<_dart_RAND_bytes>(); + late final _RAND_bytesPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Size)>>('RAND_bytes'); + late final _RAND_bytes = + _RAND_bytesPtr.asFunction, int)>(); /// RSAPublicKey_dup allocates a fresh |RSA| and copies the public key from /// |rsa| into it. It returns the fresh |RSA| object, or NULL on error. @@ -2709,15 +2714,11 @@ class BoringSsl { ); } - late final _RSAPublicKey_dup_ptr = - _lookup>('RSAPublicKey_dup'); - late final _dart_RSAPublicKey_dup _RSAPublicKey_dup = - _RSAPublicKey_dup_ptr.asFunction<_dart_RSAPublicKey_dup>(); - - late final ffi.Pointer _RSA_PSS_PARAMS_it = - _lookup('RSA_PSS_PARAMS_it'); - - ffi.Pointer get RSA_PSS_PARAMS_it => _RSA_PSS_PARAMS_it; + late final _RSAPublicKey_dupPtr = + _lookup Function(ffi.Pointer)>>( + 'RSAPublicKey_dup'); + late final _RSAPublicKey_dup = _RSAPublicKey_dupPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); /// RSA_check_key performs basic validity tests on |rsa|. It returns one if /// they pass and zero otherwise. Opaque keys and public keys always pass. If it @@ -2730,10 +2731,11 @@ class BoringSsl { ); } - late final _RSA_check_key_ptr = - _lookup>('RSA_check_key'); - late final _dart_RSA_check_key _RSA_check_key = - _RSA_check_key_ptr.asFunction<_dart_RSA_check_key>(); + late final _RSA_check_keyPtr = + _lookup)>>( + 'RSA_check_key'); + late final _RSA_check_key = + _RSA_check_keyPtr.asFunction)>(); /// RSA_free decrements the reference count of |rsa| and frees it if the /// reference count drops to zero. @@ -2745,10 +2747,11 @@ class BoringSsl { ); } - late final _RSA_free_ptr = - _lookup>('RSA_free'); - late final _dart_RSA_free _RSA_free = - _RSA_free_ptr.asFunction<_dart_RSA_free>(); + late final _RSA_freePtr = + _lookup)>>( + 'RSA_free'); + late final _RSA_free = + _RSA_freePtr.asFunction)>(); /// RSA_generate_key_ex generates a new RSA key where the modulus has size /// |bits| and the public exponent is |e|. If unsure, |RSA_F4| is a good value @@ -2772,11 +2775,13 @@ class BoringSsl { ); } - late final _RSA_generate_key_ex_ptr = - _lookup>( - 'RSA_generate_key_ex'); - late final _dart_RSA_generate_key_ex _RSA_generate_key_ex = - _RSA_generate_key_ex_ptr.asFunction<_dart_RSA_generate_key_ex>(); + late final _RSA_generate_key_exPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Int, ffi.Pointer, + ffi.Pointer)>>('RSA_generate_key_ex'); + late final _RSA_generate_key_ex = _RSA_generate_key_exPtr.asFunction< + int Function( + ffi.Pointer, int, ffi.Pointer, ffi.Pointer)>(); /// RSA_get0_crt_params sets |*out_dmp1|, |*out_dmq1|, and |*out_iqmp|, if /// non-NULL, to |rsa|'s CRT parameters. These are d (mod p-1), d (mod q-1) and @@ -2796,11 +2801,19 @@ class BoringSsl { ); } - late final _RSA_get0_crt_params_ptr = - _lookup>( - 'RSA_get0_crt_params'); - late final _dart_RSA_get0_crt_params _RSA_get0_crt_params = - _RSA_get0_crt_params_ptr.asFunction<_dart_RSA_get0_crt_params>(); + late final _RSA_get0_crt_paramsPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer>, + ffi.Pointer>, + ffi.Pointer>)>>('RSA_get0_crt_params'); + late final _RSA_get0_crt_params = _RSA_get0_crt_paramsPtr.asFunction< + void Function( + ffi.Pointer, + ffi.Pointer>, + ffi.Pointer>, + ffi.Pointer>)>(); /// RSA_get0_factors sets |*out_p| and |*out_q|, if non-NULL, to |rsa|'s prime /// factors. If |rsa| is a public key, they will be set to NULL. @@ -2816,10 +2829,13 @@ class BoringSsl { ); } - late final _RSA_get0_factors_ptr = - _lookup>('RSA_get0_factors'); - late final _dart_RSA_get0_factors _RSA_get0_factors = - _RSA_get0_factors_ptr.asFunction<_dart_RSA_get0_factors>(); + late final _RSA_get0_factorsPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Pointer>, + ffi.Pointer>)>>('RSA_get0_factors'); + late final _RSA_get0_factors = _RSA_get0_factorsPtr.asFunction< + void Function(ffi.Pointer, ffi.Pointer>, + ffi.Pointer>)>(); /// RSA_get0_key sets |*out_n|, |*out_e|, and |*out_d|, if non-NULL, to |rsa|'s /// modulus, public exponent, and private exponent, respectively. If |rsa| is a @@ -2838,18 +2854,28 @@ class BoringSsl { ); } - late final _RSA_get0_key_ptr = - _lookup>('RSA_get0_key'); - late final _dart_RSA_get0_key _RSA_get0_key = - _RSA_get0_key_ptr.asFunction<_dart_RSA_get0_key>(); + late final _RSA_get0_keyPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer>, + ffi.Pointer>, + ffi.Pointer>)>>('RSA_get0_key'); + late final _RSA_get0_key = _RSA_get0_keyPtr.asFunction< + void Function( + ffi.Pointer, + ffi.Pointer>, + ffi.Pointer>, + ffi.Pointer>)>(); /// RSA_new returns a new, empty |RSA| object or NULL on error. ffi.Pointer RSA_new() { return _RSA_new(); } - late final _RSA_new_ptr = _lookup>('RSA_new'); - late final _dart_RSA_new _RSA_new = _RSA_new_ptr.asFunction<_dart_RSA_new>(); + late final _RSA_newPtr = + _lookup Function()>>('RSA_new'); + late final _RSA_new = _RSA_newPtr.asFunction Function()>(); /// RSA_set0_crt_params sets |rsa|'s CRT parameters to |dmp1|, |dmq1|, and /// |iqmp|, if non-NULL, and takes ownership of them. On success, it takes @@ -2873,11 +2899,16 @@ class BoringSsl { ); } - late final _RSA_set0_crt_params_ptr = - _lookup>( - 'RSA_set0_crt_params'); - late final _dart_RSA_set0_crt_params _RSA_set0_crt_params = - _RSA_set0_crt_params_ptr.asFunction<_dart_RSA_set0_crt_params>(); + late final _RSA_set0_crt_paramsPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('RSA_set0_crt_params'); + late final _RSA_set0_crt_params = _RSA_set0_crt_paramsPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); /// RSA_set0_factors sets |rsa|'s prime factors to |p| and |q|, if non-NULL, and /// takes ownership of them. On success, it takes ownership of each argument and @@ -2899,10 +2930,13 @@ class BoringSsl { ); } - late final _RSA_set0_factors_ptr = - _lookup>('RSA_set0_factors'); - late final _dart_RSA_set0_factors _RSA_set0_factors = - _RSA_set0_factors_ptr.asFunction<_dart_RSA_set0_factors>(); + late final _RSA_set0_factorsPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer)>>('RSA_set0_factors'); + late final _RSA_set0_factors = _RSA_set0_factorsPtr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer, ffi.Pointer)>(); /// RSA_set0_key sets |rsa|'s modulus, public exponent, and private exponent to /// |n|, |e|, and |d| respectively, if non-NULL. On success, it takes ownership @@ -2927,444 +2961,488 @@ class BoringSsl { ); } - late final _RSA_set0_key_ptr = - _lookup>('RSA_set0_key'); - late final _dart_RSA_set0_key _RSA_set0_key = - _RSA_set0_key_ptr.asFunction<_dart_RSA_set0_key>(); + late final _RSA_set0_keyPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer, + ffi.Pointer, ffi.Pointer)>>('RSA_set0_key'); + late final _RSA_set0_key = _RSA_set0_keyPtr.asFunction< + int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, + ffi.Pointer)>(); + + late final ffi.Pointer ___daylight = _lookup('__daylight'); + + int get __daylight => ___daylight.value; - late final ffi.Pointer _SXNETID_it = - _lookup('SXNETID_it'); + set __daylight(int value) => ___daylight.value = value; - ffi.Pointer get SXNETID_it => _SXNETID_it; + late final ffi.Pointer ___timezone = + _lookup('__timezone'); - late final ffi.Pointer _SXNET_it = - _lookup('SXNET_it'); + int get __timezone => ___timezone.value; - ffi.Pointer get SXNET_it => _SXNET_it; + set __timezone(int value) => ___timezone.value = value; - late final ffi.Pointer _USERNOTICE_it = - _lookup('USERNOTICE_it'); + late final ffi.Pointer>> ___tzname = + _lookup>>('__tzname'); - ffi.Pointer get USERNOTICE_it => _USERNOTICE_it; + ffi.Pointer> get __tzname => ___tzname.value; - late final ffi.Pointer _X509_ALGORS_it = - _lookup('X509_ALGORS_it'); + set __tzname(ffi.Pointer> value) => + ___tzname.value = value; - ffi.Pointer get X509_ALGORS_it => _X509_ALGORS_it; + late final ffi.Pointer _daylight = _lookup('daylight'); - late final ffi.Pointer _X509_ALGOR_it = - _lookup('X509_ALGOR_it'); + int get daylight => _daylight.value; - ffi.Pointer get X509_ALGOR_it => _X509_ALGOR_it; + set daylight(int value) => _daylight.value = value; - late final ffi.Pointer _X509_ATTRIBUTE_it = - _lookup('X509_ATTRIBUTE_it'); + late final ffi.Pointer> _stderr = + _lookup>('stderr'); - ffi.Pointer get X509_ATTRIBUTE_it => _X509_ATTRIBUTE_it; + ffi.Pointer get stderr => _stderr.value; - late final ffi.Pointer _X509_CERT_AUX_it = - _lookup('X509_CERT_AUX_it'); + set stderr(ffi.Pointer value) => _stderr.value = value; - ffi.Pointer get X509_CERT_AUX_it => _X509_CERT_AUX_it; + late final ffi.Pointer> _stdin = + _lookup>('stdin'); - late final ffi.Pointer _X509_CINF_it = - _lookup('X509_CINF_it'); + ffi.Pointer get stdin => _stdin.value; - ffi.Pointer get X509_CINF_it => _X509_CINF_it; + set stdin(ffi.Pointer value) => _stdin.value = value; - late final ffi.Pointer _X509_CRL_INFO_it = - _lookup('X509_CRL_INFO_it'); + late final ffi.Pointer> _stdout = + _lookup>('stdout'); - ffi.Pointer get X509_CRL_INFO_it => _X509_CRL_INFO_it; + ffi.Pointer get stdout => _stdout.value; - late final ffi.Pointer _X509_CRL_it = - _lookup('X509_CRL_it'); + set stdout(ffi.Pointer value) => _stdout.value = value; - ffi.Pointer get X509_CRL_it => _X509_CRL_it; + late final ffi.Pointer _timezone = _lookup('timezone'); - late final ffi.Pointer _X509_EXTENSIONS_it = - _lookup('X509_EXTENSIONS_it'); + int get timezone => _timezone.value; - ffi.Pointer get X509_EXTENSIONS_it => _X509_EXTENSIONS_it; + set timezone(int value) => _timezone.value = value; - late final ffi.Pointer _X509_EXTENSION_it = - _lookup('X509_EXTENSION_it'); + late final ffi.Pointer>> _tzname = + _lookup>>('tzname'); - ffi.Pointer get X509_EXTENSION_it => _X509_EXTENSION_it; + ffi.Pointer> get tzname => _tzname.value; - late final ffi.Pointer _X509_NAME_ENTRY_it = - _lookup('X509_NAME_ENTRY_it'); + set tzname(ffi.Pointer> value) => _tzname.value = value; - ffi.Pointer get X509_NAME_ENTRY_it => _X509_NAME_ENTRY_it; + late final addresses = _SymbolAddresses(this); +} - late final ffi.Pointer _X509_NAME_it = - _lookup('X509_NAME_it'); +class _SymbolAddresses { + final BoringSsl _library; + _SymbolAddresses(this._library); + ffi.Pointer)>> + get EVP_PKEY_free => _library._EVP_PKEY_freePtr; +} - ffi.Pointer get X509_NAME_it => _X509_NAME_it; +const int AES_BLOCK_SIZE = 16; - late final ffi.Pointer _X509_PUBKEY_it = - _lookup('X509_PUBKEY_it'); +class ASN1_ITEM_st extends ffi.Opaque {} - ffi.Pointer get X509_PUBKEY_it => _X509_PUBKEY_it; +class AUTHORITY_KEYID_st extends ffi.Opaque {} - late final ffi.Pointer _X509_REQ_INFO_it = - _lookup('X509_REQ_INFO_it'); +class BASIC_CONSTRAINTS_st extends ffi.Opaque {} - ffi.Pointer get X509_REQ_INFO_it => _X509_REQ_INFO_it; +typedef BIGNUM = bignum_st; +typedef BN_CTX = bignum_ctx; +typedef BN_GENCB = bn_gencb_st; +typedef BN_ULONG = ffi.Uint64; +typedef CBB = cbb_st; +typedef CBS = cbs_st; - late final ffi.Pointer _X509_REQ_it = - _lookup('X509_REQ_it'); +class CRYPTO_dynlock extends ffi.Struct { + @ffi.Int() + external int references; - ffi.Pointer get X509_REQ_it => _X509_REQ_it; + external ffi.Pointer data; +} - late final ffi.Pointer _X509_REVOKED_it = - _lookup('X509_REVOKED_it'); +class CRYPTO_dynlock_value extends ffi.Opaque {} - ffi.Pointer get X509_REVOKED_it => _X509_REVOKED_it; +class DIST_POINT_st extends ffi.Opaque {} - late final ffi.Pointer _X509_SIG_it = - _lookup('X509_SIG_it'); +class DSA_SIG_st extends ffi.Opaque {} - ffi.Pointer get X509_SIG_it => _X509_SIG_it; +typedef ECDSA_SIG = ecdsa_sig_st; +typedef EC_GROUP = ec_group_st; +typedef EC_KEY = ec_key_st; - late final ffi.Pointer _X509_VAL_it = - _lookup('X509_VAL_it'); +const int EC_PKEY_NO_PUBKEY = 2; - ffi.Pointer get X509_VAL_it => _X509_VAL_it; +typedef EC_POINT = ec_point_st; - late final ffi.Pointer _X509_it = - _lookup('X509_it'); +/// EC_builtin_curve describes a supported elliptic curve. +class EC_builtin_curve extends ffi.Struct { + @ffi.Int() + external int nid; - ffi.Pointer get X509_it => _X509_it; + external ffi.Pointer comment; +} - late final ffi.Pointer ___mb_cur_max = - _lookup('__mb_cur_max'); +typedef ENGINE = engine_st; - int get __mb_cur_max => ___mb_cur_max.value; +const int ERR_LIB_HKDF = 31; - set __mb_cur_max(int value) => ___mb_cur_max.value = value; +typedef EVP_AEAD = evp_aead_st; +typedef EVP_AEAD_CTX = evp_aead_ctx_st; +typedef EVP_CIPHER = evp_cipher_st; +typedef EVP_CIPHER_CTX = evp_cipher_ctx_st; +typedef EVP_MD = env_md_st; +typedef EVP_MD_CTX = env_md_ctx_st; +typedef EVP_PKEY = evp_pkey_st; +typedef EVP_PKEY_CTX = evp_pkey_ctx_st; - late final ffi.Pointer> ___stderrp = - _lookup>('__stderrp'); +const int EVP_PKEY_EC = 408; - ffi.Pointer get __stderrp => ___stderrp.value; +const int EVP_PKEY_RSA = 6; - set __stderrp(ffi.Pointer value) => ___stderrp.value = value; +typedef FILE = _IO_FILE; - late final ffi.Pointer> ___stdinp = - _lookup>('__stdinp'); +const int HKDF_R_OUTPUT_TOO_LARGE = 100; - ffi.Pointer get __stdinp => ___stdinp.value; +typedef HMAC_CTX = hmac_ctx_st; - set __stdinp(ffi.Pointer value) => ___stdinp.value = value; +class ISSUING_DIST_POINT_st extends ffi.Opaque {} - late final ffi.Pointer> ___stdoutp = - _lookup>('__stdoutp'); +class NAME_CONSTRAINTS_st extends ffi.Opaque {} - ffi.Pointer get __stdoutp => ___stdoutp.value; +const int NID_X9_62_prime256v1 = 415; - set __stdoutp(ffi.Pointer value) => ___stdoutp.value = value; +const int NID_secp384r1 = 715; - late final ffi.Pointer _daylight = _lookup('daylight'); +const int NID_secp521r1 = 716; - int get daylight => _daylight.value; +class Netscape_spkac_st extends ffi.Opaque {} - set daylight(int value) => _daylight.value = value; +class Netscape_spki_st extends ffi.Opaque {} - late final ffi.Pointer _getdate_err = - _lookup('getdate_err'); +/// OPENSSL_sk_cmp_func is a comparison function that returns a value < 0, 0 or > +/// 0 if |*a| is less than, equal to or greater than |*b|, respectively. Note +/// the extra indirection - the function is given a pointer to a pointer to the +/// element. This differs from the usual qsort/bsearch comparison function. +/// +/// Note its actual type is |int (*)(const T **a, const T **b)|. Low-level |sk_*| +/// functions will be passed a type-specific wrapper to call it correctly. +/// +/// TODO(davidben): This type should be |const T *const *|. It is already fixed +/// in OpenSSL 1.1.1, so hopefully we can fix this compatibly. +typedef OPENSSL_sk_cmp_func = ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer>, + ffi.Pointer>)>>; - int get getdate_err => _getdate_err.value; +class RIPEMD160state_st extends ffi.Opaque {} - set getdate_err(int value) => _getdate_err.value = value; +typedef RSA = rsa_st; - late final ffi.Pointer> _suboptarg = - _lookup>('suboptarg'); +const int RSA_PKCS1_OAEP_PADDING = 4; - ffi.Pointer get suboptarg => _suboptarg.value; +const int RSA_PKCS1_PADDING = 1; - set suboptarg(ffi.Pointer value) => _suboptarg.value = value; +const int RSA_PKCS1_PSS_PADDING = 6; - late final ffi.Pointer>> _sys_errlist = - _lookup>>('sys_errlist'); +class UnnamedUnion1 extends ffi.Union { + @ffi.UnsignedInt() + external int __wch; - ffi.Pointer> get sys_errlist => _sys_errlist.value; + @ffi.Array.multi([4]) + external ffi.Array __wchb; +} - set sys_errlist(ffi.Pointer> value) => - _sys_errlist.value = value; +class X509_VERIFY_PARAM_st extends ffi.Opaque {} - late final ffi.Pointer _sys_nerr = _lookup('sys_nerr'); +class X509_algor_st extends ffi.Opaque {} - int get sys_nerr => _sys_nerr.value; +class X509_crl_st extends ffi.Opaque {} - set sys_nerr(int value) => _sys_nerr.value = value; +class X509_extension_st extends ffi.Opaque {} - late final ffi.Pointer _timezone = _lookup('timezone'); +class X509_info_st extends ffi.Opaque {} - int get timezone => _timezone.value; +class X509_name_entry_st extends ffi.Opaque {} - set timezone(int value) => _timezone.value = value; +class X509_name_st extends ffi.Opaque {} - late final ffi.Pointer>> _tzname = - _lookup>>('tzname'); +class X509_pubkey_st extends ffi.Opaque {} - ffi.Pointer> get tzname => _tzname.value; +class X509_req_st extends ffi.Opaque {} - set tzname(ffi.Pointer> value) => _tzname.value = value; +class X509_sig_st extends ffi.Opaque {} - late final addresses = _SymbolAddresses(this); +class _G_fpos64_t extends ffi.Struct { + @__off64_t() + external int __pos; + + external __mbstate_t __state; } -class _SymbolAddresses { - final BoringSsl _library; - _SymbolAddresses(this._library); - ffi.Pointer> get EVP_PKEY_free => - _library._EVP_PKEY_free_ptr; +class _G_fpos_t extends ffi.Struct { + @__off_t() + external int __pos; + + external __mbstate_t __state; } -const int AES_BLOCK_SIZE = 16; +class _IO_FILE extends ffi.Struct { + @ffi.Int() + external int _flags; -class ASN1_ITEM_st extends ffi.Opaque {} + external ffi.Pointer _IO_read_ptr; -/// Private functions -class BIGNUM extends ffi.Struct { - /// d is a pointer to an array of |width| |BN_BITS2|-bit chunks in - /// little-endian order. This stores the absolute value of the number. - external ffi.Pointer d; + external ffi.Pointer _IO_read_end; - /// width is the number of elements of |d| which are valid. This value is not - /// necessarily minimal; the most-significant words of |d| may be zero. - /// |width| determines a potentially loose upper-bound on the absolute value - /// of the |BIGNUM|. - /// - /// Functions taking |BIGNUM| inputs must compute the same answer for all - /// possible widths. |bn_minimal_width|, |bn_set_minimal_width|, and other - /// helpers may be used to recover the minimal width, provided it is not - /// secret. If it is secret, use a different algorithm. Functions may output - /// minimal or non-minimal |BIGNUM|s depending on secrecy requirements, but - /// those which cause widths to unboundedly grow beyond the minimal value - /// should be documented such. - /// - /// Note this is different from historical |BIGNUM| semantics. - @ffi.Int32() - external int width; + external ffi.Pointer _IO_read_base; - /// dmax is number of elements of |d| which are allocated. - @ffi.Int32() - external int dmax; + external ffi.Pointer _IO_write_base; - /// neg is one if the number if negative and zero otherwise. - @ffi.Int32() - external int neg; + external ffi.Pointer _IO_write_ptr; - /// flags is a bitmask of |BN_FLG_*| values - @ffi.Int32() - external int flags; -} + external ffi.Pointer _IO_write_end; -class BN_BLINDING extends ffi.Opaque {} + external ffi.Pointer _IO_buf_base; -class BN_CTX extends ffi.Opaque {} + external ffi.Pointer _IO_buf_end; -/// bn_gencb_st, or |BN_GENCB|, holds a callback function that is used by -/// generation functions that can take a very long time to complete. Use -/// |BN_GENCB_set| to initialise a |BN_GENCB| structure. -/// -/// The callback receives the address of that |BN_GENCB| structure as its last -/// argument and the user is free to put an arbitrary pointer in |arg|. The other -/// arguments are set as follows: -/// event=BN_GENCB_GENERATED, n=i: after generating the i'th possible prime -/// number. -/// event=BN_GENCB_PRIME_TEST, n=-1: when finished trial division primality -/// checks. -/// event=BN_GENCB_PRIME_TEST, n=i: when the i'th primality test has finished. -/// -/// The callback can return zero to abort the generation progress or one to -/// allow it to continue. -/// -/// When other code needs to call a BN generation function it will often take a -/// BN_GENCB argument and may call the function with other argument values. -class BN_GENCB extends ffi.Opaque {} + external ffi.Pointer _IO_save_base; -class BN_MONT_CTX extends ffi.Opaque {} + external ffi.Pointer _IO_backup_base; -class CBB extends ffi.Struct { - external ffi.Pointer base; + external ffi.Pointer _IO_save_end; - /// child points to a child CBB if a length-prefix is pending. - external ffi.Pointer child; + external ffi.Pointer<_IO_marker> _markers; - /// offset is the number of bytes from the start of |base->buf| to this |CBB|'s - /// pending length prefix. - @ffi.IntPtr() - external int offset; + external ffi.Pointer<_IO_FILE> _chain; - /// pending_len_len contains the number of bytes in this |CBB|'s pending - /// length-prefix, or zero if no length-prefix is pending. - @ffi.Uint8() - external int pending_len_len; + @ffi.Int() + external int _fileno; - @ffi.Int8() - external int pending_is_asn1; + @ffi.Int() + external int _flags2; - /// is_child is true iff this is a child |CBB| (as opposed to a top-level - /// |CBB|). Top-level objects are valid arguments for |CBB_finish|. - @ffi.Int8() - external int is_child; -} + @__off_t() + external int _old_offset; -/// CRYPTO ByteString -class CBS extends ffi.Struct { - external ffi.Pointer data; + @ffi.UnsignedShort() + external int _cur_column; - @ffi.IntPtr() - external int len; -} + @ffi.SignedChar() + external int _vtable_offset; -class CRYPTO_EX_DATA extends ffi.Struct { - external ffi.Pointer sk; -} + @ffi.Array.multi([1]) + external ffi.Array _shortbuf; -/// Low-level signing and verification. -/// -/// Low-level functions handle signatures as |ECDSA_SIG| structures which allow -/// the two values in an ECDSA signature to be handled separately. -class ECDSA_SIG extends ffi.Opaque {} + external ffi.Pointer<_IO_lock_t> _lock; -class EC_GROUP extends ffi.Opaque {} + @__off64_t() + external int _offset; -class EC_KEY extends ffi.Opaque {} + external ffi.Pointer<_IO_codecvt> _codecvt; -const int EC_PKEY_NO_PUBKEY = 2; + external ffi.Pointer<_IO_wide_data> _wide_data; -class EC_POINT extends ffi.Opaque {} + external ffi.Pointer<_IO_FILE> _freeres_list; -class ENGINE extends ffi.Opaque {} + external ffi.Pointer _freeres_buf; -const int ERR_LIB_HKDF = 31; + @ffi.Size() + external int __pad5; + + @ffi.Int() + external int _mode; -class EVP_AEAD extends ffi.Opaque {} + @ffi.Array.multi([20]) + external ffi.Array _unused2; +} -/// An EVP_AEAD_CTX represents an AEAD algorithm configured with a specific key -/// and message-independent IV. -class EVP_AEAD_CTX extends ffi.Opaque {} +class _IO_codecvt extends ffi.Opaque {} -class EVP_CIPHER extends ffi.Struct { - /// type contains a NID identifing the cipher. (e.g. NID_aes_128_gcm.) - @ffi.Int32() - external int nid; +typedef _IO_lock_t = ffi.Void; + +class _IO_marker extends ffi.Opaque {} - /// block_size contains the block size, in bytes, of the cipher, or 1 for a - /// stream cipher. - @ffi.Uint32() - external int block_size; +class _IO_wide_data extends ffi.Opaque {} - /// key_len contains the key size, in bytes, for the cipher. If the cipher - /// takes a variable key size then this contains the default size. - @ffi.Uint32() - external int key_len; +typedef __fd_mask = ffi.Long; - /// iv_len contains the IV size, in bytes, or zero if inapplicable. - @ffi.Uint32() - external int iv_len; +class __fsid_t extends ffi.Struct { + @ffi.Array.multi([2]) + external ffi.Array __val; +} + +class __locale_data extends ffi.Opaque {} - /// ctx_size contains the size, in bytes, of the per-key context for this - /// cipher. - @ffi.Uint32() - external int ctx_size; +class __locale_struct extends ffi.Struct { + @ffi.Array.multi([13]) + external ffi.Array> __locales; - /// flags contains the OR of a number of flags. See |EVP_CIPH_*|. - @ffi.Uint32() - external int flags; + external ffi.Pointer __ctype_b; - /// app_data is a pointer to opaque, user data. - external ffi.Pointer app_data; + external ffi.Pointer __ctype_tolower; - external ffi.Pointer> init; + external ffi.Pointer __ctype_toupper; - external ffi.Pointer> cipher; + @ffi.Array.multi([13]) + external ffi.Array> __names; +} - /// cleanup, if non-NULL, releases memory associated with the context. It is - /// called if |EVP_CTRL_INIT| succeeds. Note that |init| may not have been - /// called at this point. - external ffi.Pointer> cleanup; +class __mbstate_t extends ffi.Struct { + @ffi.Int() + external int __count; - external ffi.Pointer> ctrl; + external UnnamedUnion1 __value; } -class EVP_CIPHER_CTX extends ffi.Opaque {} +typedef __off64_t = ffi.Long; +typedef __off_t = ffi.Long; -class EVP_MD extends ffi.Opaque {} +class __once_flag extends ffi.Struct { + @ffi.Int() + external int __data; +} -class EVP_MD_CTX extends ffi.Struct { - /// digest is the underlying digest function, or NULL if not set. - external ffi.Pointer digest; +class __pthread_cond_s extends ffi.Struct { + @ffi.Array.multi([2]) + external ffi.Array __g_refs; - /// md_data points to a block of memory that contains the hash-specific - /// context. - external ffi.Pointer md_data; + @ffi.Array.multi([2]) + external ffi.Array __g_size; - /// pctx is an opaque (at this layer) pointer to additional context that - /// EVP_PKEY functions may store in this object. - external ffi.Pointer pctx; + @ffi.UnsignedInt() + external int __g1_orig_size; - /// pctx_ops, if not NULL, points to a vtable that contains functions to - /// manipulate |pctx|. - external ffi.Pointer pctx_ops; + @ffi.UnsignedInt() + external int __wrefs; + + @ffi.Array.multi([2]) + external ffi.Array __g_signals; } -/// Private structures. -class EVP_PKEY extends ffi.Opaque {} +class __pthread_internal_list extends ffi.Struct { + external ffi.Pointer<__pthread_internal_list> __prev; -class EVP_PKEY_ASN1_METHOD extends ffi.Opaque {} + external ffi.Pointer<__pthread_internal_list> __next; +} -class EVP_PKEY_CTX extends ffi.Opaque {} +class __pthread_internal_slist extends ffi.Struct { + external ffi.Pointer<__pthread_internal_slist> __next; +} -const int EVP_PKEY_EC = 408; +typedef __pthread_list_t = __pthread_internal_list; -const int EVP_PKEY_RSA = 6; +class __pthread_mutex_s extends ffi.Struct { + @ffi.Int() + external int __lock; -class FILE extends ffi.Opaque {} + @ffi.UnsignedInt() + external int __count; -const int HKDF_R_OUTPUT_TOO_LARGE = 100; + @ffi.Int() + external int __owner; -/// Private functions -class HMAC_CTX extends ffi.Struct { - external ffi.Pointer md; + @ffi.UnsignedInt() + external int __nusers; - external EVP_MD_CTX md_ctx; + @ffi.Int() + external int __kind; - external EVP_MD_CTX i_ctx; + @ffi.Short() + external int __spins; - external EVP_MD_CTX o_ctx; + @ffi.Short() + external int __elision; + + external __pthread_list_t __list; } -const int NID_X9_62_prime256v1 = 415; +class __pthread_rwlock_arch_t extends ffi.Struct { + @ffi.UnsignedInt() + external int __readers; -const int NID_secp384r1 = 715; + @ffi.UnsignedInt() + external int __writers; -const int NID_secp521r1 = 716; + @ffi.UnsignedInt() + external int __wrphase_futex; -class RSA extends ffi.Opaque {} + @ffi.UnsignedInt() + external int __writers_futex; -class RSA_METHOD extends ffi.Opaque {} + @ffi.UnsignedInt() + external int __pad3; -const int RSA_PKCS1_OAEP_PADDING = 4; + @ffi.UnsignedInt() + external int __pad4; -const int RSA_PKCS1_PADDING = 1; + @ffi.Int() + external int __cur_writer; -const int RSA_PKCS1_PSS_PADDING = 6; + @ffi.Int() + external int __shared; -class __sFILEX extends ffi.Opaque {} + @ffi.SignedChar() + external int __rwelision; -class __sbuf extends ffi.Struct { - external ffi.Pointer _base; + @ffi.Array.multi([7]) + external ffi.Array __pad1; + + @ffi.UnsignedLong() + external int __pad2; + + @ffi.UnsignedInt() + external int __flags; +} - @ffi.Int32() - external int _size; +class __sigset_t extends ffi.Struct { + @ffi.Array.multi([16]) + external ffi.Array __val; } -class _opaque_pthread_rwlock_t extends ffi.Opaque {} +typedef __suseconds_t = ffi.Long; +typedef __syscall_slong_t = ffi.Long; +typedef __time_t = ffi.Long; + +/// aes_key_st should be an opaque type, but EVP requires that the size be +/// known. +class aes_key_st extends ffi.Struct { + @ffi.Array.multi([60]) + external ffi.Array rd_key; + + @ffi.UnsignedInt() + external int rounds; +} + +class asn1_null_st extends ffi.Opaque {} + +class asn1_object_st extends ffi.Opaque {} + +class asn1_pctx_st extends ffi.Opaque {} + +class asn1_string_st extends ffi.Opaque {} + +class asn1_type_st extends ffi.Opaque {} + +class bignum_ctx extends ffi.Opaque {} + +class bignum_st extends ffi.Opaque {} + +class bio_method_st extends ffi.Opaque {} + +class bio_st extends ffi.Opaque {} + +class blake2b_state_st extends ffi.Opaque {} + +class bn_blinding_st extends ffi.Opaque {} + +class bn_gencb_st extends ffi.Opaque {} + +class bn_mont_ctx_st extends ffi.Opaque {} + +class buf_mem_st extends ffi.Opaque {} /// CRYPTO ByteBuilder. /// @@ -3384,26 +3462,238 @@ class cbb_buffer_st extends ffi.Struct { external ffi.Pointer buf; /// The number of valid bytes. - @ffi.IntPtr() + @ffi.Size() external int len; /// The size of buf. - @ffi.IntPtr() + @ffi.Size() external int cap; /// One iff |buf| is owned by this object. If not then |buf| /// cannot be resized. - @ffi.Int8() + @ffi.Char() external int can_resize; /// One iff there was an error writing to this CBB. All future /// operations will fail. - @ffi.Int8() + @ffi.Char() external int error; } +class cbb_st extends ffi.Struct { + external ffi.Pointer base; + + /// child points to a child CBB if a length-prefix is pending. + external ffi.Pointer child; + + /// offset is the number of bytes from the start of |base->buf| to this |CBB|'s + /// pending length prefix. + @ffi.Size() + external int offset; + + /// pending_len_len contains the number of bytes in this |CBB|'s pending + /// length-prefix, or zero if no length-prefix is pending. + @ffi.Uint8() + external int pending_len_len; + + @ffi.Char() + external int pending_is_asn1; + + /// is_child is true iff this is a child |CBB| (as opposed to a top-level + /// |CBB|). Top-level objects are valid arguments for |CBB_finish|. + @ffi.Char() + external int is_child; +} + +/// CRYPTO ByteString +class cbs_st extends ffi.Struct { + external ffi.Pointer data; + + @ffi.Size() + external int len; +} + +class cmac_ctx_st extends ffi.Opaque {} + +class conf_st extends ffi.Opaque {} + +class conf_value_st extends ffi.Opaque {} + +class crypto_buffer_pool_st extends ffi.Opaque {} + +class crypto_buffer_st extends ffi.Opaque {} + +class crypto_ex_data_st extends ffi.Struct { + external ffi.Pointer sk; +} + +/// On glibc, |pthread_rwlock_t| is hidden under feature flags, and we can't +/// ensure that we'll be able to get it from a public header. It's statically +/// asserted that this structure is large enough to contain a |pthread_rwlock_t| +/// by thread_pthread.c. +class crypto_mutex_st extends ffi.Union { + @ffi.Double() + external double alignment; + + @ffi.Array.multi([56]) + external ffi.Array padding; +} + +class ctr_drbg_state_st extends ffi.Opaque {} + +class dh_st extends ffi.Opaque {} + +class div_t extends ffi.Struct { + @ffi.Int() + external int quot; + + @ffi.Int() + external int rem; +} + +class drand48_data extends ffi.Struct { + @ffi.Array.multi([3]) + external ffi.Array __x; + + @ffi.Array.multi([3]) + external ffi.Array __old_x; + + @ffi.UnsignedShort() + external int __c; + + @ffi.UnsignedShort() + external int __init; + + @ffi.UnsignedLongLong() + external int __a; +} + +class dsa_st extends ffi.Opaque {} + +class ec_group_st extends ffi.Opaque {} + +class ec_key_st extends ffi.Opaque {} + +class ec_method_st extends ffi.Opaque {} + +class ec_point_st extends ffi.Opaque {} + +class ecdsa_method_st extends ffi.Opaque {} + +class ecdsa_sig_st extends ffi.Opaque {} + +class engine_st extends ffi.Opaque {} + +class env_md_ctx_st extends ffi.Opaque {} + +class env_md_st extends ffi.Opaque {} + +class evp_aead_ctx_st extends ffi.Opaque {} + +/// AEAD operations. +class evp_aead_ctx_st_state extends ffi.Union { + @ffi.Array.multi([580]) + external ffi.Array opaque; + + @ffi.Uint64() + external int alignment; +} + +class evp_aead_st extends ffi.Opaque {} + +class evp_cipher_ctx_st extends ffi.Opaque {} + +class evp_cipher_info_st extends ffi.Struct { + external ffi.Pointer cipher; + + @ffi.Array.multi([16]) + external ffi.Array iv; +} + +class evp_cipher_st extends ffi.Opaque {} + +class evp_encode_ctx_st extends ffi.Opaque {} + +class evp_hpke_aead_st extends ffi.Opaque {} + +class evp_hpke_ctx_st extends ffi.Opaque {} + +class evp_hpke_kdf_st extends ffi.Opaque {} + +class evp_hpke_kem_st extends ffi.Opaque {} + +class evp_hpke_key_st extends ffi.Opaque {} + class evp_md_pctx_ops extends ffi.Opaque {} +class evp_pkey_asn1_method_st extends ffi.Opaque {} + +class evp_pkey_ctx_st extends ffi.Opaque {} + +class evp_pkey_method_st extends ffi.Opaque {} + +class evp_pkey_st extends ffi.Opaque {} + +class fd_set extends ffi.Struct { + @ffi.Array.multi([16]) + external ffi.Array<__fd_mask> __fds_bits; +} + +class hmac_ctx_st extends ffi.Opaque {} + +class imaxdiv_t extends ffi.Struct { + @ffi.Long() + external int quot; + + @ffi.Long() + external int rem; +} + +class itimerspec extends ffi.Struct { + external timespec it_interval; + + external timespec it_value; +} + +class ldiv_t extends ffi.Struct { + @ffi.Long() + external int quot; + + @ffi.Long() + external int rem; +} + +class lldiv_t extends ffi.Struct { + @ffi.LongLong() + external int quot; + + @ffi.LongLong() + external int rem; +} + +class max_align_t extends ffi.Opaque {} + +class md4_state_st extends ffi.Opaque {} + +class md5_state_st extends ffi.Opaque {} + +/// openssl_method_common_st contains the common part of all method structures. +/// This must be the first member of all method structures. +class openssl_method_common_st extends ffi.Struct { + /// dummy – not used. + @ffi.Int() + external int references; + + @ffi.Char() + external int is_static; +} + +class ossl_init_settings_st extends ffi.Opaque {} + +class pkcs12_st extends ffi.Opaque {} + +class pkcs8_priv_key_info_st extends ffi.Opaque {} + /// point_conversion_form_t enumerates forms, as defined in X9.62 (ECDSA), for /// the encoding of a elliptic curve point (x,y) abstract class point_conversion_form_t { @@ -3424,1356 +3714,250 @@ abstract class point_conversion_form_t { static const int POINT_CONVERSION_HYBRID = 6; } -class stack_st_void extends ffi.Opaque {} +class private_key_st extends ffi.Opaque {} + +class pthread_attr_t extends ffi.Union { + @ffi.Array.multi([56]) + external ffi.Array __size; + + @ffi.Long() + external int __align; +} + +class pthread_barrier_t extends ffi.Union { + @ffi.Array.multi([32]) + external ffi.Array __size; + + @ffi.Long() + external int __align; +} + +class pthread_barrierattr_t extends ffi.Union { + @ffi.Array.multi([4]) + external ffi.Array __size; + + @ffi.Int() + external int __align; +} + +class pthread_cond_t extends ffi.Union { + external __pthread_cond_s __data; -typedef _c_BN_add = ffi.Int32 Function( - ffi.Pointer r, - ffi.Pointer a, - ffi.Pointer b, -); - -typedef _dart_BN_add = int Function( - ffi.Pointer r, - ffi.Pointer a, - ffi.Pointer b, -); - -typedef _c_BN_bin2bn = ffi.Pointer Function( - ffi.Pointer in_1, - ffi.IntPtr len, - ffi.Pointer ret, -); - -typedef _dart_BN_bin2bn = ffi.Pointer Function( - ffi.Pointer in_1, - int len, - ffi.Pointer ret, -); - -typedef _c_BN_bn2bin_padded = ffi.Int32 Function( - ffi.Pointer out, - ffi.IntPtr len, - ffi.Pointer in_1, -); - -typedef _dart_BN_bn2bin_padded = int Function( - ffi.Pointer out, - int len, - ffi.Pointer in_1, -); - -typedef _c_BN_cmp = ffi.Int32 Function( - ffi.Pointer a, - ffi.Pointer b, -); - -typedef _dart_BN_cmp = int Function( - ffi.Pointer a, - ffi.Pointer b, -); - -typedef _c_BN_free = ffi.Void Function( - ffi.Pointer bn, -); - -typedef _dart_BN_free = void Function( - ffi.Pointer bn, -); - -typedef _c_BN_lshift = ffi.Int32 Function( - ffi.Pointer r, - ffi.Pointer a, - ffi.Int32 n, -); - -typedef _dart_BN_lshift = int Function( - ffi.Pointer r, - ffi.Pointer a, - int n, -); - -typedef _c_BN_new = ffi.Pointer Function(); - -typedef _dart_BN_new = ffi.Pointer Function(); - -typedef _c_BN_num_bytes = ffi.Uint32 Function( - ffi.Pointer bn, -); - -typedef _dart_BN_num_bytes = int Function( - ffi.Pointer bn, -); - -typedef _c_BN_set_word = ffi.Int32 Function( - ffi.Pointer bn, - ffi.Uint64 value, -); - -typedef _dart_BN_set_word = int Function( - ffi.Pointer bn, - int value, -); - -typedef _c_BN_sub = ffi.Int32 Function( - ffi.Pointer r, - ffi.Pointer a, - ffi.Pointer b, -); - -typedef _dart_BN_sub = int Function( - ffi.Pointer r, - ffi.Pointer a, - ffi.Pointer b, -); - -typedef _c_BN_value_one = ffi.Pointer Function(); - -typedef _dart_BN_value_one = ffi.Pointer Function(); - -typedef _c_BORINGSSL_self_test = ffi.Int32 Function(); - -typedef _dart_BORINGSSL_self_test = int Function(); - -typedef _c_CBB_cleanup = ffi.Void Function( - ffi.Pointer cbb, -); - -typedef _dart_CBB_cleanup = void Function( - ffi.Pointer cbb, -); - -typedef _c_CBB_data = ffi.Pointer Function( - ffi.Pointer cbb, -); - -typedef _dart_CBB_data = ffi.Pointer Function( - ffi.Pointer cbb, -); - -typedef _c_CBB_flush = ffi.Int32 Function( - ffi.Pointer cbb, -); - -typedef _dart_CBB_flush = int Function( - ffi.Pointer cbb, -); - -typedef _c_CBB_init = ffi.Int32 Function( - ffi.Pointer cbb, - ffi.IntPtr initial_capacity, -); - -typedef _dart_CBB_init = int Function( - ffi.Pointer cbb, - int initial_capacity, -); - -typedef _c_CBB_len = ffi.IntPtr Function( - ffi.Pointer cbb, -); - -typedef _dart_CBB_len = int Function( - ffi.Pointer cbb, -); - -typedef _c_CBB_zero = ffi.Void Function( - ffi.Pointer cbb, -); - -typedef _dart_CBB_zero = void Function( - ffi.Pointer cbb, -); - -typedef _c_CBS_init = ffi.Void Function( - ffi.Pointer cbs, - ffi.Pointer data, - ffi.IntPtr len, -); - -typedef _dart_CBS_init = void Function( - ffi.Pointer cbs, - ffi.Pointer data, - int len, -); - -typedef _c_CRYPTO_memcmp = ffi.Int32 Function( - ffi.Pointer a, - ffi.Pointer b, - ffi.IntPtr len, -); - -typedef _dart_CRYPTO_memcmp = int Function( - ffi.Pointer a, - ffi.Pointer b, - int len, -); - -typedef _typedefC_5 = ffi.Pointer Function( - ffi.Pointer, - ffi.IntPtr, - ffi.Pointer, - ffi.Pointer, -); - -typedef _c_ECDH_compute_key = ffi.Int32 Function( - ffi.Pointer out, - ffi.IntPtr outlen, - ffi.Pointer pub_key, - ffi.Pointer priv_key, - ffi.Pointer> kdf, -); - -typedef _dart_ECDH_compute_key = int Function( - ffi.Pointer out, - int outlen, - ffi.Pointer pub_key, - ffi.Pointer priv_key, - ffi.Pointer> kdf, -); - -typedef _c_ECDSA_SIG_free = ffi.Void Function( - ffi.Pointer sig, -); - -typedef _dart_ECDSA_SIG_free = void Function( - ffi.Pointer sig, -); - -typedef _c_ECDSA_SIG_get0 = ffi.Void Function( - ffi.Pointer sig, - ffi.Pointer> out_r, - ffi.Pointer> out_s, -); - -typedef _dart_ECDSA_SIG_get0 = void Function( - ffi.Pointer sig, - ffi.Pointer> out_r, - ffi.Pointer> out_s, -); - -typedef _c_ECDSA_SIG_marshal = ffi.Int32 Function( - ffi.Pointer cbb, - ffi.Pointer sig, -); - -typedef _dart_ECDSA_SIG_marshal = int Function( - ffi.Pointer cbb, - ffi.Pointer sig, -); - -typedef _c_ECDSA_SIG_new = ffi.Pointer Function(); - -typedef _dart_ECDSA_SIG_new = ffi.Pointer Function(); - -typedef _c_ECDSA_SIG_parse = ffi.Pointer Function( - ffi.Pointer cbs, -); - -typedef _dart_ECDSA_SIG_parse = ffi.Pointer Function( - ffi.Pointer cbs, -); - -typedef _c_EC_GROUP_free = ffi.Void Function( - ffi.Pointer group, -); - -typedef _dart_EC_GROUP_free = void Function( - ffi.Pointer group, -); - -typedef _c_EC_GROUP_get0_order = ffi.Pointer Function( - ffi.Pointer group, -); - -typedef _dart_EC_GROUP_get0_order = ffi.Pointer Function( - ffi.Pointer group, -); - -typedef _c_EC_GROUP_get_curve_name = ffi.Int32 Function( - ffi.Pointer group, -); - -typedef _dart_EC_GROUP_get_curve_name = int Function( - ffi.Pointer group, -); - -typedef _c_EC_GROUP_get_degree = ffi.Uint32 Function( - ffi.Pointer group, -); - -typedef _dart_EC_GROUP_get_degree = int Function( - ffi.Pointer group, -); - -typedef _c_EC_GROUP_new_by_curve_name = ffi.Pointer Function( - ffi.Int32 nid, -); - -typedef _dart_EC_GROUP_new_by_curve_name = ffi.Pointer Function( - int nid, -); - -typedef _c_EC_KEY_check_key = ffi.Int32 Function( - ffi.Pointer key, -); - -typedef _dart_EC_KEY_check_key = int Function( - ffi.Pointer key, -); - -typedef _c_EC_KEY_free = ffi.Void Function( - ffi.Pointer key, -); - -typedef _dart_EC_KEY_free = void Function( - ffi.Pointer key, -); - -typedef _c_EC_KEY_generate_key = ffi.Int32 Function( - ffi.Pointer key, -); - -typedef _dart_EC_KEY_generate_key = int Function( - ffi.Pointer key, -); - -typedef _c_EC_KEY_get0_group = ffi.Pointer Function( - ffi.Pointer key, -); - -typedef _dart_EC_KEY_get0_group = ffi.Pointer Function( - ffi.Pointer key, -); - -typedef _c_EC_KEY_get0_private_key = ffi.Pointer Function( - ffi.Pointer key, -); - -typedef _dart_EC_KEY_get0_private_key = ffi.Pointer Function( - ffi.Pointer key, -); - -typedef _c_EC_KEY_get0_public_key = ffi.Pointer Function( - ffi.Pointer key, -); - -typedef _dart_EC_KEY_get0_public_key = ffi.Pointer Function( - ffi.Pointer key, -); - -typedef _c_EC_KEY_get_enc_flags = ffi.Uint32 Function( - ffi.Pointer key, -); - -typedef _dart_EC_KEY_get_enc_flags = int Function( - ffi.Pointer key, -); - -typedef _c_EC_KEY_new_by_curve_name = ffi.Pointer Function( - ffi.Int32 nid, -); - -typedef _dart_EC_KEY_new_by_curve_name = ffi.Pointer Function( - int nid, -); - -typedef _c_EC_KEY_set_enc_flags = ffi.Void Function( - ffi.Pointer key, - ffi.Uint32 flags, -); - -typedef _dart_EC_KEY_set_enc_flags = void Function( - ffi.Pointer key, - int flags, -); - -typedef _c_EC_KEY_set_private_key = ffi.Int32 Function( - ffi.Pointer key, - ffi.Pointer priv, -); - -typedef _dart_EC_KEY_set_private_key = int Function( - ffi.Pointer key, - ffi.Pointer priv, -); - -typedef _c_EC_KEY_set_public_key = ffi.Int32 Function( - ffi.Pointer key, - ffi.Pointer pub, -); - -typedef _dart_EC_KEY_set_public_key = int Function( - ffi.Pointer key, - ffi.Pointer pub, -); - -typedef _c_EC_KEY_set_public_key_affine_coordinates = ffi.Int32 Function( - ffi.Pointer key, - ffi.Pointer x, - ffi.Pointer y, -); - -typedef _dart_EC_KEY_set_public_key_affine_coordinates = int Function( - ffi.Pointer key, - ffi.Pointer x, - ffi.Pointer y, -); - -typedef _c_EC_POINT_free = ffi.Void Function( - ffi.Pointer point, -); - -typedef _dart_EC_POINT_free = void Function( - ffi.Pointer point, -); - -typedef _c_EC_POINT_get_affine_coordinates_GFp = ffi.Int32 Function( - ffi.Pointer group, - ffi.Pointer point, - ffi.Pointer x, - ffi.Pointer y, - ffi.Pointer ctx, -); - -typedef _dart_EC_POINT_get_affine_coordinates_GFp = int Function( - ffi.Pointer group, - ffi.Pointer point, - ffi.Pointer x, - ffi.Pointer y, - ffi.Pointer ctx, -); - -typedef _c_EC_POINT_new = ffi.Pointer Function( - ffi.Pointer group, -); - -typedef _dart_EC_POINT_new = ffi.Pointer Function( - ffi.Pointer group, -); - -typedef _c_EC_POINT_oct2point = ffi.Int32 Function( - ffi.Pointer group, - ffi.Pointer point, - ffi.Pointer buf, - ffi.IntPtr len, - ffi.Pointer ctx, -); - -typedef _dart_EC_POINT_oct2point = int Function( - ffi.Pointer group, - ffi.Pointer point, - ffi.Pointer buf, - int len, - ffi.Pointer ctx, -); - -typedef _c_EC_POINT_point2cbb = ffi.Int32 Function( - ffi.Pointer out, - ffi.Pointer group, - ffi.Pointer point, - ffi.Int32 form, - ffi.Pointer ctx, -); - -typedef _dart_EC_POINT_point2cbb = int Function( - ffi.Pointer out, - ffi.Pointer group, - ffi.Pointer point, - int form, - ffi.Pointer ctx, -); - -typedef _c_ERR_clear_error = ffi.Void Function(); - -typedef _dart_ERR_clear_error = void Function(); - -typedef _c_ERR_error_string_n = ffi.Pointer Function( - ffi.Uint32 packed_error, - ffi.Pointer buf, - ffi.IntPtr len, -); - -typedef _dart_ERR_error_string_n = ffi.Pointer Function( - int packed_error, - ffi.Pointer buf, - int len, -); - -typedef _c_ERR_get_error = ffi.Uint32 Function(); - -typedef _dart_ERR_get_error = int Function(); - -typedef _c_ERR_peek_error = ffi.Uint32 Function(); - -typedef _dart_ERR_peek_error = int Function(); - -typedef _c_EVP_AEAD_CTX_free = ffi.Void Function( - ffi.Pointer ctx, -); - -typedef _dart_EVP_AEAD_CTX_free = void Function( - ffi.Pointer ctx, -); - -typedef _c_EVP_AEAD_CTX_new = ffi.Pointer Function( - ffi.Pointer aead, - ffi.Pointer key, - ffi.IntPtr key_len, - ffi.IntPtr tag_len, -); - -typedef _dart_EVP_AEAD_CTX_new = ffi.Pointer Function( - ffi.Pointer aead, - ffi.Pointer key, - int key_len, - int tag_len, -); - -typedef _c_EVP_AEAD_CTX_open = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer out, - ffi.Pointer out_len, - ffi.IntPtr max_out_len, - ffi.Pointer nonce, - ffi.IntPtr nonce_len, - ffi.Pointer in_1, - ffi.IntPtr in_len, - ffi.Pointer ad, - ffi.IntPtr ad_len, -); - -typedef _dart_EVP_AEAD_CTX_open = int Function( - ffi.Pointer ctx, - ffi.Pointer out, - ffi.Pointer out_len, - int max_out_len, - ffi.Pointer nonce, - int nonce_len, - ffi.Pointer in_1, - int in_len, - ffi.Pointer ad, - int ad_len, -); - -typedef _c_EVP_AEAD_CTX_seal = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer out, - ffi.Pointer out_len, - ffi.IntPtr max_out_len, - ffi.Pointer nonce, - ffi.IntPtr nonce_len, - ffi.Pointer in_1, - ffi.IntPtr in_len, - ffi.Pointer ad, - ffi.IntPtr ad_len, -); - -typedef _dart_EVP_AEAD_CTX_seal = int Function( - ffi.Pointer ctx, - ffi.Pointer out, - ffi.Pointer out_len, - int max_out_len, - ffi.Pointer nonce, - int nonce_len, - ffi.Pointer in_1, - int in_len, - ffi.Pointer ad, - int ad_len, -); - -typedef _c_EVP_AEAD_key_length = ffi.IntPtr Function( - ffi.Pointer aead, -); - -typedef _dart_EVP_AEAD_key_length = int Function( - ffi.Pointer aead, -); - -typedef _c_EVP_AEAD_max_overhead = ffi.IntPtr Function( - ffi.Pointer aead, -); - -typedef _dart_EVP_AEAD_max_overhead = int Function( - ffi.Pointer aead, -); - -typedef _c_EVP_AEAD_max_tag_len = ffi.IntPtr Function( - ffi.Pointer aead, -); - -typedef _dart_EVP_AEAD_max_tag_len = int Function( - ffi.Pointer aead, -); - -typedef _c_EVP_AEAD_nonce_length = ffi.IntPtr Function( - ffi.Pointer aead, -); - -typedef _dart_EVP_AEAD_nonce_length = int Function( - ffi.Pointer aead, -); - -typedef _c_EVP_CIPHER_CTX_free = ffi.Void Function( - ffi.Pointer ctx, -); - -typedef _dart_EVP_CIPHER_CTX_free = void Function( - ffi.Pointer ctx, -); - -typedef _c_EVP_CIPHER_CTX_new = ffi.Pointer Function(); - -typedef _dart_EVP_CIPHER_CTX_new = ffi.Pointer Function(); - -typedef _c_EVP_CIPHER_block_size = ffi.Uint32 Function( - ffi.Pointer cipher, -); - -typedef _dart_EVP_CIPHER_block_size = int Function( - ffi.Pointer cipher, -); - -typedef _c_EVP_CIPHER_iv_length = ffi.Uint32 Function( - ffi.Pointer cipher, -); - -typedef _dart_EVP_CIPHER_iv_length = int Function( - ffi.Pointer cipher, -); - -typedef _c_EVP_CipherFinal_ex = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer out, - ffi.Pointer out_len, -); - -typedef _dart_EVP_CipherFinal_ex = int Function( - ffi.Pointer ctx, - ffi.Pointer out, - ffi.Pointer out_len, -); - -typedef _c_EVP_CipherInit_ex = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer cipher, - ffi.Pointer engine, - ffi.Pointer key, - ffi.Pointer iv, - ffi.Int32 enc, -); - -typedef _dart_EVP_CipherInit_ex = int Function( - ffi.Pointer ctx, - ffi.Pointer cipher, - ffi.Pointer engine, - ffi.Pointer key, - ffi.Pointer iv, - int enc, -); - -typedef _c_EVP_CipherUpdate = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer out, - ffi.Pointer out_len, - ffi.Pointer in_1, - ffi.Int32 in_len, -); - -typedef _dart_EVP_CipherUpdate = int Function( - ffi.Pointer ctx, - ffi.Pointer out, - ffi.Pointer out_len, - ffi.Pointer in_1, - int in_len, -); - -typedef _c_EVP_DigestFinal = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer md_out, - ffi.Pointer out_size, -); - -typedef _dart_EVP_DigestFinal = int Function( - ffi.Pointer ctx, - ffi.Pointer md_out, - ffi.Pointer out_size, -); - -typedef _c_EVP_DigestInit = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer type, -); - -typedef _dart_EVP_DigestInit = int Function( - ffi.Pointer ctx, - ffi.Pointer type, -); - -typedef _c_EVP_DigestSignFinal = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer out_sig, - ffi.Pointer out_sig_len, -); - -typedef _dart_EVP_DigestSignFinal = int Function( - ffi.Pointer ctx, - ffi.Pointer out_sig, - ffi.Pointer out_sig_len, -); - -typedef _c_EVP_DigestSignInit = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer> pctx, - ffi.Pointer type, - ffi.Pointer e, - ffi.Pointer pkey, -); - -typedef _dart_EVP_DigestSignInit = int Function( - ffi.Pointer ctx, - ffi.Pointer> pctx, - ffi.Pointer type, - ffi.Pointer e, - ffi.Pointer pkey, -); - -typedef _c_EVP_DigestSignUpdate = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer data, - ffi.IntPtr len, -); - -typedef _dart_EVP_DigestSignUpdate = int Function( - ffi.Pointer ctx, - ffi.Pointer data, - int len, -); - -typedef _c_EVP_DigestUpdate = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer data, - ffi.IntPtr len, -); - -typedef _dart_EVP_DigestUpdate = int Function( - ffi.Pointer ctx, - ffi.Pointer data, - int len, -); - -typedef _c_EVP_DigestVerifyFinal = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer sig, - ffi.IntPtr sig_len, -); - -typedef _dart_EVP_DigestVerifyFinal = int Function( - ffi.Pointer ctx, - ffi.Pointer sig, - int sig_len, -); - -typedef _c_EVP_DigestVerifyInit = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer> pctx, - ffi.Pointer type, - ffi.Pointer e, - ffi.Pointer pkey, -); - -typedef _dart_EVP_DigestVerifyInit = int Function( - ffi.Pointer ctx, - ffi.Pointer> pctx, - ffi.Pointer type, - ffi.Pointer e, - ffi.Pointer pkey, -); - -typedef _c_EVP_DigestVerifyUpdate = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer data, - ffi.IntPtr len, -); - -typedef _dart_EVP_DigestVerifyUpdate = int Function( - ffi.Pointer ctx, - ffi.Pointer data, - int len, -); - -typedef _c_EVP_MD_CTX_free = ffi.Void Function( - ffi.Pointer ctx, -); - -typedef _dart_EVP_MD_CTX_free = void Function( - ffi.Pointer ctx, -); - -typedef _c_EVP_MD_CTX_new = ffi.Pointer Function(); - -typedef _dart_EVP_MD_CTX_new = ffi.Pointer Function(); - -typedef _c_EVP_MD_CTX_size = ffi.IntPtr Function( - ffi.Pointer ctx, -); - -typedef _dart_EVP_MD_CTX_size = int Function( - ffi.Pointer ctx, -); - -typedef _c_EVP_MD_size = ffi.IntPtr Function( - ffi.Pointer md, -); - -typedef _dart_EVP_MD_size = int Function( - ffi.Pointer md, -); - -typedef _c_EVP_PKEY_CTX_free = ffi.Void Function( - ffi.Pointer ctx, -); - -typedef _dart_EVP_PKEY_CTX_free = void Function( - ffi.Pointer ctx, -); - -typedef _c_EVP_PKEY_CTX_new = ffi.Pointer Function( - ffi.Pointer pkey, - ffi.Pointer e, -); - -typedef _dart_EVP_PKEY_CTX_new = ffi.Pointer Function( - ffi.Pointer pkey, - ffi.Pointer e, -); - -typedef _c_EVP_PKEY_CTX_set0_rsa_oaep_label = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer label, - ffi.IntPtr label_len, -); - -typedef _dart_EVP_PKEY_CTX_set0_rsa_oaep_label = int Function( - ffi.Pointer ctx, - ffi.Pointer label, - int label_len, -); - -typedef _c_EVP_PKEY_CTX_set_rsa_mgf1_md = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer md, -); - -typedef _dart_EVP_PKEY_CTX_set_rsa_mgf1_md = int Function( - ffi.Pointer ctx, - ffi.Pointer md, -); - -typedef _c_EVP_PKEY_CTX_set_rsa_oaep_md = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer md, -); - -typedef _dart_EVP_PKEY_CTX_set_rsa_oaep_md = int Function( - ffi.Pointer ctx, - ffi.Pointer md, -); - -typedef _c_EVP_PKEY_CTX_set_rsa_padding = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Int32 padding, -); - -typedef _dart_EVP_PKEY_CTX_set_rsa_padding = int Function( - ffi.Pointer ctx, - int padding, -); - -typedef _c_EVP_PKEY_CTX_set_rsa_pss_saltlen = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Int32 salt_len, -); - -typedef _dart_EVP_PKEY_CTX_set_rsa_pss_saltlen = int Function( - ffi.Pointer ctx, - int salt_len, -); - -typedef _c_EVP_PKEY_decrypt = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer out, - ffi.Pointer out_len, - ffi.Pointer in_1, - ffi.IntPtr in_len, -); - -typedef _dart_EVP_PKEY_decrypt = int Function( - ffi.Pointer ctx, - ffi.Pointer out, - ffi.Pointer out_len, - ffi.Pointer in_1, - int in_len, -); - -typedef _c_EVP_PKEY_decrypt_init = ffi.Int32 Function( - ffi.Pointer ctx, -); - -typedef _dart_EVP_PKEY_decrypt_init = int Function( - ffi.Pointer ctx, -); - -typedef _c_EVP_PKEY_encrypt = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer out, - ffi.Pointer out_len, - ffi.Pointer in_1, - ffi.IntPtr in_len, -); - -typedef _dart_EVP_PKEY_encrypt = int Function( - ffi.Pointer ctx, - ffi.Pointer out, - ffi.Pointer out_len, - ffi.Pointer in_1, - int in_len, -); - -typedef _c_EVP_PKEY_encrypt_init = ffi.Int32 Function( - ffi.Pointer ctx, -); - -typedef _dart_EVP_PKEY_encrypt_init = int Function( - ffi.Pointer ctx, -); - -typedef Native_EVP_PKEY_free = ffi.Void Function( - ffi.Pointer pkey, -); - -typedef _dart_EVP_PKEY_free = void Function( - ffi.Pointer pkey, -); - -typedef _c_EVP_PKEY_get1_EC_KEY = ffi.Pointer Function( - ffi.Pointer pkey, -); - -typedef _dart_EVP_PKEY_get1_EC_KEY = ffi.Pointer Function( - ffi.Pointer pkey, -); - -typedef _c_EVP_PKEY_get1_RSA = ffi.Pointer Function( - ffi.Pointer pkey, -); - -typedef _dart_EVP_PKEY_get1_RSA = ffi.Pointer Function( - ffi.Pointer pkey, -); - -typedef _c_EVP_PKEY_id = ffi.Int32 Function( - ffi.Pointer pkey, -); + @ffi.Array.multi([48]) + external ffi.Array __size; -typedef _dart_EVP_PKEY_id = int Function( - ffi.Pointer pkey, -); + @ffi.LongLong() + external int __align; +} + +class pthread_condattr_t extends ffi.Union { + @ffi.Array.multi([4]) + external ffi.Array __size; + + @ffi.Int() + external int __align; +} + +class pthread_mutex_t extends ffi.Union { + external __pthread_mutex_s __data; + + @ffi.Array.multi([40]) + external ffi.Array __size; + + @ffi.Long() + external int __align; +} + +class pthread_mutexattr_t extends ffi.Union { + @ffi.Array.multi([4]) + external ffi.Array __size; + + @ffi.Int() + external int __align; +} + +class pthread_rwlock_t extends ffi.Union { + external __pthread_rwlock_arch_t __data; + + @ffi.Array.multi([56]) + external ffi.Array __size; + + @ffi.Long() + external int __align; +} + +class pthread_rwlockattr_t extends ffi.Union { + @ffi.Array.multi([8]) + external ffi.Array __size; + + @ffi.Long() + external int __align; +} + +class rand_meth_st extends ffi.Opaque {} + +class random_data extends ffi.Struct { + external ffi.Pointer fptr; + + external ffi.Pointer rptr; + + external ffi.Pointer state; + + @ffi.Int() + external int rand_type; + + @ffi.Int() + external int rand_deg; + + @ffi.Int() + external int rand_sep; -typedef _c_EVP_PKEY_new = ffi.Pointer Function(); + external ffi.Pointer end_ptr; +} + +class rc4_key_st extends ffi.Opaque {} -typedef _dart_EVP_PKEY_new = ffi.Pointer Function(); +class rsa_meth_st extends ffi.Opaque {} -typedef _c_EVP_PKEY_set1_EC_KEY = ffi.Int32 Function( - ffi.Pointer pkey, - ffi.Pointer key, -); +class rsa_pss_params_st extends ffi.Opaque {} -typedef _dart_EVP_PKEY_set1_EC_KEY = int Function( - ffi.Pointer pkey, - ffi.Pointer key, -); +class rsa_st extends ffi.Opaque {} -typedef _c_EVP_PKEY_set1_RSA = ffi.Int32 Function( - ffi.Pointer pkey, - ffi.Pointer key, -); +class sha256_state_st extends ffi.Opaque {} -typedef _dart_EVP_PKEY_set1_RSA = int Function( - ffi.Pointer pkey, - ffi.Pointer key, -); +class sha512_state_st extends ffi.Opaque {} -typedef _c_EVP_PKEY_set_type = ffi.Int32 Function( - ffi.Pointer pkey, - ffi.Int32 type, -); +class sha_state_st extends ffi.Opaque {} -typedef _dart_EVP_PKEY_set_type = int Function( - ffi.Pointer pkey, - int type, -); +class sigevent extends ffi.Opaque {} -typedef _c_EVP_aead_aes_128_gcm = ffi.Pointer Function(); +class spake2_ctx_st extends ffi.Opaque {} -typedef _dart_EVP_aead_aes_128_gcm = ffi.Pointer Function(); +class srtp_protection_profile_st extends ffi.Opaque {} -typedef _c_EVP_aead_aes_256_gcm = ffi.Pointer Function(); +class ssl_cipher_st extends ffi.Opaque {} -typedef _dart_EVP_aead_aes_256_gcm = ffi.Pointer Function(); +class ssl_ctx_st extends ffi.Opaque {} -typedef _c_EVP_aes_128_cbc = ffi.Pointer Function(); +class ssl_early_callback_ctx extends ffi.Opaque {} -typedef _dart_EVP_aes_128_cbc = ffi.Pointer Function(); +class ssl_ech_keys_st extends ffi.Opaque {} -typedef _c_EVP_aes_128_ctr = ffi.Pointer Function(); +class ssl_method_st extends ffi.Opaque {} -typedef _dart_EVP_aes_128_ctr = ffi.Pointer Function(); +class ssl_private_key_method_st extends ffi.Opaque {} -typedef _c_EVP_aes_256_cbc = ffi.Pointer Function(); +class ssl_quic_method_st extends ffi.Opaque {} -typedef _dart_EVP_aes_256_cbc = ffi.Pointer Function(); +class ssl_session_st extends ffi.Opaque {} -typedef _c_EVP_aes_256_ctr = ffi.Pointer Function(); +class ssl_st extends ffi.Opaque {} -typedef _dart_EVP_aes_256_ctr = ffi.Pointer Function(); +class ssl_ticket_aead_method_st extends ffi.Opaque {} -typedef _c_EVP_marshal_private_key = ffi.Int32 Function( - ffi.Pointer cbb, - ffi.Pointer key, -); +class st_ERR_FNS extends ffi.Opaque {} -typedef _dart_EVP_marshal_private_key = int Function( - ffi.Pointer cbb, - ffi.Pointer key, -); +/// stack_st contains an array of pointers. It is not designed to be used +/// directly, rather the wrapper macros should be used. +class stack_st extends ffi.Struct { + /// num contains the number of valid pointers in |data|. + @ffi.Size() + external int num; -typedef _c_EVP_marshal_public_key = ffi.Int32 Function( - ffi.Pointer cbb, - ffi.Pointer key, -); + external ffi.Pointer> data; -typedef _dart_EVP_marshal_public_key = int Function( - ffi.Pointer cbb, - ffi.Pointer key, -); + /// sorted is non-zero if the values pointed to by |data| are in ascending + /// order, based on |comp|. + @ffi.Int() + external int sorted; -typedef _c_EVP_parse_private_key = ffi.Pointer Function( - ffi.Pointer cbs, -); + /// num_alloc contains the number of pointers allocated in the buffer pointed + /// to by |data|, which may be larger than |num|. + @ffi.Size() + external int num_alloc; + + /// comp is an optional comparison function. + external OPENSSL_sk_cmp_func comp; +} + +class stack_st_OPENSSL_STRING extends ffi.Opaque {} + +class stack_st_void extends ffi.Opaque {} + +class timespec extends ffi.Struct { + @__time_t() + external int tv_sec; + + @__syscall_slong_t() + external int tv_nsec; +} + +class timeval extends ffi.Struct { + @__time_t() + external int tv_sec; + + @__suseconds_t() + external int tv_usec; +} + +class tm extends ffi.Struct { + @ffi.Int() + external int tm_sec; + + @ffi.Int() + external int tm_min; + + @ffi.Int() + external int tm_hour; + + @ffi.Int() + external int tm_mday; + + @ffi.Int() + external int tm_mon; + + @ffi.Int() + external int tm_year; + + @ffi.Int() + external int tm_wday; + + @ffi.Int() + external int tm_yday; + + @ffi.Int() + external int tm_isdst; + + @ffi.Long() + external int tm_gmtoff; + + external ffi.Pointer tm_zone; +} -typedef _dart_EVP_parse_private_key = ffi.Pointer Function( - ffi.Pointer cbs, -); +class trust_token_client_st extends ffi.Opaque {} -typedef _c_EVP_parse_public_key = ffi.Pointer Function( - ffi.Pointer cbs, -); +class trust_token_issuer_st extends ffi.Opaque {} -typedef _dart_EVP_parse_public_key = ffi.Pointer Function( - ffi.Pointer cbs, -); +class trust_token_method_st extends ffi.Opaque {} -typedef _c_EVP_sha1 = ffi.Pointer Function(); +class trust_token_st extends ffi.Opaque {} -typedef _dart_EVP_sha1 = ffi.Pointer Function(); +class v3_ext_ctx extends ffi.Opaque {} -typedef _c_EVP_sha256 = ffi.Pointer Function(); +class x509_attributes_st extends ffi.Opaque {} -typedef _dart_EVP_sha256 = ffi.Pointer Function(); +class x509_lookup_method_st extends ffi.Opaque {} -typedef _c_EVP_sha384 = ffi.Pointer Function(); +class x509_lookup_st extends ffi.Opaque {} -typedef _dart_EVP_sha384 = ffi.Pointer Function(); +class x509_object_st extends ffi.Opaque {} -typedef _c_EVP_sha512 = ffi.Pointer Function(); +class x509_revoked_st extends ffi.Opaque {} -typedef _dart_EVP_sha512 = ffi.Pointer Function(); +class x509_st extends ffi.Opaque {} -typedef _c_HKDF = ffi.Int32 Function( - ffi.Pointer out_key, - ffi.IntPtr out_len, - ffi.Pointer digest, - ffi.Pointer secret, - ffi.IntPtr secret_len, - ffi.Pointer salt, - ffi.IntPtr salt_len, - ffi.Pointer info, - ffi.IntPtr info_len, -); +class x509_store_ctx_st extends ffi.Opaque {} -typedef _dart_HKDF = int Function( - ffi.Pointer out_key, - int out_len, - ffi.Pointer digest, - ffi.Pointer secret, - int secret_len, - ffi.Pointer salt, - int salt_len, - ffi.Pointer info, - int info_len, -); +class x509_store_st extends ffi.Opaque {} -typedef _c_HMAC_CTX_free = ffi.Void Function( - ffi.Pointer ctx, -); - -typedef _dart_HMAC_CTX_free = void Function( - ffi.Pointer ctx, -); - -typedef _c_HMAC_CTX_new = ffi.Pointer Function(); - -typedef _dart_HMAC_CTX_new = ffi.Pointer Function(); - -typedef _c_HMAC_Final = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer out, - ffi.Pointer out_len, -); - -typedef _dart_HMAC_Final = int Function( - ffi.Pointer ctx, - ffi.Pointer out, - ffi.Pointer out_len, -); - -typedef _c_HMAC_Init_ex = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer key, - ffi.IntPtr key_len, - ffi.Pointer md, - ffi.Pointer impl, -); - -typedef _dart_HMAC_Init_ex = int Function( - ffi.Pointer ctx, - ffi.Pointer key, - int key_len, - ffi.Pointer md, - ffi.Pointer impl, -); - -typedef _c_HMAC_Update = ffi.Int32 Function( - ffi.Pointer ctx, - ffi.Pointer data, - ffi.IntPtr data_len, -); - -typedef _dart_HMAC_Update = int Function( - ffi.Pointer ctx, - ffi.Pointer data, - int data_len, -); - -typedef _c_HMAC_size = ffi.IntPtr Function( - ffi.Pointer ctx, -); - -typedef _dart_HMAC_size = int Function( - ffi.Pointer ctx, -); - -typedef _c_OPENSSL_free = ffi.Void Function( - ffi.Pointer ptr, -); - -typedef _dart_OPENSSL_free = void Function( - ffi.Pointer ptr, -); - -typedef _c_OPENSSL_malloc = ffi.Pointer Function( - ffi.IntPtr size, -); - -typedef _dart_OPENSSL_malloc = ffi.Pointer Function( - int size, -); - -typedef _c_OPENSSL_memdup = ffi.Pointer Function( - ffi.Pointer data, - ffi.IntPtr size, -); - -typedef _dart_OPENSSL_memdup = ffi.Pointer Function( - ffi.Pointer data, - int size, -); - -typedef _c_PKCS5_PBKDF2_HMAC = ffi.Int32 Function( - ffi.Pointer password, - ffi.IntPtr password_len, - ffi.Pointer salt, - ffi.IntPtr salt_len, - ffi.Uint32 iterations, - ffi.Pointer digest, - ffi.IntPtr key_len, - ffi.Pointer out_key, -); - -typedef _dart_PKCS5_PBKDF2_HMAC = int Function( - ffi.Pointer password, - int password_len, - ffi.Pointer salt, - int salt_len, - int iterations, - ffi.Pointer digest, - int key_len, - ffi.Pointer out_key, -); - -typedef _c_RAND_bytes = ffi.Int32 Function( - ffi.Pointer buf, - ffi.IntPtr len, -); - -typedef _dart_RAND_bytes = int Function( - ffi.Pointer buf, - int len, -); - -typedef _c_RSAPublicKey_dup = ffi.Pointer Function( - ffi.Pointer rsa, -); - -typedef _dart_RSAPublicKey_dup = ffi.Pointer Function( - ffi.Pointer rsa, -); - -typedef _c_RSA_check_key = ffi.Int32 Function( - ffi.Pointer rsa, -); - -typedef _dart_RSA_check_key = int Function( - ffi.Pointer rsa, -); - -typedef _c_RSA_free = ffi.Void Function( - ffi.Pointer rsa, -); - -typedef _dart_RSA_free = void Function( - ffi.Pointer rsa, -); - -typedef _c_RSA_generate_key_ex = ffi.Int32 Function( - ffi.Pointer rsa, - ffi.Int32 bits, - ffi.Pointer e, - ffi.Pointer cb, -); - -typedef _dart_RSA_generate_key_ex = int Function( - ffi.Pointer rsa, - int bits, - ffi.Pointer e, - ffi.Pointer cb, -); - -typedef _c_RSA_get0_crt_params = ffi.Void Function( - ffi.Pointer rsa, - ffi.Pointer> out_dmp1, - ffi.Pointer> out_dmq1, - ffi.Pointer> out_iqmp, -); - -typedef _dart_RSA_get0_crt_params = void Function( - ffi.Pointer rsa, - ffi.Pointer> out_dmp1, - ffi.Pointer> out_dmq1, - ffi.Pointer> out_iqmp, -); - -typedef _c_RSA_get0_factors = ffi.Void Function( - ffi.Pointer rsa, - ffi.Pointer> out_p, - ffi.Pointer> out_q, -); - -typedef _dart_RSA_get0_factors = void Function( - ffi.Pointer rsa, - ffi.Pointer> out_p, - ffi.Pointer> out_q, -); - -typedef _c_RSA_get0_key = ffi.Void Function( - ffi.Pointer rsa, - ffi.Pointer> out_n, - ffi.Pointer> out_e, - ffi.Pointer> out_d, -); - -typedef _dart_RSA_get0_key = void Function( - ffi.Pointer rsa, - ffi.Pointer> out_n, - ffi.Pointer> out_e, - ffi.Pointer> out_d, -); - -typedef _c_RSA_new = ffi.Pointer Function(); - -typedef _dart_RSA_new = ffi.Pointer Function(); - -typedef _c_RSA_set0_crt_params = ffi.Int32 Function( - ffi.Pointer rsa, - ffi.Pointer dmp1, - ffi.Pointer dmq1, - ffi.Pointer iqmp, -); - -typedef _dart_RSA_set0_crt_params = int Function( - ffi.Pointer rsa, - ffi.Pointer dmp1, - ffi.Pointer dmq1, - ffi.Pointer iqmp, -); - -typedef _c_RSA_set0_factors = ffi.Int32 Function( - ffi.Pointer rsa, - ffi.Pointer p, - ffi.Pointer q, -); - -typedef _dart_RSA_set0_factors = int Function( - ffi.Pointer rsa, - ffi.Pointer p, - ffi.Pointer q, -); - -typedef _c_RSA_set0_key = ffi.Int32 Function( - ffi.Pointer rsa, - ffi.Pointer n, - ffi.Pointer e, - ffi.Pointer d, -); - -typedef _dart_RSA_set0_key = int Function( - ffi.Pointer rsa, - ffi.Pointer n, - ffi.Pointer e, - ffi.Pointer d, -); - -typedef _typedefC_1 = ffi.Int32 Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Int32, -); - -typedef _typedefC_2 = ffi.Int32 Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.IntPtr, -); - -typedef _typedefC_3 = ffi.Void Function( - ffi.Pointer, -); - -typedef _typedefC_4 = ffi.Int32 Function( - ffi.Pointer, - ffi.Int32, - ffi.Int32, - ffi.Pointer, -); +class x509_trust_st extends ffi.Opaque {} diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index 69582609..4366cc7a 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -4,16 +4,6 @@ project(${PROJECT_NAME} LANGUAGES C CXX) enable_language(ASM) -# Set as required by ../third_party/dart-sdk/sources.cmake included below -set(DARTSDK_ROOT ../third_party/dart-sdk/) - -# Import sources generated by tool/update-dart-sdk.py -# This provides variables, and requires DARTSDK_ROOT to be set. -# - dart_dl_sources -include( - ../third_party/dart-sdk/sources.cmake -) - # Set as required by android-sources.cmake included below set(BORINGSSL_ROOT ../third_party/boringssl/) @@ -80,9 +70,7 @@ add_library( # Source files ../src/webcrypto.c - ../src/webcrypto_dart_dl.c ../src/symbols.generated.c - ${dart_dl_sources} ${crypto_sources} ${crypto_sources_${PLATFORM}_${ARCH}} ) @@ -92,7 +80,6 @@ target_include_directories( PRIVATE - ../third_party/dart-sdk/src/runtime/ ../third_party/boringssl/src/include/ ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b2a61dba..b66cb686 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,16 +26,6 @@ project(webcrypto) enable_language(ASM) -# Set as required by ../third_party/dart-sdk/sources.cmake included below -set(DARTSDK_ROOT ../third_party/dart-sdk/) - -# Import sources generated by tool/update-dart-sdk.py -# This provides variables, and requires DARTSDK_ROOT to be set. -# - dart_dl_sources -include( - ../third_party/dart-sdk/sources.cmake -) - # Set as required by ../third_party/boringssl/sources.cmake included below set(BORINGSSL_ROOT ../third_party/boringssl/) @@ -114,9 +104,7 @@ add_library( # Source files ../src/webcrypto.c - ../src/webcrypto_dart_dl.c ../src/symbols.generated.c - ${dart_dl_sources} ${crypto_sources} ${crypto_sources_${PLATFORM}_${ARCH}} ) @@ -126,7 +114,6 @@ target_include_directories( PRIVATE - ../third_party/dart-sdk/src/runtime/ ../third_party/boringssl/src/include/ ) diff --git a/src/symbols.generated.c b/src/symbols.generated.c index 43fcef67..a2d1d6dd 100644 --- a/src/symbols.generated.c +++ b/src/symbols.generated.c @@ -22,8 +22,6 @@ #include "symbols.h" void* _webcrypto_symbol_table[] = { - (void*)&webcrypto_dart_dl_initialize, - (void*)&webcrypto_dart_dl_attach_finalizer, (void*)&BN_bin2bn, (void*)&BN_bn2bin_padded, (void*)&BN_free, diff --git a/src/symbols.h b/src/symbols.h index 685c3b48..e15d718b 100644 --- a/src/symbols.h +++ b/src/symbols.h @@ -19,8 +19,6 @@ #include -#include "webcrypto_dart_dl.h" - // BoringSSL headers #include #include diff --git a/src/symbols.yaml b/src/symbols.yaml index 26ae213a..99a138c8 100644 --- a/src/symbols.yaml +++ b/src/symbols.yaml @@ -45,8 +45,6 @@ # # Keep consistent with lib/src/third_party/boringssl/ffigen.yaml and # lib/src/boringssl/bindings/ffigen.yaml. -- webcrypto_dart_dl_initialize -- webcrypto_dart_dl_attach_finalizer - BN_bin2bn - BN_bn2bin_padded - BN_free diff --git a/src/webcrypto.c b/src/webcrypto.c index 69e68935..96d1726f 100644 --- a/src/webcrypto.c +++ b/src/webcrypto.c @@ -15,16 +15,10 @@ */ #include -#include #include "symbols.h" +#include "webcrypto.h" -// Macro for annotating all functions to be exported -#define WEBCRYPTO_EXPORT \ - __attribute__((visibility("default"))) __attribute__((used)) - -// Function to lookup BoringSSL symbols based on index in the Sym enum. -// See src/symbols.yaml for details. WEBCRYPTO_EXPORT void* webcrypto_lookup_symbol(int32_t index) { return _webcrypto_symbol_table[index]; } diff --git a/ios/third_party/dart-sdk/src/runtime/include/dart_api_dl.c b/src/webcrypto.h similarity index 57% rename from ios/third_party/dart-sdk/src/runtime/include/dart_api_dl.c rename to src/webcrypto.h index 6dec5f25..bb1e7969 100644 --- a/ios/third_party/dart-sdk/src/runtime/include/dart_api_dl.c +++ b/src/webcrypto.h @@ -1,5 +1,5 @@ /* - * Copyright 2020 Google LLC + * Copyright 2022 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,12 @@ * limitations under the License. */ -// **GENERATED FILE DO NOT MODIFY** -// -// This file is generated using: -// `tool/update-dart-sdk.py` +#include -#include "../../../../../../third_party/dart-sdk/src/runtime/include/dart_api_dl.c" +// Macro for annotating all functions to be exported +#define WEBCRYPTO_EXPORT \ + __attribute__((visibility("default"))) __attribute__((used)) + +// Function to lookup BoringSSL symbols based on index in the Sym enum. +// See src/symbols.yaml for details. +WEBCRYPTO_EXPORT void* webcrypto_lookup_symbol(int32_t index); diff --git a/src/webcrypto_dart_dl.c b/src/webcrypto_dart_dl.c deleted file mode 100644 index 63b7953d..00000000 --- a/src/webcrypto_dart_dl.c +++ /dev/null @@ -1,72 +0,0 @@ -#include "webcrypto_dart_dl.h" - -#include - -// See webcrypto_dart_dl.h -int webcrypto_dart_dl_initialize(void* initialize_api_dl_data) { - if (Dart_InitializeApiDL(initialize_api_dl_data) != 0) { - return -1; - } - // Check symbols used are present - if (Dart_NewFinalizableHandle_DL == NULL) { - return -1; - } - return 1; -} - -// peer attached -typedef struct _finalizable_pointer { - void* pointer; - webcrypto_finalizer_t finalizer; -} _finalizable_pointer; - -// Callback from Dart_NewFinalizableHandle_DL when we have attached a finalizer -// to some Dart object. -void _webcrypto_finalizer_callback(void* isolate_callback_data, void* peer) { - _finalizable_pointer* p = (_finalizable_pointer*)peer; - - // If pointer or finalizer is NULL, we've already deallocated, we can assert - // that this doesn't happen. - assert(p->pointer != NULL); - assert(p->finalizer != NULL); - if (p->pointer == NULL || p->finalizer == NULL) { - // Abort if this happens in production where we have no asserts. - return; - } - - // Call the finalizer - p->finalizer(p->pointer); - - // Ensure that assertions will trigger upon double deallocation. - p->pointer = NULL; - p->finalizer = NULL; - - // Free the peer - OPENSSL_free(p); -} - -// See webcrypto_dart_dl.h -int webcrypto_dart_dl_attach_finalizer(Dart_Handle object, - void* pointer, - webcrypto_finalizer_t finalizer, - intptr_t external_allocation_size) { - // Create a _finalizable_pointer to be attached as peer. - _finalizable_pointer* peer = OPENSSL_malloc(sizeof(_finalizable_pointer)); - peer->finalizer = finalizer; - peer->pointer = pointer; - - // Attaced peer and _webcrypto_finalizer_callback - Dart_FinalizableHandle handle; - // NOTE: we have check the availability of Dart_NewFinalizableHandle_DL in - // webcrypto_dart_dl_initialize. - handle = Dart_NewFinalizableHandle_DL(object, (void*)peer, - external_allocation_size, - &_webcrypto_finalizer_callback); - - // Check if the operation was successful - if (handle == NULL) { - OPENSSL_free(peer); - return -1; - } - return 1; -} diff --git a/src/webcrypto_dart_dl.h b/src/webcrypto_dart_dl.h deleted file mode 100644 index a6ac4c7a..00000000 --- a/src/webcrypto_dart_dl.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FINALIZER_H -#define FINALIZER_H - -#include -#include "include/dart_api_dl.h" - -// Initialize Dart API with dynamic linking. -// -// Must be called with `NativeApi.initializeApiDLData` from `dart:ffi`, before -// using other functions. -// -// Returns 1 on success. -int webcrypto_dart_dl_initialize(void* initialize_api_dl_data); - -// Function pointer for de-allocation of a pointer, when attaching a finalizer -// using webcrypto_attach_finalizer. -typedef void (*webcrypto_finalizer_t)(void*); - -// Attach a finalizer for pointer to object, such that `finalizer(pointer)` will -// be called when `object` is collected by the Dart garbage collector. -// -// The external_allocation_size is used by the Dart garbage collector as a hint -// about the size of the external allocation. -// -// Returns 1 on success. -int webcrypto_dart_dl_attach_finalizer(Dart_Handle object, - void* pointer, - webcrypto_finalizer_t finalizer, - intptr_t external_allocation_size); - -#endif // FINALIZER_H diff --git a/third_party/dart-sdk/LICENSE b/third_party/dart-sdk/LICENSE deleted file mode 100644 index a3889d5e..00000000 --- a/third_party/dart-sdk/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -Copyright 2012, the Dart project authors. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - * Neither the name of Google Inc. nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/third_party/dart-sdk/README.md b/third_party/dart-sdk/README.md deleted file mode 100644 index 0a6698c0..00000000 --- a/third_party/dart-sdk/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Dynamic linking Dart SDK in `package:webcrypto` - -**GENERATED FOLDER DO NOT MODIFY** - -This folder contains sources from the Dart SDK allowing `package:webcrypto` to -dynamically link against native Dart APIs. Contents of this folder is generated -using `tool/update-dart-sdk.py` which clones the Dart SDK and copies over the -files required for dynamic linking. - -Files in this folder are subject to `LICENSE` from the Dart SDK project. - -Notice that this folder does NOT contain all source files from the Dart SDK -project. Only source files required to build `package:webcrypto` have been -retained. This is essential to minimize package size. For additional source -files and information about the Dart SDK refer to the [Dart SDK repository][1]. - -[1]: https://github.com/dart-lang/sdk diff --git a/third_party/dart-sdk/src/LICENSE b/third_party/dart-sdk/src/LICENSE deleted file mode 100644 index a3889d5e..00000000 --- a/third_party/dart-sdk/src/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -Copyright 2012, the Dart project authors. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - * Neither the name of Google Inc. nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/third_party/dart-sdk/src/README.dart-sdk b/third_party/dart-sdk/src/README.dart-sdk deleted file mode 100644 index 0123d054..00000000 --- a/third_party/dart-sdk/src/README.dart-sdk +++ /dev/null @@ -1,24 +0,0 @@ -The Dart SDK is a set of tools and libraries for the Dart programming language. - -You can find information about Dart online at dartlang.org. - -Here's a brief guide to what's in here: - -bin/ Binaries/scripts to compile, run, and manage Dart applications. - dart Dart virtual machine - dart2js Dart-to-JavaScript compiler - dart2native Dart-to-native AOT compiler - dartanalyzer Dart static analyzer - dartdoc Dart documentation generator - pub Pub, the Dart package manager - dartfmt Dart code formatter - -lib/ Libraries that are shipped with the Dart runtime. More - information is available at api.dartlang.org. - -packages/ Additional packages that are shipped outside of the Dart - runtime. More information is available at api.dartlang.org. - -version The version number of the SDK (ex. 1.5.1). - -revision The Subversion revision of the SDK build (ex. 37107). diff --git a/third_party/dart-sdk/src/README.md b/third_party/dart-sdk/src/README.md deleted file mode 100644 index 924e4c35..00000000 --- a/third_party/dart-sdk/src/README.md +++ /dev/null @@ -1,66 +0,0 @@ -# Dart - -## A client-optimized language for fast apps on any platform - -Dart is: - - * **Optimized for UI**: - Develop with a programming language specialized around the needs of user interface creation - - * **Productive**: - Make changes iteratively: use hot reload to see the result instantly in your running app - - * **Fast on all platforms**: - Compile to ARM & x64 machine code for mobile, desktop, and backend. Or compile to JavaScript for the web - -Dart's flexible compiler technology lets you run Dart code in different ways, -depending on your target platform and goals: - - * **Dart Native**: For programs targeting devices (mobile, desktop, server, and more), - Dart Native includes both a Dart VM with JIT (just-in-time) compilation and an - AOT (ahead-of-time) compiler for producing machine code. - - * **Dart Web**: For programs targeting the web, Dart Web includes both a development time - compiler (dartdevc) and a production time compiler (dart2js). - -![Dart platforms illustration](docs/assets/Dart-platforms.svg) - -## License & patents - -Dart is free and open source. - -See [LICENSE][license] and [PATENT_GRANT][patent_grant]. - -## Using Dart - -Visit [dart.dev][website] to learn more about the -[language][lang], [tools][tools], -[getting started][codelab], and more. - -Browse [pub.dev][pubsite] for more packages and libraries contributed -by the community and the Dart team. - -## Building Dart - -If you want to build Dart yourself, here is a guide to -[getting the source, preparing your machine to build the SDK, and -building](https://github.com/dart-lang/sdk/wiki/Building). - -There are more documents on our [wiki](https://github.com/dart-lang/sdk/wiki). - -## Contributing to Dart - -The easiest way to contribute to Dart is to [file issues][dartbug]. - -You can also contribute patches, as described in [Contributing][contrib]. - -[website]: https://dart.dev -[license]: https://github.com/dart-lang/sdk/blob/master/LICENSE -[repo]: https://github.com/dart-lang/sdk -[lang]: https://dart.dev/guides/language/language-tour -[tools]: https://dart.dev/tools -[codelab]: https://dart.dev/codelabs -[dartbug]: http://dartbug.com -[contrib]: https://github.com/dart-lang/sdk/blob/master/CONTRIBUTING.md -[pubsite]: https://pub.dev -[patent_grant]: https://github.com/dart-lang/sdk/blob/master/PATENT_GRANT diff --git a/third_party/dart-sdk/src/runtime/include/bin/dart_io_api.h b/third_party/dart-sdk/src/runtime/include/bin/dart_io_api.h deleted file mode 100644 index e194f7ae..00000000 --- a/third_party/dart-sdk/src/runtime/include/bin/dart_io_api.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -#ifndef RUNTIME_INCLUDE_BIN_DART_IO_API_H_ -#define RUNTIME_INCLUDE_BIN_DART_IO_API_H_ - -#include "dart_tools_api.h" - -namespace dart { -namespace bin { - -// Bootstraps 'dart:io'. -void BootstrapDartIo(); - -// Cleans up 'dart:io'. -void CleanupDartIo(); - -// Lets dart:io know where the system temporary directory is located. -// Currently only wired up on Android. -void SetSystemTempDirectory(const char* system_temp); - -// Tells the system whether to capture Stdout events. -void SetCaptureStdout(bool value); - -// Tells the system whether to capture Stderr events. -void SetCaptureStderr(bool value); - -// Should Stdout events be captured? -bool ShouldCaptureStdout(); - -// Should Stderr events be captured? -bool ShouldCaptureStderr(); - -// Set the executable name used by Platform.executable. -void SetExecutableName(const char* executable_name); - -// Set the arguments used by Platform.executableArguments. -void SetExecutableArguments(int script_index, char** argv); - -// Set dart:io implementation specific fields of Dart_EmbedderInformation. -void GetIOEmbedderInformation(Dart_EmbedderInformation* info); - -// Generates 'length' random bytes into 'buffer'. Returns true on success -// and false on failure. This is appropriate to assign to -// Dart_InitializeParams.entropy_source. -bool GetEntropy(uint8_t* buffer, intptr_t length); - -// Performs a lookup of the I/O Dart_NativeFunction with a specified 'name' and -// 'argument_count'. Returns NULL if no I/O native function with a matching -// name and parameter count is found. -Dart_NativeFunction LookupIONative(Dart_Handle name, - int argument_count, - bool* auto_setup_scope); - -// Returns the symbol for I/O native function 'nf'. Returns NULL if 'nf' is not -// a valid I/O native function. -const uint8_t* LookupIONativeSymbol(Dart_NativeFunction nf); - -} // namespace bin -} // namespace dart - -#endif // RUNTIME_INCLUDE_BIN_DART_IO_API_H_ diff --git a/third_party/dart-sdk/src/runtime/include/dart_api.h b/third_party/dart-sdk/src/runtime/include/dart_api.h deleted file mode 100644 index db0e630d..00000000 --- a/third_party/dart-sdk/src/runtime/include/dart_api.h +++ /dev/null @@ -1,3888 +0,0 @@ -/* - * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file - * for details. All rights reserved. Use of this source code is governed by a - * BSD-style license that can be found in the LICENSE file. - */ - -#ifndef RUNTIME_INCLUDE_DART_API_H_ -#define RUNTIME_INCLUDE_DART_API_H_ - -/** \mainpage Dart Embedding API Reference - * - * This reference describes the Dart Embedding API, which is used to embed the - * Dart Virtual Machine within C/C++ applications. - * - * This reference is generated from the header include/dart_api.h. - */ - -/* __STDC_FORMAT_MACROS has to be defined before including to - * enable platform independent printf format specifiers. */ -#ifndef __STDC_FORMAT_MACROS -#define __STDC_FORMAT_MACROS -#endif - -#include -#include -#include - -#ifdef __cplusplus -#define DART_EXTERN_C extern "C" -#else -#define DART_EXTERN_C -#endif - -#if defined(__CYGWIN__) -#error Tool chain and platform not supported. -#elif defined(_WIN32) -#if defined(DART_SHARED_LIB) -#define DART_EXPORT DART_EXTERN_C __declspec(dllexport) -#else -#define DART_EXPORT DART_EXTERN_C -#endif -#else -#if __GNUC__ >= 4 -#if defined(DART_SHARED_LIB) -#define DART_EXPORT \ - DART_EXTERN_C __attribute__((visibility("default"))) __attribute((used)) -#else -#define DART_EXPORT DART_EXTERN_C -#endif -#else -#error Tool chain not supported. -#endif -#endif - -#if __GNUC__ -#define DART_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -#elif _MSC_VER -#define DART_WARN_UNUSED_RESULT _Check_return_ -#else -#define DART_WARN_UNUSED_RESULT -#endif - -/* - * ======= - * Handles - * ======= - */ - -/** - * An isolate is the unit of concurrency in Dart. Each isolate has - * its own memory and thread of control. No state is shared between - * isolates. Instead, isolates communicate by message passing. - * - * Each thread keeps track of its current isolate, which is the - * isolate which is ready to execute on the current thread. The - * current isolate may be NULL, in which case no isolate is ready to - * execute. Most of the Dart apis require there to be a current - * isolate in order to function without error. The current isolate is - * set by any call to Dart_CreateIsolateGroup or Dart_EnterIsolate. - */ -typedef struct _Dart_Isolate* Dart_Isolate; -typedef struct _Dart_IsolateGroup* Dart_IsolateGroup; - -/** - * An object reference managed by the Dart VM garbage collector. - * - * Because the garbage collector may move objects, it is unsafe to - * refer to objects directly. Instead, we refer to objects through - * handles, which are known to the garbage collector and updated - * automatically when the object is moved. Handles should be passed - * by value (except in cases like out-parameters) and should never be - * allocated on the heap. - * - * Most functions in the Dart Embedding API return a handle. When a - * function completes normally, this will be a valid handle to an - * object in the Dart VM heap. This handle may represent the result of - * the operation or it may be a special valid handle used merely to - * indicate successful completion. Note that a valid handle may in - * some cases refer to the null object. - * - * --- Error handles --- - * - * When a function encounters a problem that prevents it from - * completing normally, it returns an error handle (See Dart_IsError). - * An error handle has an associated error message that gives more - * details about the problem (See Dart_GetError). - * - * There are four kinds of error handles that can be produced, - * depending on what goes wrong: - * - * - Api error handles are produced when an api function is misused. - * This happens when a Dart embedding api function is called with - * invalid arguments or in an invalid context. - * - * - Unhandled exception error handles are produced when, during the - * execution of Dart code, an exception is thrown but not caught. - * Prototypically this would occur during a call to Dart_Invoke, but - * it can occur in any function which triggers the execution of Dart - * code (for example, Dart_ToString). - * - * An unhandled exception error provides access to an exception and - * stacktrace via the functions Dart_ErrorGetException and - * Dart_ErrorGetStackTrace. - * - * - Compilation error handles are produced when, during the execution - * of Dart code, a compile-time error occurs. As above, this can - * occur in any function which triggers the execution of Dart code. - * - * - Fatal error handles are produced when the system wants to shut - * down the current isolate. - * - * --- Propagating errors --- - * - * When an error handle is returned from the top level invocation of - * Dart code in a program, the embedder must handle the error as they - * see fit. Often, the embedder will print the error message produced - * by Dart_Error and exit the program. - * - * When an error is returned while in the body of a native function, - * it can be propagated up the call stack by calling - * Dart_PropagateError, Dart_SetReturnValue, or Dart_ThrowException. - * Errors should be propagated unless there is a specific reason not - * to. If an error is not propagated then it is ignored. For - * example, if an unhandled exception error is ignored, that - * effectively "catches" the unhandled exception. Fatal errors must - * always be propagated. - * - * When an error is propagated, any current scopes created by - * Dart_EnterScope will be exited. - * - * Using Dart_SetReturnValue to propagate an exception is somewhat - * more convenient than using Dart_PropagateError, and should be - * preferred for reasons discussed below. - * - * Dart_PropagateError and Dart_ThrowException do not return. Instead - * they transfer control non-locally using a setjmp-like mechanism. - * This can be inconvenient if you have resources that you need to - * clean up before propagating the error. - * - * When relying on Dart_PropagateError, we often return error handles - * rather than propagating them from helper functions. Consider the - * following contrived example: - * - * 1 Dart_Handle isLongStringHelper(Dart_Handle arg) { - * 2 intptr_t* length = 0; - * 3 result = Dart_StringLength(arg, &length); - * 4 if (Dart_IsError(result)) { - * 5 return result; - * 6 } - * 7 return Dart_NewBoolean(length > 100); - * 8 } - * 9 - * 10 void NativeFunction_isLongString(Dart_NativeArguments args) { - * 11 Dart_EnterScope(); - * 12 AllocateMyResource(); - * 13 Dart_Handle arg = Dart_GetNativeArgument(args, 0); - * 14 Dart_Handle result = isLongStringHelper(arg); - * 15 if (Dart_IsError(result)) { - * 16 FreeMyResource(); - * 17 Dart_PropagateError(result); - * 18 abort(); // will not reach here - * 19 } - * 20 Dart_SetReturnValue(result); - * 21 FreeMyResource(); - * 22 Dart_ExitScope(); - * 23 } - * - * In this example, we have a native function which calls a helper - * function to do its work. On line 5, the helper function could call - * Dart_PropagateError, but that would not give the native function a - * chance to call FreeMyResource(), causing a leak. Instead, the - * helper function returns the error handle to the caller, giving the - * caller a chance to clean up before propagating the error handle. - * - * When an error is propagated by calling Dart_SetReturnValue, the - * native function will be allowed to complete normally and then the - * exception will be propagated only once the native call - * returns. This can be convenient, as it allows the C code to clean - * up normally. - * - * The example can be written more simply using Dart_SetReturnValue to - * propagate the error. - * - * 1 Dart_Handle isLongStringHelper(Dart_Handle arg) { - * 2 intptr_t* length = 0; - * 3 result = Dart_StringLength(arg, &length); - * 4 if (Dart_IsError(result)) { - * 5 return result - * 6 } - * 7 return Dart_NewBoolean(length > 100); - * 8 } - * 9 - * 10 void NativeFunction_isLongString(Dart_NativeArguments args) { - * 11 Dart_EnterScope(); - * 12 AllocateMyResource(); - * 13 Dart_Handle arg = Dart_GetNativeArgument(args, 0); - * 14 Dart_SetReturnValue(isLongStringHelper(arg)); - * 15 FreeMyResource(); - * 16 Dart_ExitScope(); - * 17 } - * - * In this example, the call to Dart_SetReturnValue on line 14 will - * either return the normal return value or the error (potentially - * generated on line 3). The call to FreeMyResource on line 15 will - * execute in either case. - * - * --- Local and persistent handles --- - * - * Local handles are allocated within the current scope (see - * Dart_EnterScope) and go away when the current scope exits. Unless - * otherwise indicated, callers should assume that all functions in - * the Dart embedding api return local handles. - * - * Persistent handles are allocated within the current isolate. They - * can be used to store objects across scopes. Persistent handles have - * the lifetime of the current isolate unless they are explicitly - * deallocated (see Dart_DeletePersistentHandle). - * The type Dart_Handle represents a handle (both local and persistent). - * The type Dart_PersistentHandle is a Dart_Handle and it is used to - * document that a persistent handle is expected as a parameter to a call - * or the return value from a call is a persistent handle. - * - * FinalizableHandles are persistent handles which are auto deleted when - * the object is garbage collected. It is never safe to use these handles - * unless you know the object is still reachable. - * - * WeakPersistentHandles are persistent handles which are automatically set - * to point Dart_Null when the object is garbage collected. They are not auto - * deleted, so it is safe to use them after the object has become unreachable. - */ -typedef struct _Dart_Handle* Dart_Handle; -typedef Dart_Handle Dart_PersistentHandle; -typedef struct _Dart_WeakPersistentHandle* Dart_WeakPersistentHandle; -typedef struct _Dart_FinalizableHandle* Dart_FinalizableHandle; -// These structs are versioned by DART_API_DL_MAJOR_VERSION, bump the -// version when changing this struct. - -typedef void (*Dart_HandleFinalizer)(void* isolate_callback_data, void* peer); - -/** - * Is this an error handle? - * - * Requires there to be a current isolate. - */ -DART_EXPORT bool Dart_IsError(Dart_Handle handle); - -/** - * Is this an api error handle? - * - * Api error handles are produced when an api function is misused. - * This happens when a Dart embedding api function is called with - * invalid arguments or in an invalid context. - * - * Requires there to be a current isolate. - */ -DART_EXPORT bool Dart_IsApiError(Dart_Handle handle); - -/** - * Is this an unhandled exception error handle? - * - * Unhandled exception error handles are produced when, during the - * execution of Dart code, an exception is thrown but not caught. - * This can occur in any function which triggers the execution of Dart - * code. - * - * See Dart_ErrorGetException and Dart_ErrorGetStackTrace. - * - * Requires there to be a current isolate. - */ -DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle handle); - -/** - * Is this a compilation error handle? - * - * Compilation error handles are produced when, during the execution - * of Dart code, a compile-time error occurs. This can occur in any - * function which triggers the execution of Dart code. - * - * Requires there to be a current isolate. - */ -DART_EXPORT bool Dart_IsCompilationError(Dart_Handle handle); - -/** - * Is this a fatal error handle? - * - * Fatal error handles are produced when the system wants to shut down - * the current isolate. - * - * Requires there to be a current isolate. - */ -DART_EXPORT bool Dart_IsFatalError(Dart_Handle handle); - -/** - * Gets the error message from an error handle. - * - * Requires there to be a current isolate. - * - * \return A C string containing an error message if the handle is - * error. An empty C string ("") if the handle is valid. This C - * String is scope allocated and is only valid until the next call - * to Dart_ExitScope. -*/ -DART_EXPORT const char* Dart_GetError(Dart_Handle handle); - -/** - * Is this an error handle for an unhandled exception? - */ -DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle); - -/** - * Gets the exception Object from an unhandled exception error handle. - */ -DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle); - -/** - * Gets the stack trace Object from an unhandled exception error handle. - */ -DART_EXPORT Dart_Handle Dart_ErrorGetStackTrace(Dart_Handle handle); - -/** - * Produces an api error handle with the provided error message. - * - * Requires there to be a current isolate. - * - * \param error the error message. - */ -DART_EXPORT Dart_Handle Dart_NewApiError(const char* error); -DART_EXPORT Dart_Handle Dart_NewCompilationError(const char* error); - -/** - * Produces a new unhandled exception error handle. - * - * Requires there to be a current isolate. - * - * \param exception An instance of a Dart object to be thrown or - * an ApiError or CompilationError handle. - * When an ApiError or CompilationError handle is passed in - * a string object of the error message is created and it becomes - * the Dart object to be thrown. - */ -DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception); - -/** - * Propagates an error. - * - * If the provided handle is an unhandled exception error, this - * function will cause the unhandled exception to be rethrown. This - * will proceed in the standard way, walking up Dart frames until an - * appropriate 'catch' block is found, executing 'finally' blocks, - * etc. - * - * If the error is not an unhandled exception error, we will unwind - * the stack to the next C frame. Intervening Dart frames will be - * discarded; specifically, 'finally' blocks will not execute. This - * is the standard way that compilation errors (and the like) are - * handled by the Dart runtime. - * - * In either case, when an error is propagated any current scopes - * created by Dart_EnterScope will be exited. - * - * See the additional discussion under "Propagating Errors" at the - * beginning of this file. - * - * \param An error handle (See Dart_IsError) - * - * \return On success, this function does not return. On failure, the - * process is terminated. - */ -DART_EXPORT void Dart_PropagateError(Dart_Handle handle); - -/** - * Converts an object to a string. - * - * May generate an unhandled exception error. - * - * \return The converted string if no error occurs during - * the conversion. If an error does occur, an error handle is - * returned. - */ -DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object); - -/** - * Checks to see if two handles refer to identically equal objects. - * - * If both handles refer to instances, this is equivalent to using the top-level - * function identical() from dart:core. Otherwise, returns whether the two - * argument handles refer to the same object. - * - * \param obj1 An object to be compared. - * \param obj2 An object to be compared. - * - * \return True if the objects are identically equal. False otherwise. - */ -DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2); - -/** - * Allocates a handle in the current scope from a persistent handle. - */ -DART_EXPORT Dart_Handle Dart_HandleFromPersistent(Dart_PersistentHandle object); - -/** - * Allocates a handle in the current scope from a weak persistent handle. - * - * This will be a handle to Dart_Null if the object has been garbage collected. - */ -DART_EXPORT Dart_Handle -Dart_HandleFromWeakPersistent(Dart_WeakPersistentHandle object); - -/** - * Allocates a persistent handle for an object. - * - * This handle has the lifetime of the current isolate unless it is - * explicitly deallocated by calling Dart_DeletePersistentHandle. - * - * Requires there to be a current isolate. - */ -DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object); - -/** - * Assign value of local handle to a persistent handle. - * - * Requires there to be a current isolate. - * - * \param obj1 A persistent handle whose value needs to be set. - * \param obj2 An object whose value needs to be set to the persistent handle. - * - * \return Success if the persistent handle was set - * Otherwise, returns an error. - */ -DART_EXPORT void Dart_SetPersistentHandle(Dart_PersistentHandle obj1, - Dart_Handle obj2); - -/** - * Deallocates a persistent handle. - * - * Requires there to be a current isolate group. - */ -DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object); - -/** - * Allocates a weak persistent handle for an object. - * - * This handle has the lifetime of the current isolate. The handle can also be - * explicitly deallocated by calling Dart_DeleteWeakPersistentHandle. - * - * If the object becomes unreachable the callback is invoked with the peer as - * argument. The callback can be executed on any thread, will have a current - * isolate group, but will not have a current isolate. The callback can only - * call Dart_DeletePersistentHandle or Dart_DeleteWeakPersistentHandle. This - * gives the embedder the ability to cleanup data associated with the object. - * The handle will point to the Dart_Null object after the finalizer has been - * run. It is illegal to call into the VM with any other Dart_* functions from - * the callback. If the handle is deleted before the object becomes - * unreachable, the callback is never invoked. - * - * Requires there to be a current isolate. - * - * \param object An object. - * \param peer A pointer to a native object or NULL. This value is - * provided to callback when it is invoked. - * \param external_allocation_size The number of externally allocated - * bytes for peer. Used to inform the garbage collector. - * \param callback A function pointer that will be invoked sometime - * after the object is garbage collected, unless the handle has been deleted. - * A valid callback needs to be specified it cannot be NULL. - * - * \return The weak persistent handle or NULL. NULL is returned in case of bad - * parameters. - */ -DART_EXPORT Dart_WeakPersistentHandle -Dart_NewWeakPersistentHandle(Dart_Handle object, - void* peer, - intptr_t external_allocation_size, - Dart_HandleFinalizer callback); - -/** - * Deletes the given weak persistent [object] handle. - * - * Requires there to be a current isolate group. - */ -DART_EXPORT void Dart_DeleteWeakPersistentHandle( - Dart_WeakPersistentHandle object); - -/** - * Updates the external memory size for the given weak persistent handle. - * - * May trigger garbage collection. - */ -DART_EXPORT void Dart_UpdateExternalSize(Dart_WeakPersistentHandle object, - intptr_t external_allocation_size); - -/** - * Allocates a finalizable handle for an object. - * - * This handle has the lifetime of the current isolate group unless the object - * pointed to by the handle is garbage collected, in this case the VM - * automatically deletes the handle after invoking the callback associated - * with the handle. The handle can also be explicitly deallocated by - * calling Dart_DeleteFinalizableHandle. - * - * If the object becomes unreachable the callback is invoked with the - * the peer as argument. The callback can be executed on any thread, will have - * an isolate group, but will not have a current isolate. The callback can only - * call Dart_DeletePersistentHandle or Dart_DeleteWeakPersistentHandle. - * This gives the embedder the ability to cleanup data associated with the - * object and clear out any cached references to the handle. All references to - * this handle after the callback will be invalid. It is illegal to call into - * the VM with any other Dart_* functions from the callback. If the handle is - * deleted before the object becomes unreachable, the callback is never - * invoked. - * - * Requires there to be a current isolate. - * - * \param object An object. - * \param peer A pointer to a native object or NULL. This value is - * provided to callback when it is invoked. - * \param external_allocation_size The number of externally allocated - * bytes for peer. Used to inform the garbage collector. - * \param callback A function pointer that will be invoked sometime - * after the object is garbage collected, unless the handle has been deleted. - * A valid callback needs to be specified it cannot be NULL. - * - * \return The finalizable handle or NULL. NULL is returned in case of bad - * parameters. - */ -DART_EXPORT Dart_FinalizableHandle -Dart_NewFinalizableHandle(Dart_Handle object, - void* peer, - intptr_t external_allocation_size, - Dart_HandleFinalizer callback); - -/** - * Deletes the given finalizable [object] handle. - * - * The caller has to provide the actual Dart object the handle was created from - * to prove the object (and therefore the finalizable handle) is still alive. - * - * Requires there to be a current isolate. - */ -DART_EXPORT void Dart_DeleteFinalizableHandle(Dart_FinalizableHandle object, - Dart_Handle strong_ref_to_object); - -/** - * Updates the external memory size for the given finalizable handle. - * - * The caller has to provide the actual Dart object the handle was created from - * to prove the object (and therefore the finalizable handle) is still alive. - * - * May trigger garbage collection. - */ -DART_EXPORT void Dart_UpdateFinalizableExternalSize( - Dart_FinalizableHandle object, - Dart_Handle strong_ref_to_object, - intptr_t external_allocation_size); - -/* - * ========================== - * Initialization and Globals - * ========================== - */ - -/** - * Gets the version string for the Dart VM. - * - * The version of the Dart VM can be accessed without initializing the VM. - * - * \return The version string for the embedded Dart VM. - */ -DART_EXPORT const char* Dart_VersionString(); - -typedef struct { - const char* library_uri; - const char* class_name; - const char* function_name; -} Dart_QualifiedFunctionName; - -/** - * Isolate specific flags are set when creating a new isolate using the - * Dart_IsolateFlags structure. - * - * Current version of flags is encoded in a 32-bit integer with 16 bits used - * for each part. - */ - -#define DART_FLAGS_CURRENT_VERSION (0x0000000c) - -typedef struct { - int32_t version; - bool enable_asserts; - bool use_field_guards; - bool use_osr; - bool obfuscate; - Dart_QualifiedFunctionName* entry_points; - bool load_vmservice_library; - bool copy_parent_code; - bool null_safety; - bool is_system_isolate; -} Dart_IsolateFlags; - -/** - * Initialize Dart_IsolateFlags with correct version and default values. - */ -DART_EXPORT void Dart_IsolateFlagsInitialize(Dart_IsolateFlags* flags); - -/** - * An isolate creation and initialization callback function. - * - * This callback, provided by the embedder, is called when the VM - * needs to create an isolate. The callback should create an isolate - * by calling Dart_CreateIsolateGroup and load any scripts required for - * execution. - * - * This callback may be called on a different thread than the one - * running the parent isolate. - * - * When the function returns NULL, it is the responsibility of this - * function to ensure that Dart_ShutdownIsolate has been called if - * required (for example, if the isolate was created successfully by - * Dart_CreateIsolateGroup() but the root library fails to load - * successfully, then the function should call Dart_ShutdownIsolate - * before returning). - * - * When the function returns NULL, the function should set *error to - * a malloc-allocated buffer containing a useful error message. The - * caller of this function (the VM) will make sure that the buffer is - * freed. - * - * \param script_uri The uri of the main source file or snapshot to load. - * Either the URI of the parent isolate set in Dart_CreateIsolateGroup for - * Isolate.spawn, or the argument to Isolate.spawnUri canonicalized by the - * library tag handler of the parent isolate. - * The callback is responsible for loading the program by a call to - * Dart_LoadScriptFromKernel. - * \param main The name of the main entry point this isolate will - * eventually run. This is provided for advisory purposes only to - * improve debugging messages. The main function is not invoked by - * this function. - * \param package_root Ignored. - * \param package_config Uri of the package configuration file (either in format - * of .packages or .dart_tool/package_config.json) for this isolate - * to resolve package imports against. If this parameter is not passed the - * package resolution of the parent isolate should be used. - * \param flags Default flags for this isolate being spawned. Either inherited - * from the spawning isolate or passed as parameters when spawning the - * isolate from Dart code. - * \param isolate_data The isolate data which was passed to the - * parent isolate when it was created by calling Dart_CreateIsolateGroup(). - * \param error A structure into which the embedder can place a - * C string containing an error message in the case of failures. - * - * \return The embedder returns NULL if the creation and - * initialization was not successful and the isolate if successful. - */ -typedef Dart_Isolate (*Dart_IsolateGroupCreateCallback)( - const char* script_uri, - const char* main, - const char* package_root, - const char* package_config, - Dart_IsolateFlags* flags, - void* isolate_data, - char** error); - -/** - * An isolate initialization callback function. - * - * This callback, provided by the embedder, is called when the VM has created an - * isolate within an existing isolate group (i.e. from the same source as an - * existing isolate). - * - * The callback should setup native resolvers and might want to set a custom - * message handler via [Dart_SetMessageNotifyCallback] and mark the isolate as - * runnable. - * - * This callback may be called on a different thread than the one - * running the parent isolate. - * - * When the function returns `false`, it is the responsibility of this - * function to ensure that `Dart_ShutdownIsolate` has been called. - * - * When the function returns `false`, the function should set *error to - * a malloc-allocated buffer containing a useful error message. The - * caller of this function (the VM) will make sure that the buffer is - * freed. - * - * \param child_isolate_data The callback data to associate with the new - * child isolate. - * \param error A structure into which the embedder can place a - * C string containing an error message in the case the initialization fails. - * - * \return The embedder returns true if the initialization was successful and - * false otherwise (in which case the VM will terminate the isolate). - */ -typedef bool (*Dart_InitializeIsolateCallback)(void** child_isolate_data, - char** error); - -/** - * An isolate unhandled exception callback function. - * - * This callback has been DEPRECATED. - */ -typedef void (*Dart_IsolateUnhandledExceptionCallback)(Dart_Handle error); - -/** - * An isolate shutdown callback function. - * - * This callback, provided by the embedder, is called before the vm - * shuts down an isolate. The isolate being shutdown will be the current - * isolate. It is safe to run Dart code. - * - * This function should be used to dispose of native resources that - * are allocated to an isolate in order to avoid leaks. - * - * \param isolate_group_data The same callback data which was passed to the - * isolate group when it was created. - * \param isolate_data The same callback data which was passed to the isolate - * when it was created. - */ -typedef void (*Dart_IsolateShutdownCallback)(void* isolate_group_data, - void* isolate_data); - -/** - * An isolate cleanup callback function. - * - * This callback, provided by the embedder, is called after the vm - * shuts down an isolate. There will be no current isolate and it is *not* - * safe to run Dart code. - * - * This function should be used to dispose of native resources that - * are allocated to an isolate in order to avoid leaks. - * - * \param isolate_group_data The same callback data which was passed to the - * isolate group when it was created. - * \param isolate_data The same callback data which was passed to the isolate - * when it was created. - */ -typedef void (*Dart_IsolateCleanupCallback)(void* isolate_group_data, - void* isolate_data); - -/** - * An isolate group cleanup callback function. - * - * This callback, provided by the embedder, is called after the vm - * shuts down an isolate group. - * - * This function should be used to dispose of native resources that - * are allocated to an isolate in order to avoid leaks. - * - * \param isolate_group_data The same callback data which was passed to the - * isolate group when it was created. - * - */ -typedef void (*Dart_IsolateGroupCleanupCallback)(void* isolate_group_data); - -/** - * A thread death callback function. - * This callback, provided by the embedder, is called before a thread in the - * vm thread pool exits. - * This function could be used to dispose of native resources that - * are associated and attached to the thread, in order to avoid leaks. - */ -typedef void (*Dart_ThreadExitCallback)(); - -/** - * Callbacks provided by the embedder for file operations. If the - * embedder does not allow file operations these callbacks can be - * NULL. - * - * Dart_FileOpenCallback - opens a file for reading or writing. - * \param name The name of the file to open. - * \param write A boolean variable which indicates if the file is to - * opened for writing. If there is an existing file it needs to truncated. - * - * Dart_FileReadCallback - Read contents of file. - * \param data Buffer allocated in the callback into which the contents - * of the file are read into. It is the responsibility of the caller to - * free this buffer. - * \param file_length A variable into which the length of the file is returned. - * In the case of an error this value would be -1. - * \param stream Handle to the opened file. - * - * Dart_FileWriteCallback - Write data into file. - * \param data Buffer which needs to be written into the file. - * \param length Length of the buffer. - * \param stream Handle to the opened file. - * - * Dart_FileCloseCallback - Closes the opened file. - * \param stream Handle to the opened file. - * - */ -typedef void* (*Dart_FileOpenCallback)(const char* name, bool write); - -typedef void (*Dart_FileReadCallback)(uint8_t** data, - intptr_t* file_length, - void* stream); - -typedef void (*Dart_FileWriteCallback)(const void* data, - intptr_t length, - void* stream); - -typedef void (*Dart_FileCloseCallback)(void* stream); - -typedef bool (*Dart_EntropySource)(uint8_t* buffer, intptr_t length); - -/** - * Callback provided by the embedder that is used by the vmservice isolate - * to request the asset archive. The asset archive must be an uncompressed tar - * archive that is stored in a Uint8List. - * - * If the embedder has no vmservice isolate assets, the callback can be NULL. - * - * \return The embedder must return a handle to a Uint8List containing an - * uncompressed tar archive or null. - */ -typedef Dart_Handle (*Dart_GetVMServiceAssetsArchive)(); - -/** - * The current version of the Dart_InitializeFlags. Should be incremented every - * time Dart_InitializeFlags changes in a binary incompatible way. - */ -#define DART_INITIALIZE_PARAMS_CURRENT_VERSION (0x00000004) - -/** Forward declaration */ -struct Dart_CodeObserver; - -/** - * Callback provided by the embedder that is used by the VM to notify on code - * object creation, *before* it is invoked the first time. - * This is useful for embedders wanting to e.g. keep track of PCs beyond - * the lifetime of the garbage collected code objects. - * Note that an address range may be used by more than one code object over the - * lifecycle of a process. Clients of this function should record timestamps for - * these compilation events and when collecting PCs to disambiguate reused - * address ranges. - */ -typedef void (*Dart_OnNewCodeCallback)(struct Dart_CodeObserver* observer, - const char* name, - uintptr_t base, - uintptr_t size); - -typedef struct Dart_CodeObserver { - void* data; - - Dart_OnNewCodeCallback on_new_code; -} Dart_CodeObserver; - -/** - * Describes how to initialize the VM. Used with Dart_Initialize. - * - * \param version Identifies the version of the struct used by the client. - * should be initialized to DART_INITIALIZE_PARAMS_CURRENT_VERSION. - * \param vm_isolate_snapshot A buffer containing a snapshot of the VM isolate - * or NULL if no snapshot is provided. If provided, the buffer must remain - * valid until Dart_Cleanup returns. - * \param instructions_snapshot A buffer containing a snapshot of precompiled - * instructions, or NULL if no snapshot is provided. If provided, the buffer - * must remain valid until Dart_Cleanup returns. - * \param initialize_isolate A function to be called during isolate - * initialization inside an existing isolate group. - * See Dart_InitializeIsolateCallback. - * \param create_group A function to be called during isolate group creation. - * See Dart_IsolateGroupCreateCallback. - * \param shutdown A function to be called right before an isolate is shutdown. - * See Dart_IsolateShutdownCallback. - * \param cleanup A function to be called after an isolate was shutdown. - * See Dart_IsolateCleanupCallback. - * \param cleanup_group A function to be called after an isolate group is shutdown. - * See Dart_IsolateGroupCleanupCallback. - * \param get_service_assets A function to be called by the service isolate when - * it requires the vmservice assets archive. - * See Dart_GetVMServiceAssetsArchive. - * \param code_observer An external code observer callback function. - * The observer can be invoked as early as during the Dart_Initialize() call. - */ -typedef struct { - int32_t version; - const uint8_t* vm_snapshot_data; - const uint8_t* vm_snapshot_instructions; - Dart_IsolateGroupCreateCallback create_group; - Dart_InitializeIsolateCallback initialize_isolate; - Dart_IsolateShutdownCallback shutdown_isolate; - Dart_IsolateCleanupCallback cleanup_isolate; - Dart_IsolateGroupCleanupCallback cleanup_group; - Dart_ThreadExitCallback thread_exit; - Dart_FileOpenCallback file_open; - Dart_FileReadCallback file_read; - Dart_FileWriteCallback file_write; - Dart_FileCloseCallback file_close; - Dart_EntropySource entropy_source; - Dart_GetVMServiceAssetsArchive get_service_assets; - bool start_kernel_isolate; - Dart_CodeObserver* code_observer; -} Dart_InitializeParams; - -/** - * Initializes the VM. - * - * \param params A struct containing initialization information. The version - * field of the struct must be DART_INITIALIZE_PARAMS_CURRENT_VERSION. - * - * \return NULL if initialization is successful. Returns an error message - * otherwise. The caller is responsible for freeing the error message. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT char* Dart_Initialize( - Dart_InitializeParams* params); - -/** - * Cleanup state in the VM before process termination. - * - * \return NULL if cleanup is successful. Returns an error message otherwise. - * The caller is responsible for freeing the error message. - * - * NOTE: This function must not be called on a thread that was created by the VM - * itself. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT char* Dart_Cleanup(); - -/** - * Sets command line flags. Should be called before Dart_Initialize. - * - * \param argc The length of the arguments array. - * \param argv An array of arguments. - * - * \return NULL if successful. Returns an error message otherwise. - * The caller is responsible for freeing the error message. - * - * NOTE: This call does not store references to the passed in c-strings. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT char* Dart_SetVMFlags(int argc, - const char** argv); - -/** - * Returns true if the named VM flag is of boolean type, specified, and set to - * true. - * - * \param flag_name The name of the flag without leading punctuation - * (example: "enable_asserts"). - */ -DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name); - -/* - * ======== - * Isolates - * ======== - */ - -/** - * Creates a new isolate. The new isolate becomes the current isolate. - * - * A snapshot can be used to restore the VM quickly to a saved state - * and is useful for fast startup. If snapshot data is provided, the - * isolate will be started using that snapshot data. Requires a core snapshot or - * an app snapshot created by Dart_CreateSnapshot or - * Dart_CreatePrecompiledSnapshot* from a VM with the same version. - * - * Requires there to be no current isolate. - * - * \param script_uri The main source file or snapshot this isolate will load. - * The VM will provide this URI to the Dart_IsolateGroupCreateCallback when a child - * isolate is created by Isolate.spawn. The embedder should use a URI that - * allows it to load the same program into such a child isolate. - * \param name A short name for the isolate to improve debugging messages. - * Typically of the format 'foo.dart:main()'. - * \param isolate_snapshot_data - * \param isolate_snapshot_instructions Buffers containing a snapshot of the - * isolate or NULL if no snapshot is provided. If provided, the buffers must - * remain valid until the isolate shuts down. - * \param flags Pointer to VM specific flags or NULL for default flags. - * \param isolate_group_data Embedder group data. This data can be obtained - * by calling Dart_IsolateGroupData and will be passed to the - * Dart_IsolateShutdownCallback, Dart_IsolateCleanupCallback, and - * Dart_IsolateGroupCleanupCallback. - * \param isolate_data Embedder data. This data will be passed to - * the Dart_IsolateGroupCreateCallback when new isolates are spawned from - * this parent isolate. - * \param error Returns NULL if creation is successful, an error message - * otherwise. The caller is responsible for calling free() on the error - * message. - * - * \return The new isolate on success, or NULL if isolate creation failed. - */ -DART_EXPORT Dart_Isolate -Dart_CreateIsolateGroup(const char* script_uri, - const char* name, - const uint8_t* isolate_snapshot_data, - const uint8_t* isolate_snapshot_instructions, - Dart_IsolateFlags* flags, - void* isolate_group_data, - void* isolate_data, - char** error); -/* TODO(turnidge): Document behavior when there is already a current - * isolate. */ - -/** - * Creates a new isolate from a Dart Kernel file. The new isolate - * becomes the current isolate. - * - * Requires there to be no current isolate. - * - * \param script_uri The main source file or snapshot this isolate will load. - * The VM will provide this URI to the Dart_IsolateGroupCreateCallback when a child - * isolate is created by Isolate.spawn. The embedder should use a URI that - * allows it to load the same program into such a child isolate. - * \param name A short name for the isolate to improve debugging messages. - * Typically of the format 'foo.dart:main()'. - * \param kernel_buffer - * \param kernel_buffer_size A buffer which contains a kernel/DIL program. Must - * remain valid until isolate shutdown. - * \param flags Pointer to VM specific flags or NULL for default flags. - * \param isolate_group_data Embedder group data. This data can be obtained - * by calling Dart_IsolateGroupData and will be passed to the - * Dart_IsolateShutdownCallback, Dart_IsolateCleanupCallback, and - * Dart_IsolateGroupCleanupCallback. - * \param isolate_data Embedder data. This data will be passed to - * the Dart_IsolateGroupCreateCallback when new isolates are spawned from - * this parent isolate. - * \param error Returns NULL if creation is successful, an error message - * otherwise. The caller is responsible for calling free() on the error - * message. - * - * \return The new isolate on success, or NULL if isolate creation failed. - */ -DART_EXPORT Dart_Isolate -Dart_CreateIsolateGroupFromKernel(const char* script_uri, - const char* name, - const uint8_t* kernel_buffer, - intptr_t kernel_buffer_size, - Dart_IsolateFlags* flags, - void* isolate_group_data, - void* isolate_data, - char** error); -/** - * Shuts down the current isolate. After this call, the current isolate is NULL. - * Any current scopes created by Dart_EnterScope will be exited. Invokes the - * shutdown callback and any callbacks of remaining weak persistent handles. - * - * Requires there to be a current isolate. - */ -DART_EXPORT void Dart_ShutdownIsolate(); -/* TODO(turnidge): Document behavior when there is no current isolate. */ - -/** - * Returns the current isolate. Will return NULL if there is no - * current isolate. - */ -DART_EXPORT Dart_Isolate Dart_CurrentIsolate(); - -/** - * Returns the callback data associated with the current isolate. This - * data was set when the isolate got created or initialized. - */ -DART_EXPORT void* Dart_CurrentIsolateData(); - -/** - * Returns the callback data associated with the given isolate. This - * data was set when the isolate got created or initialized. - */ -DART_EXPORT void* Dart_IsolateData(Dart_Isolate isolate); - -/** - * Returns the current isolate group. Will return NULL if there is no - * current isolate group. - */ -DART_EXPORT Dart_IsolateGroup Dart_CurrentIsolateGroup(); - -/** - * Returns the callback data associated with the current isolate group. This - * data was passed to the isolate group when it was created. - */ -DART_EXPORT void* Dart_CurrentIsolateGroupData(); - -/** - * Returns the callback data associated with the specified isolate group. This - * data was passed to the isolate when it was created. - * The embedder is responsible for ensuring the consistency of this data - * with respect to the lifecycle of an isolate group. - */ -DART_EXPORT void* Dart_IsolateGroupData(Dart_Isolate isolate); - -/** - * Returns the debugging name for the current isolate. - * - * This name is unique to each isolate and should only be used to make - * debugging messages more comprehensible. - */ -DART_EXPORT Dart_Handle Dart_DebugName(); - -/** - * Returns the ID for an isolate which is used to query the service protocol. - * - * It is the responsibility of the caller to free the returned ID. - */ -DART_EXPORT const char* Dart_IsolateServiceId(Dart_Isolate isolate); - -/** - * Enters an isolate. After calling this function, - * the current isolate will be set to the provided isolate. - * - * Requires there to be no current isolate. Multiple threads may not be in - * the same isolate at once. - */ -DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate); - -/** - * Kills the given isolate. - * - * This function has the same effect as dart:isolate's - * Isolate.kill(priority:immediate). - * It can interrupt ordinary Dart code but not native code. If the isolate is - * in the middle of a long running native function, the isolate will not be - * killed until control returns to Dart. - * - * Does not require a current isolate. It is safe to kill the current isolate if - * there is one. - */ -DART_EXPORT void Dart_KillIsolate(Dart_Isolate isolate); - -/** - * Notifies the VM that the embedder expects |size| bytes of memory have become - * unreachable. The VM may use this hint to adjust the garbage collector's - * growth policy. - * - * Multiple calls are interpreted as increasing, not replacing, the estimate of - * unreachable memory. - * - * Requires there to be a current isolate. - */ -DART_EXPORT void Dart_HintFreed(intptr_t size); - -/** - * Notifies the VM that the embedder expects to be idle until |deadline|. The VM - * may use this time to perform garbage collection or other tasks to avoid - * delays during execution of Dart code in the future. - * - * |deadline| is measured in microseconds against the system's monotonic time. - * This clock can be accessed via Dart_TimelineGetMicros(). - * - * Requires there to be a current isolate. - */ -DART_EXPORT void Dart_NotifyIdle(int64_t deadline); - -/** - * Notifies the VM that the system is running low on memory. - * - * Does not require a current isolate. Only valid after calling Dart_Initialize. - */ -DART_EXPORT void Dart_NotifyLowMemory(); - -/** - * Starts the CPU sampling profiler. - */ -DART_EXPORT void Dart_StartProfiling(); - -/** - * Stops the CPU sampling profiler. - * - * Note that some profile samples might still be taken after this fucntion - * returns due to the asynchronous nature of the implementation on some - * platforms. - */ -DART_EXPORT void Dart_StopProfiling(); - -/** - * Notifies the VM that the current thread should not be profiled until a - * matching call to Dart_ThreadEnableProfiling is made. - * - * NOTE: By default, if a thread has entered an isolate it will be profiled. - * This function should be used when an embedder knows a thread is about - * to make a blocking call and wants to avoid unnecessary interrupts by - * the profiler. - */ -DART_EXPORT void Dart_ThreadDisableProfiling(); - -/** - * Notifies the VM that the current thread should be profiled. - * - * NOTE: It is only legal to call this function *after* calling - * Dart_ThreadDisableProfiling. - * - * NOTE: By default, if a thread has entered an isolate it will be profiled. - */ -DART_EXPORT void Dart_ThreadEnableProfiling(); - -/** - * Register symbol information for the Dart VM's profiler and crash dumps. - * - * This consumes the output of //topaz/runtime/dart/profiler_symbols, which - * should be treated as opaque. - */ -DART_EXPORT void Dart_AddSymbols(const char* dso_name, - void* buffer, - intptr_t buffer_size); - -/** - * Exits an isolate. After this call, Dart_CurrentIsolate will - * return NULL. - * - * Requires there to be a current isolate. - */ -DART_EXPORT void Dart_ExitIsolate(); -/* TODO(turnidge): We don't want users of the api to be able to exit a - * "pure" dart isolate. Implement and document. */ - -/** - * Creates a full snapshot of the current isolate heap. - * - * A full snapshot is a compact representation of the dart vm isolate heap - * and dart isolate heap states. These snapshots are used to initialize - * the vm isolate on startup and fast initialization of an isolate. - * A Snapshot of the heap is created before any dart code has executed. - * - * Requires there to be a current isolate. Not available in the precompiled - * runtime (check Dart_IsPrecompiledRuntime). - * - * \param buffer Returns a pointer to a buffer containing the - * snapshot. This buffer is scope allocated and is only valid - * until the next call to Dart_ExitScope. - * \param size Returns the size of the buffer. - * \param is_core Create a snapshot containing core libraries. - * Such snapshot should be agnostic to null safety mode. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_CreateSnapshot(uint8_t** vm_snapshot_data_buffer, - intptr_t* vm_snapshot_data_size, - uint8_t** isolate_snapshot_data_buffer, - intptr_t* isolate_snapshot_data_size, - bool is_core); - -/** - * Returns whether the buffer contains a kernel file. - * - * \param buffer Pointer to a buffer that might contain a kernel binary. - * \param buffer_size Size of the buffer. - * - * \return Whether the buffer contains a kernel binary (full or partial). - */ -DART_EXPORT bool Dart_IsKernel(const uint8_t* buffer, intptr_t buffer_size); - -/** - * Make isolate runnable. - * - * When isolates are spawned, this function is used to indicate that - * the creation and initialization (including script loading) of the - * isolate is complete and the isolate can start. - * This function expects there to be no current isolate. - * - * \param isolate The isolate to be made runnable. - * - * \return NULL if successful. Returns an error message otherwise. The caller - * is responsible for freeing the error message. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT char* Dart_IsolateMakeRunnable( - Dart_Isolate isolate); - -/* - * ================== - * Messages and Ports - * ================== - */ - -/** - * A port is used to send or receive inter-isolate messages - */ -typedef int64_t Dart_Port; - -/** - * ILLEGAL_PORT is a port number guaranteed never to be associated with a valid - * port. - */ -#define ILLEGAL_PORT ((Dart_Port)0) - -/** - * A message notification callback. - * - * This callback allows the embedder to provide an alternate wakeup - * mechanism for the delivery of inter-isolate messages. It is the - * responsibility of the embedder to call Dart_HandleMessage to - * process the message. - */ -typedef void (*Dart_MessageNotifyCallback)(Dart_Isolate dest_isolate); - -/** - * Allows embedders to provide an alternative wakeup mechanism for the - * delivery of inter-isolate messages. This setting only applies to - * the current isolate. - * - * Most embedders will only call this function once, before isolate - * execution begins. If this function is called after isolate - * execution begins, the embedder is responsible for threading issues. - */ -DART_EXPORT void Dart_SetMessageNotifyCallback( - Dart_MessageNotifyCallback message_notify_callback); -/* TODO(turnidge): Consider moving this to isolate creation so that it - * is impossible to mess up. */ - -/** - * Query the current message notify callback for the isolate. - * - * \return The current message notify callback for the isolate. - */ -DART_EXPORT Dart_MessageNotifyCallback Dart_GetMessageNotifyCallback(); - -/** - * The VM's default message handler supports pausing an isolate before it - * processes the first message and right after the it processes the isolate's - * final message. This can be controlled for all isolates by two VM flags: - * - * `--pause-isolates-on-start` - * `--pause-isolates-on-exit` - * - * Additionally, Dart_SetShouldPauseOnStart and Dart_SetShouldPauseOnExit can be - * used to control this behaviour on a per-isolate basis. - * - * When an embedder is using a Dart_MessageNotifyCallback the embedder - * needs to cooperate with the VM so that the service protocol can report - * accurate information about isolates and so that tools such as debuggers - * work reliably. - * - * The following functions can be used to implement pausing on start and exit. - */ - -/** - * If the VM flag `--pause-isolates-on-start` was passed this will be true. - * - * \return A boolean value indicating if pause on start was requested. - */ -DART_EXPORT bool Dart_ShouldPauseOnStart(); - -/** - * Override the VM flag `--pause-isolates-on-start` for the current isolate. - * - * \param should_pause Should the isolate be paused on start? - * - * NOTE: This must be called before Dart_IsolateMakeRunnable. - */ -DART_EXPORT void Dart_SetShouldPauseOnStart(bool should_pause); - -/** - * Is the current isolate paused on start? - * - * \return A boolean value indicating if the isolate is paused on start. - */ -DART_EXPORT bool Dart_IsPausedOnStart(); - -/** - * Called when the embedder has paused the current isolate on start and when - * the embedder has resumed the isolate. - * - * \param paused Is the isolate paused on start? - */ -DART_EXPORT void Dart_SetPausedOnStart(bool paused); - -/** - * If the VM flag `--pause-isolates-on-exit` was passed this will be true. - * - * \return A boolean value indicating if pause on exit was requested. - */ -DART_EXPORT bool Dart_ShouldPauseOnExit(); - -/** - * Override the VM flag `--pause-isolates-on-exit` for the current isolate. - * - * \param should_pause Should the isolate be paused on exit? - * - */ -DART_EXPORT void Dart_SetShouldPauseOnExit(bool should_pause); - -/** - * Is the current isolate paused on exit? - * - * \return A boolean value indicating if the isolate is paused on exit. - */ -DART_EXPORT bool Dart_IsPausedOnExit(); - -/** - * Called when the embedder has paused the current isolate on exit and when - * the embedder has resumed the isolate. - * - * \param paused Is the isolate paused on exit? - */ -DART_EXPORT void Dart_SetPausedOnExit(bool paused); - -/** - * Called when the embedder has caught a top level unhandled exception error - * in the current isolate. - * - * NOTE: It is illegal to call this twice on the same isolate without first - * clearing the sticky error to null. - * - * \param error The unhandled exception error. - */ -DART_EXPORT void Dart_SetStickyError(Dart_Handle error); - -/** - * Does the current isolate have a sticky error? - */ -DART_EXPORT bool Dart_HasStickyError(); - -/** - * Gets the sticky error for the current isolate. - * - * \return A handle to the sticky error object or null. - */ -DART_EXPORT Dart_Handle Dart_GetStickyError(); - -/** - * Handles the next pending message for the current isolate. - * - * May generate an unhandled exception error. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_HandleMessage(); - -/** - * Drains the microtask queue, then blocks the calling thread until the current - * isolate recieves a message, then handles all messages. - * - * \param timeout_millis When non-zero, the call returns after the indicated - number of milliseconds even if no message was received. - * \return A valid handle if no error occurs, otherwise an error handle. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_WaitForEvent(int64_t timeout_millis); - -/** - * Handles any pending messages for the vm service for the current - * isolate. - * - * This function may be used by an embedder at a breakpoint to avoid - * pausing the vm service. - * - * This function can indirectly cause the message notify callback to - * be called. - * - * \return true if the vm service requests the program resume - * execution, false otherwise - */ -DART_EXPORT bool Dart_HandleServiceMessages(); - -/** - * Does the current isolate have pending service messages? - * - * \return true if the isolate has pending service messages, false otherwise. - */ -DART_EXPORT bool Dart_HasServiceMessages(); - -/** - * Processes any incoming messages for the current isolate. - * - * This function may only be used when the embedder has not provided - * an alternate message delivery mechanism with - * Dart_SetMessageCallbacks. It is provided for convenience. - * - * This function waits for incoming messages for the current - * isolate. As new messages arrive, they are handled using - * Dart_HandleMessage. The routine exits when all ports to the - * current isolate are closed. - * - * \return A valid handle if the run loop exited successfully. If an - * exception or other error occurs while processing messages, an - * error handle is returned. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_RunLoop(); -/* TODO(turnidge): Should this be removed from the public api? */ - -/** - * Gets the main port id for the current isolate. - */ -DART_EXPORT Dart_Port Dart_GetMainPortId(); - -/** - * Does the current isolate have live ReceivePorts? - * - * A ReceivePort is live when it has not been closed. - */ -DART_EXPORT bool Dart_HasLivePorts(); - -/** - * Posts a message for some isolate. The message is a serialized - * object. - * - * Requires there to be a current isolate. - * - * \param port The destination port. - * \param object An object from the current isolate. - * - * \return True if the message was posted. - */ -DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle object); - -/** - * Returns a new SendPort with the provided port id. - * - * \param port_id The destination port. - * - * \return A new SendPort if no errors occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id); - -/** - * Gets the SendPort id for the provided SendPort. - * \param port A SendPort object whose id is desired. - * \param port_id Returns the id of the SendPort. - * \return Success if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, - Dart_Port* port_id); - -/* - * ====== - * Scopes - * ====== - */ - -/** - * Enters a new scope. - * - * All new local handles will be created in this scope. Additionally, - * some functions may return "scope allocated" memory which is only - * valid within this scope. - * - * Requires there to be a current isolate. - */ -DART_EXPORT void Dart_EnterScope(); - -/** - * Exits a scope. - * - * The previous scope (if any) becomes the current scope. - * - * Requires there to be a current isolate. - */ -DART_EXPORT void Dart_ExitScope(); - -/** - * The Dart VM uses "zone allocation" for temporary structures. Zones - * support very fast allocation of small chunks of memory. The chunks - * cannot be deallocated individually, but instead zones support - * deallocating all chunks in one fast operation. - * - * This function makes it possible for the embedder to allocate - * temporary data in the VMs zone allocator. - * - * Zone allocation is possible: - * 1. when inside a scope where local handles can be allocated - * 2. when processing a message from a native port in a native port - * handler - * - * All the memory allocated this way will be reclaimed either on the - * next call to Dart_ExitScope or when the native port handler exits. - * - * \param size Size of the memory to allocate. - * - * \return A pointer to the allocated memory. NULL if allocation - * failed. Failure might due to is no current VM zone. - */ -DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size); - -/* - * ======= - * Objects - * ======= - */ - -/** - * Returns the null object. - * - * \return A handle to the null object. - */ -DART_EXPORT Dart_Handle Dart_Null(); - -/** - * Is this object null? - */ -DART_EXPORT bool Dart_IsNull(Dart_Handle object); - -/** - * Returns the empty string object. - * - * \return A handle to the empty string object. - */ -DART_EXPORT Dart_Handle Dart_EmptyString(); - -/** - * Returns types that are not classes, and which therefore cannot be looked up - * as library members by Dart_GetType. - * - * \return A handle to the dynamic, void or Never type. - */ -DART_EXPORT Dart_Handle Dart_TypeDynamic(); -DART_EXPORT Dart_Handle Dart_TypeVoid(); -DART_EXPORT Dart_Handle Dart_TypeNever(); - -/** - * Checks if the two objects are equal. - * - * The result of the comparison is returned through the 'equal' - * parameter. The return value itself is used to indicate success or - * failure, not equality. - * - * May generate an unhandled exception error. - * - * \param obj1 An object to be compared. - * \param obj2 An object to be compared. - * \param equal Returns the result of the equality comparison. - * - * \return A valid handle if no error occurs during the comparison. - */ -DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, - Dart_Handle obj2, - bool* equal); - -/** - * Is this object an instance of some type? - * - * The result of the test is returned through the 'instanceof' parameter. - * The return value itself is used to indicate success or failure. - * - * \param object An object. - * \param type A type. - * \param instanceof Return true if 'object' is an instance of type 'type'. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, - Dart_Handle type, - bool* instanceof); - -/** - * Query object type. - * - * \param object Some Object. - * - * \return true if Object is of the specified type. - */ -DART_EXPORT bool Dart_IsInstance(Dart_Handle object); -DART_EXPORT bool Dart_IsNumber(Dart_Handle object); -DART_EXPORT bool Dart_IsInteger(Dart_Handle object); -DART_EXPORT bool Dart_IsDouble(Dart_Handle object); -DART_EXPORT bool Dart_IsBoolean(Dart_Handle object); -DART_EXPORT bool Dart_IsString(Dart_Handle object); -DART_EXPORT bool Dart_IsStringLatin1(Dart_Handle object); /* (ISO-8859-1) */ -DART_EXPORT bool Dart_IsExternalString(Dart_Handle object); -DART_EXPORT bool Dart_IsList(Dart_Handle object); -DART_EXPORT bool Dart_IsMap(Dart_Handle object); -DART_EXPORT bool Dart_IsLibrary(Dart_Handle object); -DART_EXPORT bool Dart_IsType(Dart_Handle handle); -DART_EXPORT bool Dart_IsFunction(Dart_Handle handle); -DART_EXPORT bool Dart_IsVariable(Dart_Handle handle); -DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle); -DART_EXPORT bool Dart_IsClosure(Dart_Handle object); -DART_EXPORT bool Dart_IsTypedData(Dart_Handle object); -DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle object); -DART_EXPORT bool Dart_IsFuture(Dart_Handle object); - -/* - * ========= - * Instances - * ========= - */ - -/* - * For the purposes of the embedding api, not all objects returned are - * Dart language objects. Within the api, we use the term 'Instance' - * to indicate handles which refer to true Dart language objects. - * - * TODO(turnidge): Reorganize the "Object" section above, pulling down - * any functions that more properly belong here. */ - -/** - * Gets the type of a Dart language object. - * - * \param instance Some Dart object. - * - * \return If no error occurs, the type is returned. Otherwise an - * error handle is returned. - */ -DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance); - -/** - * Returns the name for the provided class type. - * - * \return A valid string handle if no error occurs during the - * operation. - */ -DART_EXPORT Dart_Handle Dart_ClassName(Dart_Handle cls_type); - -/** - * Returns the name for the provided function or method. - * - * \return A valid string handle if no error occurs during the - * operation. - */ -DART_EXPORT Dart_Handle Dart_FunctionName(Dart_Handle function); - -/** - * Returns a handle to the owner of a function. - * - * The owner of an instance method or a static method is its defining - * class. The owner of a top-level function is its defining - * library. The owner of the function of a non-implicit closure is the - * function of the method or closure that defines the non-implicit - * closure. - * - * \return A valid handle to the owner of the function, or an error - * handle if the argument is not a valid handle to a function. - */ -DART_EXPORT Dart_Handle Dart_FunctionOwner(Dart_Handle function); - -/** - * Determines whether a function handle referes to a static function - * of method. - * - * For the purposes of the embedding API, a top-level function is - * implicitly declared static. - * - * \param function A handle to a function or method declaration. - * \param is_static Returns whether the function or method is declared static. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_FunctionIsStatic(Dart_Handle function, - bool* is_static); - -/** - * Is this object a closure resulting from a tear-off (closurized method)? - * - * Returns true for closures produced when an ordinary method is accessed - * through a getter call. Returns false otherwise, in particular for closures - * produced from local function declarations. - * - * \param object Some Object. - * - * \return true if Object is a tear-off. - */ -DART_EXPORT bool Dart_IsTearOff(Dart_Handle object); - -/** - * Retrieves the function of a closure. - * - * \return A handle to the function of the closure, or an error handle if the - * argument is not a closure. - */ -DART_EXPORT Dart_Handle Dart_ClosureFunction(Dart_Handle closure); - -/** - * Returns a handle to the library which contains class. - * - * \return A valid handle to the library with owns class, null if the class - * has no library or an error handle if the argument is not a valid handle - * to a class type. - */ -DART_EXPORT Dart_Handle Dart_ClassLibrary(Dart_Handle cls_type); - -/* - * ============================= - * Numbers, Integers and Doubles - * ============================= - */ - -/** - * Does this Integer fit into a 64-bit signed integer? - * - * \param integer An integer. - * \param fits Returns true if the integer fits into a 64-bit signed integer. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, - bool* fits); - -/** - * Does this Integer fit into a 64-bit unsigned integer? - * - * \param integer An integer. - * \param fits Returns true if the integer fits into a 64-bit unsigned integer. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, - bool* fits); - -/** - * Returns an Integer with the provided value. - * - * \param value The value of the integer. - * - * \return The Integer object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value); - -/** - * Returns an Integer with the provided value. - * - * \param value The unsigned value of the integer. - * - * \return The Integer object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value); - -/** - * Returns an Integer with the provided value. - * - * \param value The value of the integer represented as a C string - * containing a hexadecimal number. - * - * \return The Integer object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* value); - -/** - * Gets the value of an Integer. - * - * The integer must fit into a 64-bit signed integer, otherwise an error occurs. - * - * \param integer An Integer. - * \param value Returns the value of the Integer. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, - int64_t* value); - -/** - * Gets the value of an Integer. - * - * The integer must fit into a 64-bit unsigned integer, otherwise an - * error occurs. - * - * \param integer An Integer. - * \param value Returns the value of the Integer. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, - uint64_t* value); - -/** - * Gets the value of an integer as a hexadecimal C string. - * - * \param integer An Integer. - * \param value Returns the value of the Integer as a hexadecimal C - * string. This C string is scope allocated and is only valid until - * the next call to Dart_ExitScope. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, - const char** value); - -/** - * Returns a Double with the provided value. - * - * \param value A double. - * - * \return The Double object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewDouble(double value); - -/** - * Gets the value of a Double - * - * \param double_obj A Double - * \param value Returns the value of the Double. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, double* value); - -/** - * Returns a closure of static function 'function_name' in the class 'class_name' - * in the exported namespace of specified 'library'. - * - * \param library Library object - * \param cls_type Type object representing a Class - * \param function_name Name of the static function in the class - * - * \return A valid Dart instance if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_GetStaticMethodClosure(Dart_Handle library, - Dart_Handle cls_type, - Dart_Handle function_name); - -/* - * ======== - * Booleans - * ======== - */ - -/** - * Returns the True object. - * - * Requires there to be a current isolate. - * - * \return A handle to the True object. - */ -DART_EXPORT Dart_Handle Dart_True(); - -/** - * Returns the False object. - * - * Requires there to be a current isolate. - * - * \return A handle to the False object. - */ -DART_EXPORT Dart_Handle Dart_False(); - -/** - * Returns a Boolean with the provided value. - * - * \param value true or false. - * - * \return The Boolean object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewBoolean(bool value); - -/** - * Gets the value of a Boolean - * - * \param boolean_obj A Boolean - * \param value Returns the value of the Boolean. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, bool* value); - -/* - * ======= - * Strings - * ======= - */ - -/** - * Gets the length of a String. - * - * \param str A String. - * \param length Returns the length of the String. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* length); - -/** - * Returns a String built from the provided C string - * (There is an implicit assumption that the C string passed in contains - * UTF-8 encoded characters and '\0' is considered as a termination - * character). - * - * \param value A C String - * - * \return The String object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str); -/* TODO(turnidge): Document what happens when we run out of memory - * during this call. */ - -/** - * Returns a String built from an array of UTF-8 encoded characters. - * - * \param utf8_array An array of UTF-8 encoded characters. - * \param length The length of the codepoints array. - * - * \return The String object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, - intptr_t length); - -/** - * Returns a String built from an array of UTF-16 encoded characters. - * - * \param utf16_array An array of UTF-16 encoded characters. - * \param length The length of the codepoints array. - * - * \return The String object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, - intptr_t length); - -/** - * Returns a String built from an array of UTF-32 encoded characters. - * - * \param utf32_array An array of UTF-32 encoded characters. - * \param length The length of the codepoints array. - * - * \return The String object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array, - intptr_t length); - -/** - * Returns a String which references an external array of - * Latin-1 (ISO-8859-1) encoded characters. - * - * \param latin1_array Array of Latin-1 encoded characters. This must not move. - * \param length The length of the characters array. - * \param peer An external pointer to associate with this string. - * \param external_allocation_size The number of externally allocated - * bytes for peer. Used to inform the garbage collector. - * \param callback A callback to be called when this string is finalized. - * - * \return The String object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle -Dart_NewExternalLatin1String(const uint8_t* latin1_array, - intptr_t length, - void* peer, - intptr_t external_allocation_size, - Dart_HandleFinalizer callback); - -/** - * Returns a String which references an external array of UTF-16 encoded - * characters. - * - * \param utf16_array An array of UTF-16 encoded characters. This must not move. - * \param length The length of the characters array. - * \param peer An external pointer to associate with this string. - * \param external_allocation_size The number of externally allocated - * bytes for peer. Used to inform the garbage collector. - * \param callback A callback to be called when this string is finalized. - * - * \return The String object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle -Dart_NewExternalUTF16String(const uint16_t* utf16_array, - intptr_t length, - void* peer, - intptr_t external_allocation_size, - Dart_HandleFinalizer callback); - -/** - * Gets the C string representation of a String. - * (It is a sequence of UTF-8 encoded values with a '\0' termination.) - * - * \param str A string. - * \param cstr Returns the String represented as a C string. - * This C string is scope allocated and is only valid until - * the next call to Dart_ExitScope. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle str, - const char** cstr); - -/** - * Gets a UTF-8 encoded representation of a String. - * - * Any unpaired surrogate code points in the string will be converted as - * replacement characters (U+FFFD, 0xEF 0xBF 0xBD in UTF-8). If you need - * to preserve unpaired surrogates, use the Dart_StringToUTF16 function. - * - * \param str A string. - * \param utf8_array Returns the String represented as UTF-8 code - * units. This UTF-8 array is scope allocated and is only valid - * until the next call to Dart_ExitScope. - * \param length Used to return the length of the array which was - * actually used. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, - uint8_t** utf8_array, - intptr_t* length); - -/** - * Gets the data corresponding to the string object. This function returns - * the data only for Latin-1 (ISO-8859-1) string objects. For all other - * string objects it returns an error. - * - * \param str A string. - * \param latin1_array An array allocated by the caller, used to return - * the string data. - * \param length Used to pass in the length of the provided array. - * Used to return the length of the array which was actually used. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_StringToLatin1(Dart_Handle str, - uint8_t* latin1_array, - intptr_t* length); - -/** - * Gets the UTF-16 encoded representation of a string. - * - * \param str A string. - * \param utf16_array An array allocated by the caller, used to return - * the array of UTF-16 encoded characters. - * \param length Used to pass in the length of the provided array. - * Used to return the length of the array which was actually used. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str, - uint16_t* utf16_array, - intptr_t* length); - -/** - * Gets the storage size in bytes of a String. - * - * \param str A String. - * \param length Returns the storage size in bytes of the String. - * This is the size in bytes needed to store the String. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str, intptr_t* size); - -/** - * Retrieves some properties associated with a String. - * Properties retrieved are: - * - character size of the string (one or two byte) - * - length of the string - * - peer pointer of string if it is an external string. - * \param str A String. - * \param char_size Returns the character size of the String. - * \param str_len Returns the length of the String. - * \param peer Returns the peer pointer associated with the String or 0 if - * there is no peer pointer for it. - * \return Success if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle str, - intptr_t* char_size, - intptr_t* str_len, - void** peer); - -/* - * ===== - * Lists - * ===== - */ - -/** - * Returns a List of the desired length. - * - * \param length The length of the list. - * - * \return The List object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewList(intptr_t length); - -typedef enum { - Dart_CoreType_Dynamic, - Dart_CoreType_Int, - Dart_CoreType_String, -} Dart_CoreType_Id; - -// TODO(bkonyi): convert this to use nullable types once NNBD is enabled. -/** - * Returns a List of the desired length with the desired legacy element type. - * - * \param element_type_id The type of elements of the list. - * \param length The length of the list. - * - * \return The List object if no error occurs. Otherwise returns an error - * handle. - */ -DART_EXPORT Dart_Handle Dart_NewListOf(Dart_CoreType_Id element_type_id, - intptr_t length); - -/** - * Returns a List of the desired length with the desired element type. - * - * \param element_type Handle to a nullable type object. E.g., from - * Dart_GetType or Dart_GetNullableType. - * - * \param length The length of the list. - * - * \return The List object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewListOfType(Dart_Handle element_type, - intptr_t length); - -/** - * Returns a List of the desired length with the desired element type, filled - * with the provided object. - * - * \param element_type Handle to a type object. E.g., from Dart_GetType. - * - * \param fill_object Handle to an object of type 'element_type' that will be - * used to populate the list. This parameter can only be Dart_Null() if the - * length of the list is 0 or 'element_type' is a nullable type. - * - * \param length The length of the list. - * - * \return The List object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewListOfTypeFilled(Dart_Handle element_type, - Dart_Handle fill_object, - intptr_t length); - -/** - * Gets the length of a List. - * - * May generate an unhandled exception error. - * - * \param list A List. - * \param length Returns the length of the List. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* length); - -/** - * Gets the Object at some index of a List. - * - * If the index is out of bounds, an error occurs. - * - * May generate an unhandled exception error. - * - * \param list A List. - * \param index A valid index into the List. - * - * \return The Object in the List at the specified index if no error - * occurs. Otherwise returns an error handle. - */ -DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index); - -/** -* Gets a range of Objects from a List. -* -* If any of the requested index values are out of bounds, an error occurs. -* -* May generate an unhandled exception error. -* -* \param list A List. -* \param offset The offset of the first item to get. -* \param length The number of items to get. -* \param result A pointer to fill with the objects. -* -* \return Success if no error occurs during the operation. -*/ -DART_EXPORT Dart_Handle Dart_ListGetRange(Dart_Handle list, - intptr_t offset, - intptr_t length, - Dart_Handle* result); - -/** - * Sets the Object at some index of a List. - * - * If the index is out of bounds, an error occurs. - * - * May generate an unhandled exception error. - * - * \param array A List. - * \param index A valid index into the List. - * \param value The Object to put in the List. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, - intptr_t index, - Dart_Handle value); - -/** - * May generate an unhandled exception error. - */ -DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, - intptr_t offset, - uint8_t* native_array, - intptr_t length); - -/** - * May generate an unhandled exception error. - */ -DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, - intptr_t offset, - const uint8_t* native_array, - intptr_t length); - -/* - * ==== - * Maps - * ==== - */ - -/** - * Gets the Object at some key of a Map. - * - * May generate an unhandled exception error. - * - * \param map A Map. - * \param key An Object. - * - * \return The value in the map at the specified key, null if the map does not - * contain the key, or an error handle. - */ -DART_EXPORT Dart_Handle Dart_MapGetAt(Dart_Handle map, Dart_Handle key); - -/** - * Returns whether the Map contains a given key. - * - * May generate an unhandled exception error. - * - * \param map A Map. - * - * \return A handle on a boolean indicating whether map contains the key. - * Otherwise returns an error handle. - */ -DART_EXPORT Dart_Handle Dart_MapContainsKey(Dart_Handle map, Dart_Handle key); - -/** - * Gets the list of keys of a Map. - * - * May generate an unhandled exception error. - * - * \param map A Map. - * - * \return The list of key Objects if no error occurs. Otherwise returns an - * error handle. - */ -DART_EXPORT Dart_Handle Dart_MapKeys(Dart_Handle map); - -/* - * ========== - * Typed Data - * ========== - */ - -typedef enum { - Dart_TypedData_kByteData = 0, - Dart_TypedData_kInt8, - Dart_TypedData_kUint8, - Dart_TypedData_kUint8Clamped, - Dart_TypedData_kInt16, - Dart_TypedData_kUint16, - Dart_TypedData_kInt32, - Dart_TypedData_kUint32, - Dart_TypedData_kInt64, - Dart_TypedData_kUint64, - Dart_TypedData_kFloat32, - Dart_TypedData_kFloat64, - Dart_TypedData_kInt32x4, - Dart_TypedData_kFloat32x4, - Dart_TypedData_kFloat64x2, - Dart_TypedData_kInvalid -} Dart_TypedData_Type; - -/** - * Return type if this object is a TypedData object. - * - * \return kInvalid if the object is not a TypedData object or the appropriate - * Dart_TypedData_Type. - */ -DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object); - -/** - * Return type if this object is an external TypedData object. - * - * \return kInvalid if the object is not an external TypedData object or - * the appropriate Dart_TypedData_Type. - */ -DART_EXPORT Dart_TypedData_Type -Dart_GetTypeOfExternalTypedData(Dart_Handle object); - -/** - * Returns a TypedData object of the desired length and type. - * - * \param type The type of the TypedData object. - * \param length The length of the TypedData object (length in type units). - * - * \return The TypedData object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, - intptr_t length); - -/** - * Returns a TypedData object which references an external data array. - * - * \param type The type of the data array. - * \param data A data array. This array must not move. - * \param length The length of the data array (length in type units). - * - * \return The TypedData object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewExternalTypedData(Dart_TypedData_Type type, - void* data, - intptr_t length); - -/** - * Returns a TypedData object which references an external data array. - * - * \param type The type of the data array. - * \param data A data array. This array must not move. - * \param length The length of the data array (length in type units). - * \param peer A pointer to a native object or NULL. This value is - * provided to callback when it is invoked. - * \param external_allocation_size The number of externally allocated - * bytes for peer. Used to inform the garbage collector. - * \param callback A function pointer that will be invoked sometime - * after the object is garbage collected, unless the handle has been deleted. - * A valid callback needs to be specified it cannot be NULL. - * - * \return The TypedData object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle -Dart_NewExternalTypedDataWithFinalizer(Dart_TypedData_Type type, - void* data, - intptr_t length, - void* peer, - intptr_t external_allocation_size, - Dart_HandleFinalizer callback); - -/** - * Returns a ByteBuffer object for the typed data. - * - * \param type_data The TypedData object. - * - * \return The ByteBuffer object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_NewByteBuffer(Dart_Handle typed_data); - -/** - * Acquires access to the internal data address of a TypedData object. - * - * \param object The typed data object whose internal data address is to - * be accessed. - * \param type The type of the object is returned here. - * \param data The internal data address is returned here. - * \param len Size of the typed array is returned here. - * - * Notes: - * When the internal address of the object is acquired any calls to a - * Dart API function that could potentially allocate an object or run - * any Dart code will return an error. - * - * Any Dart API functions for accessing the data should not be called - * before the corresponding release. In particular, the object should - * not be acquired again before its release. This leads to undefined - * behavior. - * - * \return Success if the internal data address is acquired successfully. - * Otherwise, returns an error handle. - */ -DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, - Dart_TypedData_Type* type, - void** data, - intptr_t* len); - -/** - * Releases access to the internal data address that was acquired earlier using - * Dart_TypedDataAcquireData. - * - * \param object The typed data object whose internal data address is to be - * released. - * - * \return Success if the internal data address is released successfully. - * Otherwise, returns an error handle. - */ -DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object); - -/** - * Returns the TypedData object associated with the ByteBuffer object. - * - * \param byte_buffer The ByteBuffer object. - * - * \return The TypedData object if no error occurs. Otherwise returns - * an error handle. - */ -DART_EXPORT Dart_Handle Dart_GetDataFromByteBuffer(Dart_Handle byte_buffer); - -/* - * ============================================================ - * Invoking Constructors, Methods, Closures and Field accessors - * ============================================================ - */ - -/** - * Invokes a constructor, creating a new object. - * - * This function allows hidden constructors (constructors with leading - * underscores) to be called. - * - * \param type Type of object to be constructed. - * \param constructor_name The name of the constructor to invoke. Use - * Dart_Null() or Dart_EmptyString() to invoke the unnamed constructor. - * This name should not include the name of the class. - * \param number_of_arguments Size of the arguments array. - * \param arguments An array of arguments to the constructor. - * - * \return If the constructor is called and completes successfully, - * then the new object. If an error occurs during execution, then an - * error handle is returned. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_New(Dart_Handle type, - Dart_Handle constructor_name, - int number_of_arguments, - Dart_Handle* arguments); - -/** - * Allocate a new object without invoking a constructor. - * - * \param type The type of an object to be allocated. - * - * \return The new object. If an error occurs during execution, then an - * error handle is returned. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_Allocate(Dart_Handle type); - -/** - * Allocate a new object without invoking a constructor, and sets specified - * native fields. - * - * \param type The type of an object to be allocated. - * \param num_native_fields The number of native fields to set. - * \param native_fields An array containing the value of native fields. - * - * \return The new object. If an error occurs during execution, then an - * error handle is returned. - */ -DART_EXPORT Dart_Handle -Dart_AllocateWithNativeFields(Dart_Handle type, - intptr_t num_native_fields, - const intptr_t* native_fields); - -/** - * Invokes a method or function. - * - * The 'target' parameter may be an object, type, or library. If - * 'target' is an object, then this function will invoke an instance - * method. If 'target' is a type, then this function will invoke a - * static method. If 'target' is a library, then this function will - * invoke a top-level function from that library. - * NOTE: This API call cannot be used to invoke methods of a type object. - * - * This function ignores visibility (leading underscores in names). - * - * May generate an unhandled exception error. - * - * \param target An object, type, or library. - * \param name The name of the function or method to invoke. - * \param number_of_arguments Size of the arguments array. - * \param arguments An array of arguments to the function. - * - * \return If the function or method is called and completes - * successfully, then the return value is returned. If an error - * occurs during execution, then an error handle is returned. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_Invoke(Dart_Handle target, - Dart_Handle name, - int number_of_arguments, - Dart_Handle* arguments); -/* TODO(turnidge): Document how to invoke operators. */ - -/** - * Invokes a Closure with the given arguments. - * - * May generate an unhandled exception error. - * - * \return If no error occurs during execution, then the result of - * invoking the closure is returned. If an error occurs during - * execution, then an error handle is returned. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_InvokeClosure(Dart_Handle closure, - int number_of_arguments, - Dart_Handle* arguments); - -/** - * Invokes a Generative Constructor on an object that was previously - * allocated using Dart_Allocate/Dart_AllocateWithNativeFields. - * - * The 'target' parameter must be an object. - * - * This function ignores visibility (leading underscores in names). - * - * May generate an unhandled exception error. - * - * \param target An object. - * \param name The name of the constructor to invoke. - * Use Dart_Null() or Dart_EmptyString() to invoke the unnamed constructor. - * \param number_of_arguments Size of the arguments array. - * \param arguments An array of arguments to the function. - * - * \return If the constructor is called and completes - * successfully, then the object is returned. If an error - * occurs during execution, then an error handle is returned. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_InvokeConstructor(Dart_Handle object, - Dart_Handle name, - int number_of_arguments, - Dart_Handle* arguments); - -/** - * Gets the value of a field. - * - * The 'container' parameter may be an object, type, or library. If - * 'container' is an object, then this function will access an - * instance field. If 'container' is a type, then this function will - * access a static field. If 'container' is a library, then this - * function will access a top-level variable. - * NOTE: This API call cannot be used to access fields of a type object. - * - * This function ignores field visibility (leading underscores in names). - * - * May generate an unhandled exception error. - * - * \param container An object, type, or library. - * \param name A field name. - * - * \return If no error occurs, then the value of the field is - * returned. Otherwise an error handle is returned. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_GetField(Dart_Handle container, Dart_Handle name); - -/** - * Sets the value of a field. - * - * The 'container' parameter may actually be an object, type, or - * library. If 'container' is an object, then this function will - * access an instance field. If 'container' is a type, then this - * function will access a static field. If 'container' is a library, - * then this function will access a top-level variable. - * NOTE: This API call cannot be used to access fields of a type object. - * - * This function ignores field visibility (leading underscores in names). - * - * May generate an unhandled exception error. - * - * \param container An object, type, or library. - * \param name A field name. - * \param value The new field value. - * - * \return A valid handle if no error occurs. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_SetField(Dart_Handle container, Dart_Handle name, Dart_Handle value); - -/* - * ========== - * Exceptions - * ========== - */ - -/* - * TODO(turnidge): Remove these functions from the api and replace all - * uses with Dart_NewUnhandledExceptionError. */ - -/** - * Throws an exception. - * - * This function causes a Dart language exception to be thrown. This - * will proceed in the standard way, walking up Dart frames until an - * appropriate 'catch' block is found, executing 'finally' blocks, - * etc. - * - * If an error handle is passed into this function, the error is - * propagated immediately. See Dart_PropagateError for a discussion - * of error propagation. - * - * If successful, this function does not return. Note that this means - * that the destructors of any stack-allocated C++ objects will not be - * called. If there are no Dart frames on the stack, an error occurs. - * - * \return An error handle if the exception was not thrown. - * Otherwise the function does not return. - */ -DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception); - -/** - * Rethrows an exception. - * - * Rethrows an exception, unwinding all dart frames on the stack. If - * successful, this function does not return. Note that this means - * that the destructors of any stack-allocated C++ objects will not be - * called. If there are no Dart frames on the stack, an error occurs. - * - * \return An error handle if the exception was not thrown. - * Otherwise the function does not return. - */ -DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, - Dart_Handle stacktrace); - -/* - * =========================== - * Native fields and functions - * =========================== - */ - -/** - * Gets the number of native instance fields in an object. - */ -DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, - int* count); - -/** - * Gets the value of a native field. - * - * TODO(turnidge): Document. - */ -DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, - int index, - intptr_t* value); - -/** - * Sets the value of a native field. - * - * TODO(turnidge): Document. - */ -DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, - int index, - intptr_t value); - -/** - * The arguments to a native function. - * - * This object is passed to a native function to represent its - * arguments and return value. It allows access to the arguments to a - * native function by index. It also allows the return value of a - * native function to be set. - */ -typedef struct _Dart_NativeArguments* Dart_NativeArguments; - -/** - * Extracts current isolate group data from the native arguments structure. - */ -DART_EXPORT void* Dart_GetNativeIsolateGroupData(Dart_NativeArguments args); - -typedef enum { - Dart_NativeArgument_kBool = 0, - Dart_NativeArgument_kInt32, - Dart_NativeArgument_kUint32, - Dart_NativeArgument_kInt64, - Dart_NativeArgument_kUint64, - Dart_NativeArgument_kDouble, - Dart_NativeArgument_kString, - Dart_NativeArgument_kInstance, - Dart_NativeArgument_kNativeFields, -} Dart_NativeArgument_Type; - -typedef struct _Dart_NativeArgument_Descriptor { - uint8_t type; - uint8_t index; -} Dart_NativeArgument_Descriptor; - -typedef union _Dart_NativeArgument_Value { - bool as_bool; - int32_t as_int32; - uint32_t as_uint32; - int64_t as_int64; - uint64_t as_uint64; - double as_double; - struct { - Dart_Handle dart_str; - void* peer; - } as_string; - struct { - intptr_t num_fields; - intptr_t* values; - } as_native_fields; - Dart_Handle as_instance; -} Dart_NativeArgument_Value; - -enum { - kNativeArgNumberPos = 0, - kNativeArgNumberSize = 8, - kNativeArgTypePos = kNativeArgNumberPos + kNativeArgNumberSize, - kNativeArgTypeSize = 8, -}; - -#define BITMASK(size) ((1 << size) - 1) -#define DART_NATIVE_ARG_DESCRIPTOR(type, position) \ - (((type & BITMASK(kNativeArgTypeSize)) << kNativeArgTypePos) | \ - (position & BITMASK(kNativeArgNumberSize))) - -/** - * Gets the native arguments based on the types passed in and populates - * the passed arguments buffer with appropriate native values. - * - * \param args the Native arguments block passed into the native call. - * \param num_arguments length of argument descriptor array and argument - * values array passed in. - * \param arg_descriptors an array that describes the arguments that - * need to be retrieved. For each argument to be retrieved the descriptor - * contains the argument number (0, 1 etc.) and the argument type - * described using Dart_NativeArgument_Type, e.g: - * DART_NATIVE_ARG_DESCRIPTOR(Dart_NativeArgument_kBool, 1) indicates - * that the first argument is to be retrieved and it should be a boolean. - * \param arg_values array into which the native arguments need to be - * extracted into, the array is allocated by the caller (it could be - * stack allocated to avoid the malloc/free performance overhead). - * - * \return Success if all the arguments could be extracted correctly, - * returns an error handle if there were any errors while extracting the - * arguments (mismatched number of arguments, incorrect types, etc.). - */ -DART_EXPORT Dart_Handle -Dart_GetNativeArguments(Dart_NativeArguments args, - int num_arguments, - const Dart_NativeArgument_Descriptor* arg_descriptors, - Dart_NativeArgument_Value* arg_values); - -/** - * Gets the native argument at some index. - */ -DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, - int index); -/* TODO(turnidge): Specify the behavior of an out-of-bounds access. */ - -/** - * Gets the number of native arguments. - */ -DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args); - -/** - * Gets all the native fields of the native argument at some index. - * \param args Native arguments structure. - * \param arg_index Index of the desired argument in the structure above. - * \param num_fields size of the intptr_t array 'field_values' passed in. - * \param field_values intptr_t array in which native field values are returned. - * \return Success if the native fields where copied in successfully. Otherwise - * returns an error handle. On success the native field values are copied - * into the 'field_values' array, if the argument at 'arg_index' is a - * null object then 0 is copied as the native field values into the - * 'field_values' array. - */ -DART_EXPORT Dart_Handle -Dart_GetNativeFieldsOfArgument(Dart_NativeArguments args, - int arg_index, - int num_fields, - intptr_t* field_values); - -/** - * Gets the native field of the receiver. - */ -DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, - intptr_t* value); - -/** - * Gets a string native argument at some index. - * \param args Native arguments structure. - * \param arg_index Index of the desired argument in the structure above. - * \param peer Returns the peer pointer if the string argument has one. - * \return Success if the string argument has a peer, if it does not - * have a peer then the String object is returned. Otherwise returns - * an error handle (argument is not a String object). - */ -DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, - int arg_index, - void** peer); - -/** - * Gets an integer native argument at some index. - * \param args Native arguments structure. - * \param arg_index Index of the desired argument in the structure above. - * \param value Returns the integer value if the argument is an Integer. - * \return Success if no error occurs. Otherwise returns an error handle. - */ -DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, - int index, - int64_t* value); - -/** - * Gets a boolean native argument at some index. - * \param args Native arguments structure. - * \param arg_index Index of the desired argument in the structure above. - * \param value Returns the boolean value if the argument is a Boolean. - * \return Success if no error occurs. Otherwise returns an error handle. - */ -DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, - int index, - bool* value); - -/** - * Gets a double native argument at some index. - * \param args Native arguments structure. - * \param arg_index Index of the desired argument in the structure above. - * \param value Returns the double value if the argument is a double. - * \return Success if no error occurs. Otherwise returns an error handle. - */ -DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, - int index, - double* value); - -/** - * Sets the return value for a native function. - * - * If retval is an Error handle, then error will be propagated once - * the native functions exits. See Dart_PropagateError for a - * discussion of how different types of errors are propagated. - */ -DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, - Dart_Handle retval); - -DART_EXPORT void Dart_SetWeakHandleReturnValue(Dart_NativeArguments args, - Dart_WeakPersistentHandle rval); - -DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, - bool retval); - -DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, - int64_t retval); - -DART_EXPORT void Dart_SetDoubleReturnValue(Dart_NativeArguments args, - double retval); - -/** - * A native function. - */ -typedef void (*Dart_NativeFunction)(Dart_NativeArguments arguments); - -/** - * Native entry resolution callback. - * - * For libraries and scripts which have native functions, the embedder - * can provide a native entry resolver. This callback is used to map a - * name/arity to a Dart_NativeFunction. If no function is found, the - * callback should return NULL. - * - * The parameters to the native resolver function are: - * \param name a Dart string which is the name of the native function. - * \param num_of_arguments is the number of arguments expected by the - * native function. - * \param auto_setup_scope is a boolean flag that can be set by the resolver - * to indicate if this function needs a Dart API scope (see Dart_EnterScope/ - * Dart_ExitScope) to be setup automatically by the VM before calling into - * the native function. By default most native functions would require this - * to be true but some light weight native functions which do not call back - * into the VM through the Dart API may not require a Dart scope to be - * setup automatically. - * - * \return A valid Dart_NativeFunction which resolves to a native entry point - * for the native function. - * - * See Dart_SetNativeResolver. - */ -typedef Dart_NativeFunction (*Dart_NativeEntryResolver)(Dart_Handle name, - int num_of_arguments, - bool* auto_setup_scope); -/* TODO(turnidge): Consider renaming to NativeFunctionResolver or - * NativeResolver. */ - -/** - * Native entry symbol lookup callback. - * - * For libraries and scripts which have native functions, the embedder - * can provide a callback for mapping a native entry to a symbol. This callback - * maps a native function entry PC to the native function name. If no native - * entry symbol can be found, the callback should return NULL. - * - * The parameters to the native reverse resolver function are: - * \param nf A Dart_NativeFunction. - * - * \return A const UTF-8 string containing the symbol name or NULL. - * - * See Dart_SetNativeResolver. - */ -typedef const uint8_t* (*Dart_NativeEntrySymbol)(Dart_NativeFunction nf); - -/* - * =========== - * Environment - * =========== - */ - -/** - * An environment lookup callback function. - * - * \param name The name of the value to lookup in the environment. - * - * \return A valid handle to a string if the name exists in the - * current environment or Dart_Null() if not. - */ -typedef Dart_Handle (*Dart_EnvironmentCallback)(Dart_Handle name); - -/** - * Sets the environment callback for the current isolate. This - * callback is used to lookup environment values by name in the - * current environment. This enables the embedder to supply values for - * the const constructors bool.fromEnvironment, int.fromEnvironment - * and String.fromEnvironment. - */ -DART_EXPORT Dart_Handle -Dart_SetEnvironmentCallback(Dart_EnvironmentCallback callback); - -/** - * Sets the callback used to resolve native functions for a library. - * - * \param library A library. - * \param resolver A native entry resolver. - * - * \return A valid handle if the native resolver was set successfully. - */ -DART_EXPORT Dart_Handle -Dart_SetNativeResolver(Dart_Handle library, - Dart_NativeEntryResolver resolver, - Dart_NativeEntrySymbol symbol); -/* TODO(turnidge): Rename to Dart_LibrarySetNativeResolver? */ - -/** - * Returns the callback used to resolve native functions for a library. - * - * \param library A library. - * \param resolver a pointer to a Dart_NativeEntryResolver - * - * \return A valid handle if the library was found. - */ -DART_EXPORT Dart_Handle -Dart_GetNativeResolver(Dart_Handle library, Dart_NativeEntryResolver* resolver); - -/** - * Returns the callback used to resolve native function symbols for a library. - * - * \param library A library. - * \param resolver a pointer to a Dart_NativeEntrySymbol. - * - * \return A valid handle if the library was found. - */ -DART_EXPORT Dart_Handle Dart_GetNativeSymbol(Dart_Handle library, - Dart_NativeEntrySymbol* resolver); - -/* - * ===================== - * Scripts and Libraries - * ===================== - */ - -typedef enum { - Dart_kCanonicalizeUrl = 0, - Dart_kImportTag, - Dart_kKernelTag, - Dart_kImportExtensionTag, -} Dart_LibraryTag; - -/** - * The library tag handler is a multi-purpose callback provided by the - * embedder to the Dart VM. The embedder implements the tag handler to - * provide the ability to load Dart scripts and imports. - * - * -- TAGS -- - * - * Dart_kCanonicalizeUrl - * - * This tag indicates that the embedder should canonicalize 'url' with - * respect to 'library'. For most embedders, the - * Dart_DefaultCanonicalizeUrl function is a sufficient implementation - * of this tag. The return value should be a string holding the - * canonicalized url. - * - * Dart_kImportTag - * - * This tag is used to load a library from IsolateMirror.loadUri. The embedder - * should call Dart_LoadLibraryFromKernel to provide the library to the VM. The - * return value should be an error or library (the result from - * Dart_LoadLibraryFromKernel). - * - * Dart_kKernelTag - * - * This tag is used to load the intermediate file (kernel) generated by - * the Dart front end. This tag is typically used when a 'hot-reload' - * of an application is needed and the VM is 'use dart front end' mode. - * The dart front end typically compiles all the scripts, imports and part - * files into one intermediate file hence we don't use the source/import or - * script tags. The return value should be an error or a TypedData containing - * the kernel bytes. - * - * Dart_kImportExtensionTag - * - * This tag is used to load an external import (shared object file). The - * extension path must have the scheme 'dart-ext:'. - */ -typedef Dart_Handle (*Dart_LibraryTagHandler)( - Dart_LibraryTag tag, - Dart_Handle library_or_package_map_url, - Dart_Handle url); - -/** - * Sets library tag handler for the current isolate. This handler is - * used to handle the various tags encountered while loading libraries - * or scripts in the isolate. - * - * \param handler Handler code to be used for handling the various tags - * encountered while loading libraries or scripts in the isolate. - * - * \return If no error occurs, the handler is set for the isolate. - * Otherwise an error handle is returned. - * - * TODO(turnidge): Document. - */ -DART_EXPORT Dart_Handle -Dart_SetLibraryTagHandler(Dart_LibraryTagHandler handler); - -/** - * Handles deferred loading requests. When this handler is invoked, it should - * eventually load the deferred loading unit with the given id and call - * Dart_DeferredLoadComplete or Dart_DeferredLoadCompleteError. It is - * recommended that the loading occur asynchronously, but it is permitted to - * call Dart_DeferredLoadComplete or Dart_DeferredLoadCompleteError before the - * handler returns. - * - * If an error is returned, it will be propogated through - * `prefix.loadLibrary()`. This is useful for synchronous - * implementations, which must propogate any unwind errors from - * Dart_DeferredLoadComplete or Dart_DeferredLoadComplete. Otherwise the handler - * should return a non-error such as `Dart_Null()`. - */ -typedef Dart_Handle (*Dart_DeferredLoadHandler)(intptr_t loading_unit_id); - -/** - * Sets the deferred load handler for the current isolate. This handler is - * used to handle loading deferred imports in an AppJIT or AppAOT program. - */ -DART_EXPORT Dart_Handle -Dart_SetDeferredLoadHandler(Dart_DeferredLoadHandler handler); - -/** - * Notifies the VM that a deferred load completed successfully. This function - * will eventually cause the corresponding `prefix.loadLibrary()` futures to - * complete. - * - * Requires the current isolate to be the same current isolate during the - * invocation of the Dart_DeferredLoadHandler. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_DeferredLoadComplete(intptr_t loading_unit_id, - const uint8_t* snapshot_data, - const uint8_t* snapshot_instructions); - -/** - * Notifies the VM that a deferred load failed. This function - * will eventually cause the corresponding `prefix.loadLibrary()` futures to - * complete with an error. - * - * If `transient` is true, future invocations of `prefix.loadLibrary()` will - * trigger new load requests. If false, futures invocation will complete with - * the same error. - * - * Requires the current isolate to be the same current isolate during the - * invocation of the Dart_DeferredLoadHandler. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_DeferredLoadCompleteError(intptr_t loading_unit_id, - const char* error_message, - bool transient); - -/** - * Canonicalizes a url with respect to some library. - * - * The url is resolved with respect to the library's url and some url - * normalizations are performed. - * - * This canonicalization function should be sufficient for most - * embedders to implement the Dart_kCanonicalizeUrl tag. - * - * \param base_url The base url relative to which the url is - * being resolved. - * \param url The url being resolved and canonicalized. This - * parameter is a string handle. - * - * \return If no error occurs, a String object is returned. Otherwise - * an error handle is returned. - */ -DART_EXPORT Dart_Handle Dart_DefaultCanonicalizeUrl(Dart_Handle base_url, - Dart_Handle url); - -/** - * Loads the root library for the current isolate. - * - * Requires there to be no current root library. - * - * \param buffer A buffer which contains a kernel binary (see - * pkg/kernel/binary.md). Must remain valid until isolate group shutdown. - * \param buffer_size Length of the passed in buffer. - * - * \return A handle to the root library, or an error. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_LoadScriptFromKernel(const uint8_t* kernel_buffer, intptr_t kernel_size); - -/** - * Gets the library for the root script for the current isolate. - * - * If the root script has not yet been set for the current isolate, - * this function returns Dart_Null(). This function never returns an - * error handle. - * - * \return Returns the root Library for the current isolate or Dart_Null(). - */ -DART_EXPORT Dart_Handle Dart_RootLibrary(); - -/** - * Sets the root library for the current isolate. - * - * \return Returns an error handle if `library` is not a library handle. - */ -DART_EXPORT Dart_Handle Dart_SetRootLibrary(Dart_Handle library); - -/** - * Lookup or instantiate a legacy type by name and type arguments from a - * Library. - * - * \param library The library containing the class or interface. - * \param class_name The class name for the type. - * \param number_of_type_arguments Number of type arguments. - * For non parametric types the number of type arguments would be 0. - * \param type_arguments Pointer to an array of type arguments. - * For non parameteric types a NULL would be passed in for this argument. - * - * \return If no error occurs, the type is returned. - * Otherwise an error handle is returned. - */ -DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library, - Dart_Handle class_name, - intptr_t number_of_type_arguments, - Dart_Handle* type_arguments); - -/** - * Lookup or instantiate a nullable type by name and type arguments from - * Library. - * - * \param library The library containing the class or interface. - * \param class_name The class name for the type. - * \param number_of_type_arguments Number of type arguments. - * For non parametric types the number of type arguments would be 0. - * \param type_arguments Pointer to an array of type arguments. - * For non parameteric types a NULL would be passed in for this argument. - * - * \return If no error occurs, the type is returned. - * Otherwise an error handle is returned. - */ -DART_EXPORT Dart_Handle Dart_GetNullableType(Dart_Handle library, - Dart_Handle class_name, - intptr_t number_of_type_arguments, - Dart_Handle* type_arguments); - -/** - * Lookup or instantiate a non-nullable type by name and type arguments from - * Library. - * - * \param library The library containing the class or interface. - * \param class_name The class name for the type. - * \param number_of_type_arguments Number of type arguments. - * For non parametric types the number of type arguments would be 0. - * \param type_arguments Pointer to an array of type arguments. - * For non parameteric types a NULL would be passed in for this argument. - * - * \return If no error occurs, the type is returned. - * Otherwise an error handle is returned. - */ -DART_EXPORT Dart_Handle -Dart_GetNonNullableType(Dart_Handle library, - Dart_Handle class_name, - intptr_t number_of_type_arguments, - Dart_Handle* type_arguments); - -/** - * Creates a nullable version of the provided type. - * - * \param type The type to be converted to a nullable type. - * - * \return If no error occurs, a nullable type is returned. - * Otherwise an error handle is returned. - */ -DART_EXPORT Dart_Handle Dart_TypeToNullableType(Dart_Handle type); - -/** - * Creates a non-nullable version of the provided type. - * - * \param type The type to be converted to a non-nullable type. - * - * \return If no error occurs, a non-nullable type is returned. - * Otherwise an error handle is returned. - */ -DART_EXPORT Dart_Handle Dart_TypeToNonNullableType(Dart_Handle type); - -/** - * A type's nullability. - * - * \param type A Dart type. - * \param result An out parameter containing the result of the check. True if - * the type is of the specified nullability, false otherwise. - * - * \return Returns an error handle if type is not of type Type. - */ -DART_EXPORT Dart_Handle Dart_IsNullableType(Dart_Handle type, bool* result); -DART_EXPORT Dart_Handle Dart_IsNonNullableType(Dart_Handle type, bool* result); -DART_EXPORT Dart_Handle Dart_IsLegacyType(Dart_Handle type, bool* result); - -/** - * Lookup a class or interface by name from a Library. - * - * \param library The library containing the class or interface. - * \param class_name The name of the class or interface. - * - * \return If no error occurs, the class or interface is - * returned. Otherwise an error handle is returned. - */ -DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, - Dart_Handle class_name); -/* TODO(asiva): The above method needs to be removed once all uses - * of it are removed from the embedder code. */ - -/** - * Returns an import path to a Library, such as "file:///test.dart" or - * "dart:core". - */ -DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library); - -/** - * Returns a URL from which a Library was loaded. - */ -DART_EXPORT Dart_Handle Dart_LibraryResolvedUrl(Dart_Handle library); - -/** - * \return An array of libraries. - */ -DART_EXPORT Dart_Handle Dart_GetLoadedLibraries(); - -DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url); -/* TODO(turnidge): Consider returning Dart_Null() when the library is - * not found to distinguish that from a true error case. */ - -/** - * Report an loading error for the library. - * - * \param library The library that failed to load. - * \param error The Dart error instance containing the load error. - * - * \return If the VM handles the error, the return value is - * a null handle. If it doesn't handle the error, the error - * object is returned. - */ -DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library, - Dart_Handle error); - -/** - * Called by the embedder to load a partial program. Does not set the root - * library. - * - * \param buffer A buffer which contains a kernel binary (see - * pkg/kernel/binary.md). Must remain valid until isolate shutdown. - * \param buffer_size Length of the passed in buffer. - * - * \return A handle to the main library of the compilation unit, or an error. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_LoadLibraryFromKernel(const uint8_t* kernel_buffer, - intptr_t kernel_buffer_size); - -/** - * Returns a flattened list of pairs. The first element in each pair is the - * importing library and and the second element is the imported library for each - * import in the isolate of a library whose URI's scheme is [scheme]. - * - * Requires there to be a current isolate. - * - * \return A handle to a list of flattened pairs of importer-importee. - */ -DART_EXPORT Dart_Handle Dart_GetImportsOfScheme(Dart_Handle scheme); - -/** - * Indicates that all outstanding load requests have been satisfied. - * This finalizes all the new classes loaded and optionally completes - * deferred library futures. - * - * Requires there to be a current isolate. - * - * \param complete_futures Specify true if all deferred library - * futures should be completed, false otherwise. - * - * \return Success if all classes have been finalized and deferred library - * futures are completed. Otherwise, returns an error. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_FinalizeLoading(bool complete_futures); - -/* - * ===== - * Peers - * ===== - */ - -/** - * The peer field is a lazily allocated field intended for storage of - * an uncommonly used values. Most instances types can have a peer - * field allocated. The exceptions are subtypes of Null, num, and - * bool. - */ - -/** - * Returns the value of peer field of 'object' in 'peer'. - * - * \param object An object. - * \param peer An out parameter that returns the value of the peer - * field. - * - * \return Returns an error if 'object' is a subtype of Null, num, or - * bool. - */ -DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer); - -/** - * Sets the value of the peer field of 'object' to the value of - * 'peer'. - * - * \param object An object. - * \param peer A value to store in the peer field. - * - * \return Returns an error if 'object' is a subtype of Null, num, or - * bool. - */ -DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer); - -/* - * ====== - * Kernel - * ====== - */ - -/** - * Experimental support for Dart to Kernel parser isolate. - * - * TODO(hausner): Document finalized interface. - * - */ - -// TODO(33433): Remove kernel service from the embedding API. - -typedef enum { - Dart_KernelCompilationStatus_Unknown = -1, - Dart_KernelCompilationStatus_Ok = 0, - Dart_KernelCompilationStatus_Error = 1, - Dart_KernelCompilationStatus_Crash = 2, -} Dart_KernelCompilationStatus; - -typedef struct { - Dart_KernelCompilationStatus status; - bool null_safety; - char* error; - uint8_t* kernel; - intptr_t kernel_size; -} Dart_KernelCompilationResult; - -DART_EXPORT bool Dart_IsKernelIsolate(Dart_Isolate isolate); -DART_EXPORT bool Dart_KernelIsolateIsRunning(); -DART_EXPORT Dart_Port Dart_KernelPort(); - -/** - * Compiles the given `script_uri` to a kernel file. - * - * \param platform_kernel A buffer containing the kernel of the platform (e.g. - * `vm_platform_strong.dill`). The VM does not take ownership of this memory. - * - * \param platform_kernel_size The length of the platform_kernel buffer. - * - * \return Returns the result of the compilation. - * - * On a successful compilation the returned [Dart_KernelCompilationResult] has - * a status of [Dart_KernelCompilationStatus_Ok] and the `kernel`/`kernel_size` - * fields are set. The caller takes ownership of the malloc()ed buffer. - * - * On a failed compilation the `error` might be set describing the reason for - * the failed compilation. The caller takes ownership of the malloc()ed - * error. - * - * Requires there to be a current isolate. - */ -DART_EXPORT Dart_KernelCompilationResult -Dart_CompileToKernel(const char* script_uri, - const uint8_t* platform_kernel, - const intptr_t platform_kernel_size, - bool incremental_compile, - const char* package_config); - -typedef struct { - const char* uri; - const char* source; -} Dart_SourceFile; - -DART_EXPORT Dart_KernelCompilationResult Dart_KernelListDependencies(); - -/** - * Sets the kernel buffer which will be used to load Dart SDK sources - * dynamically at runtime. - * - * \param platform_kernel A buffer containing kernel which has sources for the - * Dart SDK populated. Note: The VM does not take ownership of this memory. - * - * \param platform_kernel_size The length of the platform_kernel buffer. - */ -DART_EXPORT void Dart_SetDartLibrarySourcesKernel( - const uint8_t* platform_kernel, - const intptr_t platform_kernel_size); - -/** - * Detect the null safety opt-in status. - * - * When running from source, it is based on the opt-in status of `script_uri`. - * When running from a kernel buffer, it is based on the mode used when - * generating `kernel_buffer`. - * When running from an appJIT or AOT snapshot, it is based on the mode used - * when generating `snapshot_data`. - * - * \param script_uri Uri of the script that contains the source code - * - * \param package_config Uri of the package configuration file (either in format - * of .packages or .dart_tool/package_config.json) for the null safety - * detection to resolve package imports against. If this parameter is not - * passed the package resolution of the parent isolate should be used. - * - * \param original_working_directory current working directory when the VM - * process was launched, this is used to correctly resolve the path specified - * for package_config. - * - * \param snapshot_data - * - * \param snapshot_instructions Buffers containing a snapshot of the - * isolate or NULL if no snapshot is provided. If provided, the buffers must - * remain valid until the isolate shuts down. - * - * \param kernel_buffer - * - * \param kernel_buffer_size A buffer which contains a kernel/DIL program. Must - * remain valid until isolate shutdown. - * - * \return Returns true if the null safety is opted in by the input being - * run `script_uri`, `snapshot_data` or `kernel_buffer`. - * - */ -DART_EXPORT bool Dart_DetectNullSafety(const char* script_uri, - const char* package_config, - const char* original_working_directory, - const uint8_t* snapshot_data, - const uint8_t* snapshot_instructions, - const uint8_t* kernel_buffer, - intptr_t kernel_buffer_size); - -#define DART_KERNEL_ISOLATE_NAME "kernel-service" - -/* - * ======= - * Service - * ======= - */ - -#define DART_VM_SERVICE_ISOLATE_NAME "vm-service" - -/** - * Returns true if isolate is the service isolate. - * - * \param isolate An isolate - * - * \return Returns true if 'isolate' is the service isolate. - */ -DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate); - -/** - * Writes the CPU profile to the timeline as a series of 'instant' events. - * - * Note that this is an expensive operation. - * - * \param main_port The main port of the Isolate whose profile samples to write. - * \param error An optional error, must be free()ed by caller. - * - * \return Returns true if the profile is successfully written and false - * otherwise. - */ -DART_EXPORT bool Dart_WriteProfileToTimeline(Dart_Port main_port, char** error); - -/* - * ==================== - * Compilation Feedback - * ==================== - */ - -/** - * Record all functions which have been compiled in the current isolate. - * - * \param buffer Returns a pointer to a buffer containing the trace. - * This buffer is scope allocated and is only valid until the next call to - * Dart_ExitScope. - * \param size Returns the size of the buffer. - * \return Returns an valid handle upon success. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_SaveCompilationTrace(uint8_t** buffer, intptr_t* buffer_length); - -/** - * Compile all functions from data from Dart_SaveCompilationTrace. Unlike JIT - * feedback, this data is fuzzy: loading does not need to happen in the exact - * program that was saved, the saver and loader do not need to agree on checked - * mode versus production mode or debug/release/product. - * - * \return Returns an error handle if a compilation error was encountered. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_LoadCompilationTrace(uint8_t* buffer, intptr_t buffer_length); - -/** - * Record runtime feedback for the current isolate, including type feedback - * and usage counters. - * - * \param buffer Returns a pointer to a buffer containing the trace. - * This buffer is scope allocated and is only valid until the next call to - * Dart_ExitScope. - * \param size Returns the size of the buffer. - * \return Returns an valid handle upon success. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_SaveTypeFeedback(uint8_t** buffer, intptr_t* buffer_length); - -/** - * Compile functions using data from Dart_SaveTypeFeedback. The data must from a - * VM with the same version and compiler flags. - * - * \return Returns an error handle if a compilation error was encountered or a - * version mismatch is detected. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_LoadTypeFeedback(uint8_t* buffer, intptr_t buffer_length); - -/* - * ============== - * Precompilation - * ============== - */ - -/** - * Compiles all functions reachable from entry points and marks - * the isolate to disallow future compilation. - * - * Entry points should be specified using `@pragma("vm:entry-point")` - * annotation. - * - * \return An error handle if a compilation error or runtime error running const - * constructors was encountered. - */ -DART_EXPORT Dart_Handle Dart_Precompile(); - -typedef void (*Dart_CreateLoadingUnitCallback)( - void* callback_data, - intptr_t loading_unit_id, - void** write_callback_data, - void** write_debug_callback_data); -typedef void (*Dart_StreamingWriteCallback)(void* callback_data, - const uint8_t* buffer, - intptr_t size); -typedef void (*Dart_StreamingCloseCallback)(void* callback_data); - -DART_EXPORT Dart_Handle Dart_LoadingUnitLibraryUris(intptr_t loading_unit_id); - -// On Darwin systems, 'dlsym' adds an '_' to the beginning of the symbol name. -// Use the '...CSymbol' definitions for resolving through 'dlsym'. The actual -// symbol names in the objects are given by the '...AsmSymbol' definitions. -#if defined(__APPLE__) -#define kSnapshotBuildIdCSymbol "kDartSnapshotBuildId" -#define kVmSnapshotDataCSymbol "kDartVmSnapshotData" -#define kVmSnapshotInstructionsCSymbol "kDartVmSnapshotInstructions" -#define kVmSnapshotBssCSymbol "kDartVmSnapshotBss" -#define kIsolateSnapshotDataCSymbol "kDartIsolateSnapshotData" -#define kIsolateSnapshotInstructionsCSymbol "kDartIsolateSnapshotInstructions" -#define kIsolateSnapshotBssCSymbol "kDartIsolateSnapshotBss" -#else -#define kSnapshotBuildIdCSymbol "_kDartSnapshotBuildId" -#define kVmSnapshotDataCSymbol "_kDartVmSnapshotData" -#define kVmSnapshotInstructionsCSymbol "_kDartVmSnapshotInstructions" -#define kVmSnapshotBssCSymbol "_kDartVmSnapshotBss" -#define kIsolateSnapshotDataCSymbol "_kDartIsolateSnapshotData" -#define kIsolateSnapshotInstructionsCSymbol "_kDartIsolateSnapshotInstructions" -#define kIsolateSnapshotBssCSymbol "_kDartIsolateSnapshotBss" -#endif - -#define kSnapshotBuildIdAsmSymbol "_kDartSnapshotBuildId" -#define kVmSnapshotDataAsmSymbol "_kDartVmSnapshotData" -#define kVmSnapshotInstructionsAsmSymbol "_kDartVmSnapshotInstructions" -#define kVmSnapshotBssAsmSymbol "_kDartVmSnapshotBss" -#define kIsolateSnapshotDataAsmSymbol "_kDartIsolateSnapshotData" -#define kIsolateSnapshotInstructionsAsmSymbol \ - "_kDartIsolateSnapshotInstructions" -#define kIsolateSnapshotBssAsmSymbol "_kDartIsolateSnapshotBss" - -/** - * Creates a precompiled snapshot. - * - A root library must have been loaded. - * - Dart_Precompile must have been called. - * - * Outputs an assembly file defining the symbols listed in the definitions - * above. - * - * The assembly should be compiled as a static or shared library and linked or - * loaded by the embedder. Running this snapshot requires a VM compiled with - * DART_PRECOMPILED_SNAPSHOT. The kDartVmSnapshotData and - * kDartVmSnapshotInstructions should be passed to Dart_Initialize. The - * kDartIsolateSnapshotData and kDartIsolateSnapshotInstructions should be - * passed to Dart_CreateIsolateGroup. - * - * The callback will be invoked one or more times to provide the assembly code. - * - * If stripped is true, then the assembly code will not include DWARF - * debugging sections. - * - * If debug_callback_data is provided, debug_callback_data will be used with - * the callback to provide separate debugging information. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_CreateAppAOTSnapshotAsAssembly(Dart_StreamingWriteCallback callback, - void* callback_data, - bool stripped, - void* debug_callback_data); -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_CreateAppAOTSnapshotAsAssemblies( - Dart_CreateLoadingUnitCallback next_callback, - void* next_callback_data, - bool stripped, - Dart_StreamingWriteCallback write_callback, - Dart_StreamingCloseCallback close_callback); - -/** - * Creates a precompiled snapshot. - * - A root library must have been loaded. - * - Dart_Precompile must have been called. - * - * Outputs an ELF shared library defining the symbols - * - _kDartVmSnapshotData - * - _kDartVmSnapshotInstructions - * - _kDartIsolateSnapshotData - * - _kDartIsolateSnapshotInstructions - * - * The shared library should be dynamically loaded by the embedder. - * Running this snapshot requires a VM compiled with DART_PRECOMPILED_SNAPSHOT. - * The kDartVmSnapshotData and kDartVmSnapshotInstructions should be passed to - * Dart_Initialize. The kDartIsolateSnapshotData and - * kDartIsolateSnapshotInstructions should be passed to Dart_CreateIsolate. - * - * The callback will be invoked one or more times to provide the binary output. - * - * If stripped is true, then the binary output will not include DWARF - * debugging sections. - * - * If debug_callback_data is provided, debug_callback_data will be used with - * the callback to provide separate debugging information. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_CreateAppAOTSnapshotAsElf(Dart_StreamingWriteCallback callback, - void* callback_data, - bool stripped, - void* debug_callback_data); -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_CreateAppAOTSnapshotAsElfs(Dart_CreateLoadingUnitCallback next_callback, - void* next_callback_data, - bool stripped, - Dart_StreamingWriteCallback write_callback, - Dart_StreamingCloseCallback close_callback); - -/** - * Like Dart_CreateAppAOTSnapshotAsAssembly, but only includes - * kDartVmSnapshotData and kDartVmSnapshotInstructions. It also does - * not strip DWARF information from the generated assembly or allow for - * separate debug information. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_CreateVMAOTSnapshotAsAssembly(Dart_StreamingWriteCallback callback, - void* callback_data); - -/** - * Sorts the class-ids in depth first traversal order of the inheritance - * tree. This is a costly operation, but it can make method dispatch - * more efficient and is done before writing snapshots. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_SortClasses(); - -/** - * Creates a snapshot that caches compiled code and type feedback for faster - * startup and quicker warmup in a subsequent process. - * - * Outputs a snapshot in two pieces. The pieces should be passed to - * Dart_CreateIsolateGroup in a VM using the same VM snapshot pieces used in the - * current VM. The instructions piece must be loaded with read and execute - * permissions; the data piece may be loaded as read-only. - * - * - Requires the VM to have not been started with --precompilation. - * - Not supported when targeting IA32. - * - The VM writing the snapshot and the VM reading the snapshot must be the - * same version, must be built in the same DEBUG/RELEASE/PRODUCT mode, must - * be targeting the same architecture, and must both be in checked mode or - * both in unchecked mode. - * - * The buffers are scope allocated and are only valid until the next call to - * Dart_ExitScope. - * - * \return A valid handle if no error occurs during the operation. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_data_buffer, - intptr_t* isolate_snapshot_data_size, - uint8_t** isolate_snapshot_instructions_buffer, - intptr_t* isolate_snapshot_instructions_size); - -/** - * Like Dart_CreateAppJITSnapshotAsBlobs, but also creates a new VM snapshot. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_CreateCoreJITSnapshotAsBlobs( - uint8_t** vm_snapshot_data_buffer, - intptr_t* vm_snapshot_data_size, - uint8_t** vm_snapshot_instructions_buffer, - intptr_t* vm_snapshot_instructions_size, - uint8_t** isolate_snapshot_data_buffer, - intptr_t* isolate_snapshot_data_size, - uint8_t** isolate_snapshot_instructions_buffer, - intptr_t* isolate_snapshot_instructions_size); - -/** - * Get obfuscation map for precompiled code. - * - * Obfuscation map is encoded as a JSON array of pairs (original name, - * obfuscated name). - * - * \return Returns an error handler if the VM was built in a mode that does not - * support obfuscation. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle -Dart_GetObfuscationMap(uint8_t** buffer, intptr_t* buffer_length); - -/** - * Returns whether the VM only supports running from precompiled snapshots and - * not from any other kind of snapshot or from source (that is, the VM was - * compiled with DART_PRECOMPILED_RUNTIME). - */ -DART_EXPORT bool Dart_IsPrecompiledRuntime(); - -/** - * Print a native stack trace. Used for crash handling. - * - * If context is NULL, prints the current stack trace. Otherwise, context - * should be a CONTEXT* (Windows) or ucontext_t* (POSIX) from a signal handler - * running on the current thread. - */ -DART_EXPORT void Dart_DumpNativeStackTrace(void* context); - -/** - * Indicate that the process is about to abort, and the Dart VM should not - * attempt to cleanup resources. - */ -DART_EXPORT void Dart_PrepareToAbort(); - -#endif /* INCLUDE_DART_API_H_ */ /* NOLINT */ diff --git a/third_party/dart-sdk/src/runtime/include/dart_api_dl.c b/third_party/dart-sdk/src/runtime/include/dart_api_dl.c deleted file mode 100644 index c4a68f44..00000000 --- a/third_party/dart-sdk/src/runtime/include/dart_api_dl.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file - * for details. All rights reserved. Use of this source code is governed by a - * BSD-style license that can be found in the LICENSE file. - */ - -#include "dart_api_dl.h" /* NOLINT */ -#include "dart_version.h" /* NOLINT */ -#include "internal/dart_api_dl_impl.h" /* NOLINT */ - -#include - -#define DART_API_DL_DEFINITIONS(name, R, A) name##_Type name##_DL = NULL; - -DART_API_ALL_DL_SYMBOLS(DART_API_DL_DEFINITIONS) - -#undef DART_API_DL_DEFINITIONS - -typedef void* DartApiEntry_function; - -DartApiEntry_function FindFunctionPointer(const DartApiEntry* entries, - const char* name) { - while (entries->name != NULL) { - if (strcmp(entries->name, name) == 0) return entries->function; - entries++; - } - return NULL; -} - -intptr_t Dart_InitializeApiDL(void* data) { - DartApi* dart_api_data = (DartApi*)data; - - if (dart_api_data->major != DART_API_DL_MAJOR_VERSION) { - // If the DartVM we're running on does not have the same version as this - // file was compiled against, refuse to initialize. The symbols are not - // compatible. - return -1; - } - // Minor versions are allowed to be different. - // If the DartVM has a higher minor version, it will provide more symbols - // than we initialize here. - // If the DartVM has a lower minor version, it will not provide all symbols. - // In that case, we leave the missing symbols un-initialized. Those symbols - // should not be used by the Dart and native code. The client is responsible - // for checking the minor version number himself based on which symbols it - // is using. - // (If we would error out on this case, recompiling native code against a - // newer SDK would break all uses on older SDKs, which is too strict.) - - const DartApiEntry* dart_api_function_pointers = dart_api_data->functions; - -#define DART_API_DL_INIT(name, R, A) \ - name##_DL = \ - (name##_Type)(FindFunctionPointer(dart_api_function_pointers, #name)); - DART_API_ALL_DL_SYMBOLS(DART_API_DL_INIT) -#undef DART_API_DL_INIT - - return 0; -} diff --git a/third_party/dart-sdk/src/runtime/include/dart_api_dl.h b/third_party/dart-sdk/src/runtime/include/dart_api_dl.h deleted file mode 100644 index 0854d71f..00000000 --- a/third_party/dart-sdk/src/runtime/include/dart_api_dl.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file - * for details. All rights reserved. Use of this source code is governed by a - * BSD-style license that can be found in the LICENSE file. - */ - -#ifndef RUNTIME_INCLUDE_DART_API_DL_H_ -#define RUNTIME_INCLUDE_DART_API_DL_H_ - -#include "dart_api.h" /* NOLINT */ -#include "dart_native_api.h" /* NOLINT */ - -/** \mainpage Dynamically Linked Dart API - * - * This exposes a subset of symbols from dart_api.h and dart_native_api.h - * available in every Dart embedder through dynamic linking. - * - * All symbols are postfixed with _DL to indicate that they are dynamically - * linked and to prevent conflicts with the original symbol. - * - * Link `dart_api_dl.c` file into your library and invoke - * `Dart_InitializeApiDL` with `NativeApi.initializeApiDLData`. - */ - -#ifdef __cplusplus -#define DART_EXTERN extern "C" -#else -#define DART_EXTERN extern -#endif - -DART_EXTERN intptr_t Dart_InitializeApiDL(void* data); - -// ============================================================================ -// IMPORTANT! Never update these signatures without properly updating -// DART_API_DL_MAJOR_VERSION and DART_API_DL_MINOR_VERSION. -// -// Verbatim copy of `dart_native_api.h` and `dart_api.h` symbol names and types -// to trigger compile-time errors if the sybols in those files are updated -// without updating these. -// -// Function return and argument types, and typedefs are carbon copied. Structs -// are typechecked nominally in C/C++, so they are not copied, instead a -// comment is added to their definition. -typedef int64_t Dart_Port_DL; - -typedef void (*Dart_NativeMessageHandler_DL)(Dart_Port_DL dest_port_id, - Dart_CObject* message); - -// dart_native_api.h symbols can be called on any thread. -#define DART_NATIVE_API_DL_SYMBOLS(F) \ - /***** dart_native_api.h *****/ \ - /* Dart_Port */ \ - F(Dart_PostCObject, bool, (Dart_Port_DL port_id, Dart_CObject * message)) \ - F(Dart_PostInteger, bool, (Dart_Port_DL port_id, int64_t message)) \ - F(Dart_NewNativePort, Dart_Port_DL, \ - (const char* name, Dart_NativeMessageHandler_DL handler, \ - bool handle_concurrently)) \ - F(Dart_CloseNativePort, bool, (Dart_Port_DL native_port_id)) - -// dart_api.h symbols can only be called on Dart threads. -#define DART_API_DL_SYMBOLS(F) \ - /***** dart_api.h *****/ \ - /* Errors */ \ - F(Dart_IsError, bool, (Dart_Handle handle)) \ - F(Dart_IsApiError, bool, (Dart_Handle handle)) \ - F(Dart_IsUnhandledExceptionError, bool, (Dart_Handle handle)) \ - F(Dart_IsCompilationError, bool, (Dart_Handle handle)) \ - F(Dart_IsFatalError, bool, (Dart_Handle handle)) \ - F(Dart_GetError, const char*, (Dart_Handle handle)) \ - F(Dart_ErrorHasException, bool, (Dart_Handle handle)) \ - F(Dart_ErrorGetException, Dart_Handle, (Dart_Handle handle)) \ - F(Dart_ErrorGetStackTrace, Dart_Handle, (Dart_Handle handle)) \ - F(Dart_NewApiError, Dart_Handle, (const char* error)) \ - F(Dart_NewCompilationError, Dart_Handle, (const char* error)) \ - F(Dart_NewUnhandledExceptionError, Dart_Handle, (Dart_Handle exception)) \ - F(Dart_PropagateError, void, (Dart_Handle handle)) \ - /* Dart_Handle, Dart_PersistentHandle, Dart_WeakPersistentHandle */ \ - F(Dart_HandleFromPersistent, Dart_Handle, (Dart_PersistentHandle object)) \ - F(Dart_HandleFromWeakPersistent, Dart_Handle, \ - (Dart_WeakPersistentHandle object)) \ - F(Dart_NewPersistentHandle, Dart_PersistentHandle, (Dart_Handle object)) \ - F(Dart_SetPersistentHandle, void, \ - (Dart_PersistentHandle obj1, Dart_Handle obj2)) \ - F(Dart_DeletePersistentHandle, void, (Dart_PersistentHandle object)) \ - F(Dart_NewWeakPersistentHandle, Dart_WeakPersistentHandle, \ - (Dart_Handle object, void* peer, intptr_t external_allocation_size, \ - Dart_HandleFinalizer callback)) \ - F(Dart_DeleteWeakPersistentHandle, void, (Dart_WeakPersistentHandle object)) \ - F(Dart_UpdateExternalSize, void, \ - (Dart_WeakPersistentHandle object, intptr_t external_allocation_size)) \ - F(Dart_NewFinalizableHandle, Dart_FinalizableHandle, \ - (Dart_Handle object, void* peer, intptr_t external_allocation_size, \ - Dart_HandleFinalizer callback)) \ - F(Dart_DeleteFinalizableHandle, void, \ - (Dart_FinalizableHandle object, Dart_Handle strong_ref_to_object)) \ - F(Dart_UpdateFinalizableExternalSize, void, \ - (Dart_FinalizableHandle object, Dart_Handle strong_ref_to_object, \ - intptr_t external_allocation_size)) \ - /* Dart_Port */ \ - F(Dart_Post, bool, (Dart_Port_DL port_id, Dart_Handle object)) \ - F(Dart_NewSendPort, Dart_Handle, (Dart_Port_DL port_id)) \ - F(Dart_SendPortGetId, Dart_Handle, \ - (Dart_Handle port, Dart_Port_DL * port_id)) \ - /* Scopes */ \ - F(Dart_EnterScope, void, ()) \ - F(Dart_ExitScope, void, ()) - -#define DART_API_ALL_DL_SYMBOLS(F) \ - DART_NATIVE_API_DL_SYMBOLS(F) \ - DART_API_DL_SYMBOLS(F) -// IMPORTANT! Never update these signatures without properly updating -// DART_API_DL_MAJOR_VERSION and DART_API_DL_MINOR_VERSION. -// -// End of verbatim copy. -// ============================================================================ - -#define DART_API_DL_DECLARATIONS(name, R, A) \ - typedef R(*name##_Type) A; \ - DART_EXTERN name##_Type name##_DL; - -DART_API_ALL_DL_SYMBOLS(DART_API_DL_DECLARATIONS) - -#undef DART_API_DL_DEFINITIONS - -#undef DART_EXTERN - -#endif /* RUNTIME_INCLUDE_DART_API_DL_H_ */ /* NOLINT */ diff --git a/third_party/dart-sdk/src/runtime/include/dart_embedder_api.h b/third_party/dart-sdk/src/runtime/include/dart_embedder_api.h deleted file mode 100644 index e565ebf6..00000000 --- a/third_party/dart-sdk/src/runtime/include/dart_embedder_api.h +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -#ifndef RUNTIME_INCLUDE_DART_EMBEDDER_API_H_ -#define RUNTIME_INCLUDE_DART_EMBEDDER_API_H_ - -#include "include/dart_api.h" -#include "include/dart_tools_api.h" - -namespace dart { -namespace embedder { - -// Initialize all subsystems of the embedder. -// -// Must be called before the `Dart_Initialize()` call to initialize the -// Dart VM. -// -// Returns true on success and false otherwise, in which case error would -// contain error message. -DART_WARN_UNUSED_RESULT bool InitOnce(char** error); - -// Cleans up all subsystems of the embedder. -// -// Must be called after the `Dart_Cleanup()` call to initialize the -// Dart VM. -void Cleanup(); - -// Common arguments that are passed to isolate creation callback and to -// API methods that create isolates. -struct IsolateCreationData { - // URI for the main script that will be running in the isolate. - const char* script_uri; - - // Advisory name of the main method that will be run by isolate. - // Only used for error messages. - const char* main; - - // Isolate creation flags. Might be absent. - Dart_IsolateFlags* flags; - - // Isolate group callback data. - void* isolate_group_data; - - // Isolate callback data. - void* isolate_data; -}; - -// Create and initialize kernel-service isolate. This method should be used -// when VM invokes isolate creation callback with DART_KERNEL_ISOLATE_NAME as -// script_uri. -// The isolate is created from the given snapshot (might be kernel data or -// app-jit snapshot). -DART_WARN_UNUSED_RESULT Dart_Isolate -CreateKernelServiceIsolate(const IsolateCreationData& data, - const uint8_t* buffer, - intptr_t buffer_size, - char** error); - -// Service isolate configuration. -struct VmServiceConfiguration { - enum { - kBindHttpServerToAFreePort = 0, - kDoNotAutoStartHttpServer = -1 - }; - - // Address to which HTTP server will be bound. - const char* ip; - - // Default port. See enum above for special values. - int port; - - // If non-null, connection information for the VM service will be output to a - // file in JSON format at the location specified. - const char* write_service_info_filename; - - // TODO(vegorov) document these ones. - bool dev_mode; - bool deterministic; - bool disable_auth_codes; -}; - -// Create and initialize vm-service isolate from the given AOT snapshot, which -// is expected to contain all necessary 'vm-service' libraries. -// This method should be used when VM invokes isolate creation callback with -// DART_VM_SERVICE_ISOLATE_NAME as script_uri. -DART_WARN_UNUSED_RESULT Dart_Isolate -CreateVmServiceIsolate(const IsolateCreationData& data, - const VmServiceConfiguration& config, - const uint8_t* isolate_data, - const uint8_t* isolate_instr, - char** error); - -// Create and initialize vm-service isolate from the given kernel binary, which -// is expected to contain all necessary 'vm-service' libraries. -// This method should be used when VM invokes isolate creation callback with -// DART_VM_SERVICE_ISOLATE_NAME as script_uri. -DART_WARN_UNUSED_RESULT Dart_Isolate -CreateVmServiceIsolateFromKernel(const IsolateCreationData& data, - const VmServiceConfiguration& config, - const uint8_t* kernel_buffer, - intptr_t kernel_buffer_size, - char** error); - -} // namespace embedder -} // namespace dart - -#endif // RUNTIME_INCLUDE_DART_EMBEDDER_API_H_ diff --git a/third_party/dart-sdk/src/runtime/include/dart_native_api.h b/third_party/dart-sdk/src/runtime/include/dart_native_api.h deleted file mode 100644 index a40c522d..00000000 --- a/third_party/dart-sdk/src/runtime/include/dart_native_api.h +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file - * for details. All rights reserved. Use of this source code is governed by a - * BSD-style license that can be found in the LICENSE file. - */ - -#ifndef RUNTIME_INCLUDE_DART_NATIVE_API_H_ -#define RUNTIME_INCLUDE_DART_NATIVE_API_H_ - -#include "dart_api.h" /* NOLINT */ - -/* - * ========================================== - * Message sending/receiving from native code - * ========================================== - */ - -/** - * A Dart_CObject is used for representing Dart objects as native C - * data outside the Dart heap. These objects are totally detached from - * the Dart heap. Only a subset of the Dart objects have a - * representation as a Dart_CObject. - * - * The string encoding in the 'value.as_string' is UTF-8. - * - * All the different types from dart:typed_data are exposed as type - * kTypedData. The specific type from dart:typed_data is in the type - * field of the as_typed_data structure. The length in the - * as_typed_data structure is always in bytes. - * - * The data for kTypedData is copied on message send and ownership remains with - * the caller. The ownership of data for kExternalTyped is passed to the VM on - * message send and returned when the VM invokes the - * Dart_HandleFinalizer callback; a non-NULL callback must be provided. - */ -typedef enum { - Dart_CObject_kNull = 0, - Dart_CObject_kBool, - Dart_CObject_kInt32, - Dart_CObject_kInt64, - Dart_CObject_kDouble, - Dart_CObject_kString, - Dart_CObject_kArray, - Dart_CObject_kTypedData, - Dart_CObject_kExternalTypedData, - Dart_CObject_kSendPort, - Dart_CObject_kCapability, - Dart_CObject_kUnsupported, - Dart_CObject_kNumberOfTypes -} Dart_CObject_Type; - -typedef struct _Dart_CObject { - Dart_CObject_Type type; - union { - bool as_bool; - int32_t as_int32; - int64_t as_int64; - double as_double; - char* as_string; - struct { - Dart_Port id; - Dart_Port origin_id; - } as_send_port; - struct { - int64_t id; - } as_capability; - struct { - intptr_t length; - struct _Dart_CObject** values; - } as_array; - struct { - Dart_TypedData_Type type; - intptr_t length; - uint8_t* values; - } as_typed_data; - struct { - Dart_TypedData_Type type; - intptr_t length; - uint8_t* data; - void* peer; - Dart_HandleFinalizer callback; - } as_external_typed_data; - } value; -} Dart_CObject; -// This struct is versioned by DART_API_DL_MAJOR_VERSION, bump the version when -// changing this struct. - -/** - * Posts a message on some port. The message will contain the Dart_CObject - * object graph rooted in 'message'. - * - * While the message is being sent the state of the graph of Dart_CObject - * structures rooted in 'message' should not be accessed, as the message - * generation will make temporary modifications to the data. When the message - * has been sent the graph will be fully restored. - * - * If true is returned, the message was enqueued, and finalizers for external - * typed data will eventually run, even if the receiving isolate shuts down - * before processing the message. If false is returned, the message was not - * enqueued and ownership of external typed data in the message remains with the - * caller. - * - * This function may be called on any thread when the VM is running (that is, - * after Dart_Initialize has returned and before Dart_Cleanup has been called). - * - * \param port_id The destination port. - * \param message The message to send. - * - * \return True if the message was posted. - */ -DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message); - -/** - * Posts a message on some port. The message will contain the integer 'message'. - * - * \param port_id The destination port. - * \param message The message to send. - * - * \return True if the message was posted. - */ -DART_EXPORT bool Dart_PostInteger(Dart_Port port_id, int64_t message); - -/** - * A native message handler. - * - * This handler is associated with a native port by calling - * Dart_NewNativePort. - * - * The message received is decoded into the message structure. The - * lifetime of the message data is controlled by the caller. All the - * data references from the message are allocated by the caller and - * will be reclaimed when returning to it. - */ -typedef void (*Dart_NativeMessageHandler)(Dart_Port dest_port_id, - Dart_CObject* message); - -/** - * Creates a new native port. When messages are received on this - * native port, then they will be dispatched to the provided native - * message handler. - * - * \param name The name of this port in debugging messages. - * \param handler The C handler to run when messages arrive on the port. - * \param handle_concurrently Is it okay to process requests on this - * native port concurrently? - * - * \return If successful, returns the port id for the native port. In - * case of error, returns ILLEGAL_PORT. - */ -DART_EXPORT Dart_Port Dart_NewNativePort(const char* name, - Dart_NativeMessageHandler handler, - bool handle_concurrently); -/* TODO(turnidge): Currently handle_concurrently is ignored. */ - -/** - * Closes the native port with the given id. - * - * The port must have been allocated by a call to Dart_NewNativePort. - * - * \param native_port_id The id of the native port to close. - * - * \return Returns true if the port was closed successfully. - */ -DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id); - -/* - * ================== - * Verification Tools - * ================== - */ - -/** - * Forces all loaded classes and functions to be compiled eagerly in - * the current isolate.. - * - * TODO(turnidge): Document. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_CompileAll(); - -/** - * Finalizes all classes. - */ -DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_FinalizeAllClasses(); - -/* This function is intentionally undocumented. - * - * It should not be used outside internal tests. - */ -DART_EXPORT void* Dart_ExecuteInternalCommand(const char* command, void* arg); - -#endif /* INCLUDE_DART_NATIVE_API_H_ */ /* NOLINT */ diff --git a/third_party/dart-sdk/src/runtime/include/dart_tools_api.h b/third_party/dart-sdk/src/runtime/include/dart_tools_api.h deleted file mode 100644 index a106d42e..00000000 --- a/third_party/dart-sdk/src/runtime/include/dart_tools_api.h +++ /dev/null @@ -1,499 +0,0 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -#ifndef RUNTIME_INCLUDE_DART_TOOLS_API_H_ -#define RUNTIME_INCLUDE_DART_TOOLS_API_H_ - -#include "dart_api.h" /* NOLINT */ - -/** \mainpage Dart Tools Embedding API Reference - * - * This reference describes the Dart embedding API for tools. Tools include - * a debugger, service protocol, and timeline. - * - * NOTE: The APIs described in this file are unstable and subject to change. - * - * This reference is generated from the header include/dart_tools_api.h. - */ - -/* - * ======== - * Debugger - * ======== - */ - -/** - * ILLEGAL_ISOLATE_ID is a number guaranteed never to be associated with a - * valid isolate. - */ -#define ILLEGAL_ISOLATE_ID ILLEGAL_PORT - - -/* - * ======= - * Service - * ======= - */ - -/** - * A service request callback function. - * - * These callbacks, registered by the embedder, are called when the VM receives - * a service request it can't handle and the service request command name - * matches one of the embedder registered handlers. - * - * The return value of the callback indicates whether the response - * should be used as a regular result or an error result. - * Specifically, if the callback returns true, a regular JSON-RPC - * response is built in the following way: - * - * { - * "jsonrpc": "2.0", - * "result": , - * "id": , - * } - * - * If the callback returns false, a JSON-RPC error is built like this: - * - * { - * "jsonrpc": "2.0", - * "error": , - * "id": , - * } - * - * \param method The rpc method name. - * \param param_keys Service requests can have key-value pair parameters. The - * keys and values are flattened and stored in arrays. - * \param param_values The values associated with the keys. - * \param num_params The length of the param_keys and param_values arrays. - * \param user_data The user_data pointer registered with this handler. - * \param result A C string containing a valid JSON object. The returned - * pointer will be freed by the VM by calling free. - * - * \return True if the result is a regular JSON-RPC response, false if the - * result is a JSON-RPC error. - */ -typedef bool (*Dart_ServiceRequestCallback)(const char* method, - const char** param_keys, - const char** param_values, - intptr_t num_params, - void* user_data, - const char** json_object); - -/** - * Register a Dart_ServiceRequestCallback to be called to handle - * requests for the named rpc on a specific isolate. The callback will - * be invoked with the current isolate set to the request target. - * - * \param method The name of the method that this callback is responsible for. - * \param callback The callback to invoke. - * \param user_data The user data passed to the callback. - * - * NOTE: If multiple callbacks with the same name are registered, only - * the last callback registered will be remembered. - */ -DART_EXPORT void Dart_RegisterIsolateServiceRequestCallback( - const char* method, - Dart_ServiceRequestCallback callback, - void* user_data); - -/** - * Register a Dart_ServiceRequestCallback to be called to handle - * requests for the named rpc. The callback will be invoked without a - * current isolate. - * - * \param method The name of the command that this callback is responsible for. - * \param callback The callback to invoke. - * \param user_data The user data passed to the callback. - * - * NOTE: If multiple callbacks with the same name are registered, only - * the last callback registered will be remembered. - */ -DART_EXPORT void Dart_RegisterRootServiceRequestCallback( - const char* method, - Dart_ServiceRequestCallback callback, - void* user_data); - -/** - * Embedder information which can be requested by the VM for internal or - * reporting purposes. - * - * The pointers in this structure are not going to be cached or freed by the VM. - */ - - #define DART_EMBEDDER_INFORMATION_CURRENT_VERSION (0x00000001) - -typedef struct { - int32_t version; - const char* name; // [optional] The name of the embedder - int64_t current_rss; // [optional] the current RSS of the embedder - int64_t max_rss; // [optional] the maximum RSS of the embedder -} Dart_EmbedderInformation; - -/** - * Callback provided by the embedder that is used by the vm to request - * information. - * - * \return Returns a pointer to a Dart_EmbedderInformation structure. - * The embedder keeps the ownership of the structure and any field in it. - * The embedder must ensure that the structure will remain valid until the - * next invokation of the callback. - */ -typedef void (*Dart_EmbedderInformationCallback)( - Dart_EmbedderInformation* info); - -/** - * Register a Dart_ServiceRequestCallback to be called to handle - * requests for the named rpc. The callback will be invoked without a - * current isolate. - * - * \param method The name of the command that this callback is responsible for. - * \param callback The callback to invoke. - * \param user_data The user data passed to the callback. - * - * NOTE: If multiple callbacks with the same name are registered, only - * the last callback registered will be remembered. - */ -DART_EXPORT void Dart_SetEmbedderInformationCallback( - Dart_EmbedderInformationCallback callback); - -/** - * Invoke a vm-service method and wait for its result. - * - * \param request_json The utf8-encoded json-rpc request. - * \param request_json_length The length of the json-rpc request. - * - * \param response_json The returned utf8-encoded json response, must be - * free()ed by caller. - * \param response_json_length The length of the returned json response. - * \param error An optional error, must be free()ed by caller. - * - * \return Whether the call was sucessfully performed. - * - * NOTE: This method does not need a current isolate and must not have the - * vm-isolate being the current isolate. It must be called after - * Dart_Initialize() and before Dart_Cleanup(). - */ -DART_EXPORT bool Dart_InvokeVMServiceMethod(uint8_t* request_json, - intptr_t request_json_length, - uint8_t** response_json, - intptr_t* response_json_length, - char** error); - -/* - * ======== - * Event Streams - * ======== - */ - -/** - * A callback invoked when the VM service gets a request to listen to - * some stream. - * - * \return Returns true iff the embedder supports the named stream id. - */ -typedef bool (*Dart_ServiceStreamListenCallback)(const char* stream_id); - -/** - * A callback invoked when the VM service gets a request to cancel - * some stream. - */ -typedef void (*Dart_ServiceStreamCancelCallback)(const char* stream_id); - -/** - * Adds VM service stream callbacks. - * - * \param listen_callback A function pointer to a listen callback function. - * A listen callback function should not be already set when this function - * is called. A NULL value removes the existing listen callback function - * if any. - * - * \param cancel_callback A function pointer to a cancel callback function. - * A cancel callback function should not be already set when this function - * is called. A NULL value removes the existing cancel callback function - * if any. - * - * \return Success if the callbacks were added. Otherwise, returns an - * error handle. - */ -DART_EXPORT char* Dart_SetServiceStreamCallbacks( - Dart_ServiceStreamListenCallback listen_callback, - Dart_ServiceStreamCancelCallback cancel_callback); - -/** - * A callback invoked when the VM service receives an event. - */ -typedef void (*Dart_NativeStreamConsumer)(const uint8_t* event_json, - intptr_t event_json_length); - -/** - * Sets the native VM service stream callbacks for a particular stream. - * Note: The function may be called on multiple threads concurrently. - * - * \param consumer A function pointer to an event handler callback function. - * A NULL value removes the existing listen callback function if any. - * - * \param stream_id The ID of the stream on which to set the callback. - */ -DART_EXPORT void Dart_SetNativeServiceStreamCallback( - Dart_NativeStreamConsumer consumer, - const char* stream_id); - -/** - * Sends a data event to clients of the VM Service. - * - * A data event is used to pass an array of bytes to subscribed VM - * Service clients. For example, in the standalone embedder, this is - * function used to provide WriteEvents on the Stdout and Stderr - * streams. - * - * If the embedder passes in a stream id for which no client is - * subscribed, then the event is ignored. - * - * \param stream_id The id of the stream on which to post the event. - * - * \param event_kind A string identifying what kind of event this is. - * For example, 'WriteEvent'. - * - * \param bytes A pointer to an array of bytes. - * - * \param bytes_length The length of the byte array. - * - * \return Success if the arguments are well formed. Otherwise, returns an - * error handle. - */ -DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id, - const char* event_kind, - const uint8_t* bytes, - intptr_t bytes_length); - -/** - * Usage statistics for a space/generation at a particular moment in time. - * - * \param used Amount of memory used, in bytes. - * - * \param capacity Memory capacity, in bytes. - * - * \param external External memory, in bytes. - * - * \param collections How many times the garbage collector has run in this - * space. - * - * \param time Cumulative time spent collecting garbage in this space, in - * seconds. - * - * \param avg_collection_period Average time between garbage collector running - * in this space, in milliseconds. - */ -typedef struct { - intptr_t used; - intptr_t capacity; - intptr_t external; - intptr_t collections; - double time; - double avg_collection_period; -} Dart_GCStats; - -/** - * A Garbage Collection event with memory usage statistics. - * - * \param type The event type. Static lifetime. - * - * \param reason The reason for the GC event. Static lifetime. - * - * \param new_space Data for New Space. - * - * \param old_space Data for Old Space. - */ -typedef struct { - const char* type; - const char* reason; - const char* isolate_id; - - Dart_GCStats new_space; - Dart_GCStats old_space; -} Dart_GCEvent; - -/** - * A callback invoked when the VM emits a GC event. - * - * \param event The GC event data. Pointer only valid for the duration of the - * callback. - */ -typedef void (*Dart_GCEventCallback)(Dart_GCEvent* event); - -/** - * Sets the native GC event callback. - * - * \param callback A function pointer to an event handler callback function. - * A NULL value removes the existing listen callback function if any. - */ -DART_EXPORT void Dart_SetGCEventCallback(Dart_GCEventCallback callback); - -/* - * ======== - * Reload support - * ======== - * - * These functions are used to implement reloading in the Dart VM. - * This is an experimental feature, so embedders should be prepared - * for these functions to change. - */ - -/** - * A callback which determines whether the file at some url has been - * modified since some time. If the file cannot be found, true should - * be returned. - */ -typedef bool (*Dart_FileModifiedCallback)(const char* url, int64_t since); - -DART_EXPORT char* Dart_SetFileModifiedCallback( - Dart_FileModifiedCallback file_modified_callback); - -/** - * Returns true if isolate is currently reloading. - */ -DART_EXPORT bool Dart_IsReloading(); - -/* - * ======== - * Timeline - * ======== - */ - -/** - * Returns a timestamp in microseconds. This timestamp is suitable for - * passing into the timeline system, and uses the same monotonic clock - * as dart:developer's Timeline.now. - * - * \return A timestamp that can be passed to the timeline system. - */ -DART_EXPORT int64_t Dart_TimelineGetMicros(); - -/** Timeline stream for Dart API calls */ -#define DART_TIMELINE_STREAM_API (1 << 0) -/** Timeline stream for compiler events */ -#define DART_TIMELINE_STREAM_COMPILER (1 << 1) -/** Timeline stream for Dart provided events */ -#define DART_TIMELINE_STREAM_DART (1 << 2) -/** Timeline stream for debugger provided events */ -#define DART_TIMELINE_STREAM_DEBUGGER (1 << 3) -/** Timeline stream for embedder provided events */ -#define DART_TIMELINE_STREAM_EMBEDDER (1 << 4) -/** Timeline stream for GC events */ -#define DART_TIMELINE_STREAM_GC (1 << 5) -/** Timeline stream for isolate events */ -#define DART_TIMELINE_STREAM_ISOLATE (1 << 6) -/** Timeline stream for VM events */ -#define DART_TIMELINE_STREAM_VM (1 << 7) - -/** All timeline streams */ -#define DART_TIMELINE_STREAM_ALL \ - (DART_TIMELINE_STREAM_API | DART_TIMELINE_STREAM_COMPILER | \ - DART_TIMELINE_STREAM_DART | DART_TIMELINE_STREAM_DEBUGGER | \ - DART_TIMELINE_STREAM_EMBEDDER | DART_TIMELINE_STREAM_GC | \ - DART_TIMELINE_STREAM_ISOLATE | DART_TIMELINE_STREAM_VM) - -/** Disable all timeline stream recording */ -#define DART_TIMELINE_STREAM_DISABLE 0 - -/** - * Start recording timeline events for the entire VM (including all isolates). - * - * \param stream_mask A bitmask of streams that should be recorded. - * - * NOTE: Calling with 0 disables recording of all streams. - */ -DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask); - -typedef enum { - Dart_Timeline_Event_Begin, // Phase = 'B'. - Dart_Timeline_Event_End, // Phase = 'E'. - Dart_Timeline_Event_Instant, // Phase = 'i'. - Dart_Timeline_Event_Duration, // Phase = 'X'. - Dart_Timeline_Event_Async_Begin, // Phase = 'b'. - Dart_Timeline_Event_Async_End, // Phase = 'e'. - Dart_Timeline_Event_Async_Instant, // Phase = 'n'. - Dart_Timeline_Event_Counter, // Phase = 'C'. - Dart_Timeline_Event_Flow_Begin, // Phase = 's'. - Dart_Timeline_Event_Flow_Step, // Phase = 't'. - Dart_Timeline_Event_Flow_End, // Phase = 'f'. -} Dart_Timeline_Event_Type; - -/** - * Add a timeline event to the embedder stream. - * - * \param label The name of the event. Its lifetime must extend at least until - * Dart_Cleanup. - * \param timestamp0 The first timestamp of the event. - * \param timestamp1_or_async_id The second timestamp of the event or - * the async id. - * \param argument_count The number of argument names and values. - * \param argument_names An array of names of the arguments. The lifetime of the - * names must extend at least until Dart_Cleanup. The array may be reclaimed - * when this call returns. - * \param argument_values An array of values of the arguments. The values and - * the array may be reclaimed when this call returns. - */ -DART_EXPORT void Dart_TimelineEvent(const char* label, - int64_t timestamp0, - int64_t timestamp1_or_async_id, - Dart_Timeline_Event_Type type, - intptr_t argument_count, - const char** argument_names, - const char** argument_values); - -/** - * Associates a name with the current thread. This name will be used to name - * threads in the timeline. Can only be called after a call to Dart_Initialize. - * - * \param name The name of the thread. - */ -DART_EXPORT void Dart_SetThreadName(const char* name); - -/* - * ======= - * Metrics - * ======= - */ - -/** - * Return metrics gathered for the VM and individual isolates. - * - * NOTE: Non-heap metrics are not available in PRODUCT builds of Dart. - * Calling the non-heap metric functions on a PRODUCT build might return invalid metrics. - */ -DART_EXPORT int64_t Dart_VMIsolateCountMetric(); // Counter -DART_EXPORT int64_t Dart_VMCurrentRSSMetric(); // Byte -DART_EXPORT int64_t Dart_VMPeakRSSMetric(); // Byte -DART_EXPORT int64_t -Dart_IsolateHeapOldUsedMetric(Dart_Isolate isolate); // Byte -DART_EXPORT int64_t -Dart_IsolateHeapOldUsedMaxMetric(Dart_Isolate isolate); // Byte -DART_EXPORT int64_t -Dart_IsolateHeapOldCapacityMetric(Dart_Isolate isolate); // Byte -DART_EXPORT int64_t -Dart_IsolateHeapOldCapacityMaxMetric(Dart_Isolate isolate); // Byte -DART_EXPORT int64_t -Dart_IsolateHeapOldExternalMetric(Dart_Isolate isolate); // Byte -DART_EXPORT int64_t -Dart_IsolateHeapNewUsedMetric(Dart_Isolate isolate); // Byte -DART_EXPORT int64_t -Dart_IsolateHeapNewUsedMaxMetric(Dart_Isolate isolate); // Byte -DART_EXPORT int64_t -Dart_IsolateHeapNewCapacityMetric(Dart_Isolate isolate); // Byte -DART_EXPORT int64_t -Dart_IsolateHeapNewCapacityMaxMetric(Dart_Isolate isolate); // Byte -DART_EXPORT int64_t -Dart_IsolateHeapNewExternalMetric(Dart_Isolate isolate); // Byte -DART_EXPORT int64_t -Dart_IsolateHeapGlobalUsedMetric(Dart_Isolate isolate); // Byte -DART_EXPORT int64_t -Dart_IsolateHeapGlobalUsedMaxMetric(Dart_Isolate isolate); // Byte -DART_EXPORT int64_t -Dart_IsolateRunnableLatencyMetric(Dart_Isolate isolate); // Microsecond -DART_EXPORT int64_t -Dart_IsolateRunnableHeapSizeMetric(Dart_Isolate isolate); // Byte - -#endif // RUNTIME_INCLUDE_DART_TOOLS_API_H_ diff --git a/third_party/dart-sdk/src/runtime/include/dart_version.h b/third_party/dart-sdk/src/runtime/include/dart_version.h deleted file mode 100644 index b3b49243..00000000 --- a/third_party/dart-sdk/src/runtime/include/dart_version.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file - * for details. All rights reserved. Use of this source code is governed by a - * BSD-style license that can be found in the LICENSE file. - */ - -#ifndef RUNTIME_INCLUDE_DART_VERSION_H_ -#define RUNTIME_INCLUDE_DART_VERSION_H_ - -// On breaking changes the major version is increased. -// On backwards compatible changes the minor version is increased. -// The versioning covers the symbols exposed in dart_api_dl.h -#define DART_API_DL_MAJOR_VERSION 2 -#define DART_API_DL_MINOR_VERSION 0 - -#endif /* RUNTIME_INCLUDE_DART_VERSION_H_ */ /* NOLINT */ diff --git a/third_party/dart-sdk/src/runtime/include/internal/dart_api_dl_impl.h b/third_party/dart-sdk/src/runtime/include/internal/dart_api_dl_impl.h deleted file mode 100644 index ad13a4b8..00000000 --- a/third_party/dart-sdk/src/runtime/include/internal/dart_api_dl_impl.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file - * for details. All rights reserved. Use of this source code is governed by a - * BSD-style license that can be found in the LICENSE file. - */ - -#ifndef RUNTIME_INCLUDE_INTERNAL_DART_API_DL_IMPL_H_ -#define RUNTIME_INCLUDE_INTERNAL_DART_API_DL_IMPL_H_ - -typedef struct { - const char* name; - void (*function)(); -} DartApiEntry; - -typedef struct { - const int major; - const int minor; - const DartApiEntry* const functions; -} DartApi; - -#endif /* RUNTIME_INCLUDE_INTERNAL_DART_API_DL_IMPL_H_ */ /* NOLINT */ diff --git a/third_party/dart-sdk/sources.cmake b/tool/update-bindings.sh old mode 100644 new mode 100755 similarity index 68% rename from third_party/dart-sdk/sources.cmake rename to tool/update-bindings.sh index 8077e493..cfdca997 --- a/third_party/dart-sdk/sources.cmake +++ b/tool/update-bindings.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,11 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -# **GENERATED FILE DO NOT MODIFY** -# -# This file is generated using: -# `tool/update-dart-sdk.py` +set -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +cd "$DIR/.." + +flutter pub get -set(dart_dl_sources - ${DARTSDK_ROOT}src/runtime/include/dart_api_dl.c -) +flutter pub run ffigen --config=lib/src/boringssl/bindings/ffigen.yaml +flutter pub run ffigen --config=lib/src/third_party/boringssl/ffigen.yaml diff --git a/tool/update-dart-sdk.py b/tool/update-dart-sdk.py deleted file mode 100755 index 4955558e..00000000 --- a/tool/update-dart-sdk.py +++ /dev/null @@ -1,228 +0,0 @@ -#!/usr/bin/env python2 - -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Roll Dart-SDK into third_party/dart-sdk/ -# Remember to bump DARTSDK_REVISION. - -import os -import os.path -import shutil -import subprocess -import sys -import tempfile - -TOOL_PATH = os.path.dirname(os.path.realpath(__file__)) -ROOT_PATH = os.path.dirname(TOOL_PATH) - -DARTSDK_REPOSITORY = 'https://dart.googlesource.com/sdk/' -DARTSDK_REVISION = '09481aa6ca60a12a5885db108aa5152cecb73fb1' - - -def cleanup(): - """ Remove dart-sdk sources and generated files """ - paths = [ - os.path.join(ROOT_PATH, 'third_party', 'dart-sdk'), - os.path.join(ROOT_PATH, 'ios', 'third_party', 'dart-sdk') - ] - for p in paths: - if os.path.exists(p): - shutil.rmtree(p) - mkdirp(p) - - -def git_clone(target): - """ Clone dart-sdk into target """ - mkdirp(target) - subprocess.check_call( - ['git', 'clone', DARTSDK_REPOSITORY, target], - ) - subprocess.check_call( - ['git', 'checkout', '--detach', DARTSDK_REVISION], - cwd=target, - ) - - -# Files from dart-sdk that should always be retained -FILES_TO_RETAIN = [ - 'README.dart-sdk', - 'README.md', - 'LICENSE', -] - -DARTSDK_FOLDER_README = """# Dynamic linking Dart SDK in `package:webcrypto` - -**GENERATED FOLDER DO NOT MODIFY** - -This folder contains sources from the Dart SDK allowing `package:webcrypto` to -dynamically link against native Dart APIs. Contents of this folder is generated -using `tool/update-dart-sdk.py` which clones the Dart SDK and copies over the -files required for dynamic linking. - -Files in this folder are subject to `LICENSE` from the Dart SDK project. - -Notice that this folder does NOT contain all source files from the Dart SDK -project. Only source files required to build `package:webcrypto` have been -retained. This is essential to minimize package size. For additional source -files and information about the Dart SDK refer to the [Dart SDK repository][1]. - -[1]: https://github.com/dart-lang/sdk -""" - -SOURCES_CMAKE_HEADER = """# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# **GENERATED FILE DO NOT MODIFY** -# -# This file is generated using: -# `tool/update-dart-sdk.py` -""" - -FAKE_IOS_SOURCE_HEADER = """/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// **GENERATED FILE DO NOT MODIFY** -// -// This file is generated using: -// `tool/update-dart-sdk.py` -""" - - -def writeFile(path_relative_root, contents): - with open(os.path.join(ROOT_PATH, path_relative_root), 'w') as f: - f.write(contents) - - -def writeFakeIosSource(g): - """ - Write fake-source files that each #include "../..." the original source - file for ios/ - """ - for f in sorted(set(g.file_sets['crypto'])): - target = os.path.join(ROOT_PATH, 'ios', 'third_party', 'boringssl', f) - original = os.path.join(ROOT_PATH, 'third_party', 'boringssl', f) - rel = os.path.relpath(original, os.path.dirname(target)) - mkdirp(os.path.dirname(target)) - contents = '' - contents += FAKE_IOS_SOURCE_HEADER - contents += '\n' - contents += '#include "'+rel+'"\n' - writeFile(os.path.join('ios', 'third_party', 'boringssl', f), contents) - - -def generate(dartsdk_clone): - # Add a README.md to the third_party/dart-sdk/ folder - readmePath = os.path.join('third_party', 'dart-sdk', 'README.md') - writeFile(readmePath, DARTSDK_FOLDER_README) - - # Copy runtime/include/ into third_party/dart-sdk/src/runtime/include/ - mkdirp(os.path.join(ROOT_PATH, 'third_party', 'dart-sdk', 'src')) - shutil.copytree( - os.path.join(dartsdk_clone, 'runtime', 'include'), - os.path.join(ROOT_PATH, 'third_party', 'dart-sdk', - 'src', 'runtime', 'include'), - ) - - # Copy over files to retain - for f in FILES_TO_RETAIN: - shutil.copy( - os.path.join(dartsdk_clone, f), - os.path.join(ROOT_PATH, 'third_party', 'dart-sdk', 'src', f), - ) - - # Source files that should compiled - source_files = [ - os.path.join('src', 'runtime', 'include', 'dart_api_dl.c'), - ] - - # Write fake-source files for ios/ which use #include "../..." to include - # the original source file. This is necessary because webcrypto.podspec - # cannot reference sources not under the ios/ folder. - # But the C-preprocessor can still include them :D - for f in source_files: - target = os.path.join(ROOT_PATH, 'ios', 'third_party', 'dart-sdk', f) - original = os.path.join(ROOT_PATH, 'third_party', 'dart-sdk', f) - rel = os.path.relpath(original, os.path.dirname(target)) - mkdirp(os.path.dirname(target)) - contents = '' - contents += FAKE_IOS_SOURCE_HEADER - contents += '\n' - contents += '#include "'+rel+'"\n' - writeFile(os.path.join('ios', 'third_party', 'dart-sdk', f), contents) - - # Write sources.cmake in third_party/dart-sdk/ - cmake_sources = '' - cmake_sources += SOURCES_CMAKE_HEADER - cmake_sources += '\nset(dart_dl_sources\n' - cmake_sources += '\n'.join(( - ' ${DARTSDK_ROOT}' + f for f in sorted(source_files) - )) - cmake_sources += '\n)\n' - writeFile( - os.path.join('third_party', 'dart-sdk', 'sources.cmake'), - cmake_sources, - ) - - # Copy LICENSE file for Dart SDK into third_party/dart-sdk/LICENSE - # because all files in this folder are copied or generated from Dart SDK. - LICENSE_src = os.path.join(dartsdk_clone, 'LICENSE') - LICENSE_dst = os.path.join( - ROOT_PATH, 'third_party', 'dart-sdk', 'LICENSE') - shutil.copy(LICENSE_src, LICENSE_dst) - - -def mkdirp(path): - if not os.path.isdir(path): - os.makedirs(path) - - -def main(): - try: - print('Updating third_party/dart-sdk/') - tmp = tempfile.mkdtemp(prefix='update-dart-sdk-') - cleanup() - git_clone(tmp) - generate(tmp) - print('Updated to dart_lang/sdk revision: ' + DARTSDK_REVISION) - finally: - shutil.rmtree(tmp) - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/tool/update_bindings.dart b/tool/update_bindings.dart deleted file mode 100644 index 7c9da8ab..00000000 --- a/tool/update_bindings.dart +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import 'dart:io'; - -void main(List arguments) async { - final root = - Directory.fromUri(Platform.script).parent.parent.uri.toFilePath(); - - final generateWebCryptoDL = Process.run('dart', [ - 'run', - 'ffigen', - '--config=$root/lib/src/boringssl/bindings/ffigen.yaml', - ]); - - final generateBoringSsl = Process.run('dart', [ - 'run', - 'ffigen', - '--config=$root/lib/src/third_party/boringssl/ffigen.yaml', - ]); - - final result1 = await generateWebCryptoDL; - print(result1.stdout); - print(result1.stderr); - final result2 = await generateBoringSsl; - print(result2.stdout); - print(result2.stderr); -}