Skip to content

Commit 9597543

Browse files
committed
Create user/pass credentials from native
1 parent a9d2f76 commit 9597543

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

LibGit2Sharp/Core/GitCredential.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace LibGit2Sharp.Core
5+
{
6+
[StructLayout(LayoutKind.Sequential)]
7+
internal class GitCredential
8+
{
9+
public GitCredentialType credtype;
10+
public IntPtr free;
11+
}
12+
}
13+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace LibGit2Sharp.Core
5+
{
6+
[StructLayout(LayoutKind.Sequential)]
7+
internal class GitCredentialUserpass
8+
{
9+
public GitCredential parent;
10+
public IntPtr username;
11+
public IntPtr password;
12+
}
13+
}
14+

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@
383383
<Compile Include="Core\GitCertificateSshType.cs" />
384384
<Compile Include="CertificateSsh.cs" />
385385
<Compile Include="IDiffResult.cs" />
386+
<Compile Include="Core\GitCredential.cs" />
387+
<Compile Include="Core\GitCredentialUserpass.cs" />
386388
</ItemGroup>
387389
<ItemGroup>
388390
<CodeAnalysisDictionary Include="CustomDictionary.xml" />

LibGit2Sharp/UsernamePasswordCredentials.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Text;
3+
using System.Runtime.InteropServices;
24
using LibGit2Sharp.Core;
35

46
namespace LibGit2Sharp
@@ -23,6 +25,15 @@ protected internal override int GitCredentialHandler(out IntPtr cred)
2325
return NativeMethods.git_cred_userpass_plaintext_new(out cred, Username, Password);
2426
}
2527

28+
static internal UsernamePasswordCredentials FromNative(GitCredentialUserpass gitCred)
29+
{
30+
return new UsernamePasswordCredentials()
31+
{
32+
Username = LaxUtf8Marshaler.FromNative(gitCred.username),
33+
Password = LaxUtf8Marshaler.FromNative(gitCred.password),
34+
};
35+
}
36+
2637
/// <summary>
2738
/// Username for username/password authentication (as in HTTP basic auth).
2839
/// </summary>

0 commit comments

Comments
 (0)