initFromSodiumFFI static method
Creates a Sodium instance for the loaded libsodium returned by the
callback as LibSodiumFFI
.
Helper function that you can use if you can't provide a DynamicLibrary
for loading libsodium. Instead, you can pass the LibSodiumFFI
native
interface, which is the raw dart interface to access the C library.
Please note that LibSodiumFFI
is not documented, as it is an auto
generated binding, which simply mimics the C interface in dart, as
required by dart:ffi.
Implementation
static Future<Sodium> initFromSodiumFFI(
LibSodiumFFIFactory getSodium,
) async =>
Future.value(
SodiumFFI.fromFactory(() async {
final sodium = await getSodium();
final result = sodium.sodium_init();
SodiumException.checkSucceededInitInt(result);
return sodium;
}),
);