OpenSslBindings.load constructor

OpenSslBindings.load({
  1. String? cryptoPath,
  2. String? sslPath,
  3. bool requireKeyGeneration = false,
})

Attempts to load libssl/libcrypto using the provided overrides and platform defaults.

Implementation

factory OpenSslBindings.load({
  String? cryptoPath,
  String? sslPath,
  bool requireKeyGeneration = false,
}) {
  final cryptoLib = _loadDynamicLibrary(
    description: 'libcrypto',
    explicitPath: cryptoPath ?? Platform.environment['OPENSSL_LIBCRYPTO_PATH'],
    candidates: _cryptoCandidates(),
  );

  final sslLib = _loadDynamicLibrary(
    description: 'libssl',
    explicitPath: sslPath ?? Platform.environment['OPENSSL_LIBSSL_PATH'],
    candidates: _sslCandidates(),
  );

  final supportsFromData = _supportsFromDataKeygen(cryptoLib);
  if (requireKeyGeneration && !supportsFromData) {
    throw OpenSslLoadException(
      'Loaded OpenSSL build does not expose EVP_PKEY_fromdata symbols.\n'
      'Provide OpenSSL 3.x DLLs or pass explicit paths via OPENSSL_LIBCRYPTO_PATH/OPENSSL_LIBSSL_PATH.',
    );
  }

  return OpenSslBindings._(
    cryptoLib,
    sslLib,
    OpenSslFfi(cryptoLib),
    OpenSslFfi(sslLib),
    supportsFromData,
  );
}