-
Notifications
You must be signed in to change notification settings - Fork 892
/
Copy pathUsernamePasswordCredentials.cs
47 lines (42 loc) · 1.69 KB
/
UsernamePasswordCredentials.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Text;
using System.Runtime.InteropServices;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
/// <summary>
/// Class that holds username and password credentials for remote repository access.
/// </summary>
public sealed class UsernamePasswordCredentials : Credentials
{
/// <summary>
/// Callback to acquire a credential object.
/// </summary>
/// <param name="cred">The newly created credential object.</param>
/// <returns>0 for success, < 0 to indicate an error, > 0 to indicate no credential was acquired.</returns>
protected internal override int GitCredentialHandler(out IntPtr cred)
{
if (Username == null || Password == null)
{
throw new InvalidOperationException("UsernamePasswordCredentials contains a null Username or Password.");
}
return NativeMethods.git_cred_userpass_plaintext_new(out cred, Username, Password);
}
static internal unsafe UsernamePasswordCredentials FromNative(GitCredentialUserpass* gitCred)
{
return new UsernamePasswordCredentials()
{
Username = LaxUtf8Marshaler.FromNative(gitCred->username),
Password = LaxUtf8Marshaler.FromNative(gitCred->password),
};
}
/// <summary>
/// Username for username/password authentication (as in HTTP basic auth).
/// </summary>
public string Username { get; set; }
/// <summary>
/// Password for username/password authentication (as in HTTP basic auth).
/// </summary>
public string Password { get; set; }
}
}