8000 Add reference to Libgit2sharp.NativeBinaries package built with SSH s… · UiPath/libgit2sharp@ce6bdab · GitHub
[go: up one dir, main page]

Skip to content

Commit ce6bdab

Browse files
committed
Add reference to Libgit2sharp.NativeBinaries package built with SSH support
using libgit2 v 0.28.1
1 parent a709ab8 commit ce6bdab

File tree

4 files changed

+116
-1
lines changed

4 files changed

+116
-1
lines changed

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,19 @@ internal static extern int git_cred_userpass_plaintext_new(
515515
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
516516
internal static extern void git_cred_free(IntPtr cred);
517517

518+
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
519+
internal static extern int git_cred_ssh_key_new(
520+
out IntPtr cred,
521+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string username,
522+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string publickey,
523+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string privatekey,
524+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string passphrase);
525+
526+
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
527+
internal static extern int git_cred_ssh_key_from_agent(
528+
out IntPtr cred,
529+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string username);
530+
518531
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
519532
internal static extern unsafe int git_describe_commit(
520533
out git_describe_result* describe,

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Include="LibGit2Sharp.NativeBinaries" Version="[2.0.267]" PrivateAssets="none" />
32+
<PackageReference Include="LibGit2Sharp.NativeBinaries" Version="0.28.1-ssh" PrivateAssets="none" />
3333
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-63127-02" PrivateAssets="all" />
3434
<PackageReference Include="Nerdbank.GitVersioning" Version="2.2.13" PrivateAssets="all" />
3535
</ItemGroup>

LibGit2Sharp/SshAgentCredentials.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using LibGit2Sharp.Core;
3+
4+
namespace LibGit2Sharp
5+
{
6+
/// <summary>
7+
/// Class that holds SSH agent credentials for remote repository access.
8+
/// </summary>
9+
public sealed class SshAgentCredentials : Credentials
10+
{
11+
/// <summary>
12+
/// Callback to acquire a credential object.
13+
/// </summary>
14+
/// <param name="cred">The newly created credential object.</param>
15+
/// <returns>0 for success, &lt; 0 to indicate an error, &gt; 0 to indicate no credential was acquired.</returns>
16+
protected internal override int GitCredentialHandler(out IntPtr cred)
17+
{
18+
if (!GlobalSettings.Version.Features.HasFlag(BuiltInFeatures.Ssh))
19+
{
20+
throw new InvalidOperationException("LibGit2 was not built with SSH support.");
21+
}
22+
23+
if (Username == null)
24+
{
25+
throw new InvalidOperationException("SshAgentCredentials contains a null Username.");
26+
}
27+
28+
return NativeMethods.git_cred_ssh_key_from_agent(out cred, Username);
29+
}
30+
31+
/// <summary>
32+
/// Username for SSH authentication.
33+
/// </summary>
34+
public string Username { get; set; }
35+
}
36+
}

LibGit2Sharp/SshUserKeyCredentials.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using LibGit2Sharp.Core;
3+
4+
namespace LibGit2Sharp
5+
{
6+
/// <summary>
7+
/// Class that holds SSH username with key credentials for remote repository access.
8+
/// </summary>
9+
public sealed class SshUserKeyCredentials : Credentials
10+
{
11+
/// <summary>
12+
/// Callback to acquire a credential object.
13+
/// </summary>
14+
/// <param name="cred">The newly created credential object.</param>
15+
/// <returns>0 for success, &lt; 0 to indicate an error, &gt; 0 to indicate no credential was acquired.</returns>
16+
protected internal override int GitCredentialHandler(out IntPtr cred)
17+
{
18+
if (!GlobalSettings.Version.Features.HasFlag(BuiltInFeatures.Ssh))
19+
{
20+
throw new InvalidOperationException("LibGit2 was not built with SSH support.");
21+
}
22+
23+
if (Username == null)
24+
{
25+
throw new InvalidOperationException("SshUserKeyCredentials contains a null Username.");
26+
}
27+
28+
if (Passphrase == null)
29+
{
30+
throw new InvalidOperationException("SshUserKeyCredentials contains a null Passphrase.");
31+
}
32+
33+
if (PublicKey == null)
34+
{
35+
throw new InvalidOperationException("SshUserKeyCredentials contains a null PublicKey.");
36+
}
37+
38+
if (PrivateKey == null)
39+
{
40+
throw new InvalidOperationException("SshUserKeyCredentials contains a null PrivateKey.");
41+
}
42+
43+
return NativeMethods.git_cred_ssh_key_new(out cred, Username, PublicKey, PrivateKey, Passphrase);
44+
}
45+
46+
/// <summary>
47+
/// Username for SSH authentication.
48+
/// </summary>
49+
public string Username { get; set; }
50+
51+
/// <summary>
52+
/// Public key file location for SSH authentication.
53+
/// </summary>
54+
public string PublicKey { get; set; }
55+
56+
/// <summary>
57+
/// Private key file location for SSH authentication.
58+
/// </summary>
59+
public string PrivateKey { get; set; }
60+
61+
/// <summary>
62+
/// Passphrase for SSH authentication.
63+
/// </summary>
64+
public string Passphrase { get; set; }
65+
}
66+
}

0 commit comments

Comments
 (0)
0