Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,37 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor
// libc/OpenSSL libraries. Try them out.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// The libraries are located at 'runtimes/<rid>/native/lib{libraryName}.so'
// The <rid> ends with the processor architecture. e.g. fedora-x64.
string assemblyDirectory = Path.GetDirectoryName(AppContext.BaseDirectory);
string processorArchitecture = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
string runtimesDirectory = Path.Combine(assemblyDirectory, "runtimes");

// The default libgit2 binary is linked against OpenSSL 3. On hosts that have only
// libcrypto.so.1.1 fall back to the OpenSSL-1.1 variant shipped alongside it. We probe
// both layouts: flat (self-contained publish copies natives next to the assembly) and
// 'runtimes/<rid>/native/' (framework-dependent / build output).
if (!NativeLibrary.TryLoad("libcrypto.so.3", out _) && NativeLibrary.TryLoad("libcrypto.so.1.1", out _))
{
string variantFile = $"lib{libraryName}-openssl1.1.so";

string flatVariantPath = Path.Combine(assemblyDirectory, variantFile);
if (NativeLibrary.TryLoad(flatVariantPath, out handle))
{
return handle;
}

if (Directory.Exists(runtimesDirectory))
{
foreach (var runtimeFolder in Directory.GetDirectories(runtimesDirectory, $"*-{processorArchitecture}"))
{
string variantPath = Path.Combine(runtimeFolder, "native", variantFile);
if (NativeLibrary.TryLoad(variantPath, out handle))
{
return handle;
}
}
}
}

if (Directory.Exists(runtimesDirectory))
{
foreach (var runtimeFolder in Directory.GetDirectories(runtimesDirectory, $"*-{processorArchitecture}"))
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Octopus.LibGit2Sharp.NativeBinaries" Version="2.0.323-octopus.2" PrivateAssets="none" />
<PackageReference Include="Octopus.LibGit2Sharp.NativeBinaries" Version="2.0.323-octopus.2.octopus-em-build-for.48" PrivateAssets="none" />
<PackageReference Include="MinVer" Version="6.0.0" PrivateAssets="all" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace LibGit2Sharp
/// <summary>
/// Class that holds SSH username with key credentials for remote repository access.
/// </summary>
public sealed class SshUserKeyCredentials : Credentials
public sealed class SshKeyCredentials : Credentials
{
/// <summary>
/// Callback to acquire a credential object.
Expand All @@ -20,11 +20,6 @@ protected internal override int GitCredentialHandler(out IntPtr cred)
throw new InvalidOperationException("SshUserKeyCredentials contains a null Username.");
}

if (Passphrase == null)
{
throw new InvalidOperationException("SshUserKeyCredentials contains a null Passphrase.");
}

if (PrivateKey == null)
{
throw new InvalidOperationException("SshUserKeyCredentials contains a null PrivateKey.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace LibGit2Sharp
/// <summary>
/// Class that holds SSH username with in-memory key credentials for remote repository access.
/// </summary>
public sealed class SshUserKeyMemoryCredentials : Credentials
public sealed class SshKeyMemoryCredentials : Credentials
{
/// <summary>
/// Callback to acquire a credential object.
Expand All @@ -20,11 +20,6 @@ protected internal override int GitCredentialHandler(out IntPtr cred)
throw new InvalidOperationException("SshUserKeyMemoryCredentials contains a null Username.");
}

if (Passphrase == null)
{
throw new InvalidOperationException("SshUserKeyMemoryCredentials contains a null Passphrase.");
}

if (PrivateKey == null)
{
throw new InvalidOperationException("SshUserKeyMemoryCredentials contains a null PrivateKey.");
Expand Down