-
Notifications
You must be signed in to change notification settings - Fork 386
/
Copy pathBasicAuthCredentials.cs
51 lines (42 loc) · 1.44 KB
/
BasicAuthCredentials.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
48
49
50
51
using System.Net.Http;
using System.Security;
namespace Docker.DotNet.BasicAuth
{
public class BasicAuthCredentials : Credentials
{
private readonly bool _isTls;
private readonly MaybeSecureString _username;
private readonly MaybeSecureString _password;
public override HttpMessageHandler GetHandler(HttpMessageHandler innerHandler)
{
return new BasicAuthHandler(_username, _password, innerHandler);
}
public BasicAuthCredentials(SecureString username, SecureString password, bool isTls = false)
: this(new MaybeSecureString(username), new MaybeSecureString(password), isTls)
{
}
public BasicAuthCredentials(string username, string password, bool isTls = false)
: this(new MaybeSecureString(username), new MaybeSecureString(password), isTls)
{
}
private BasicAuthCredentials(MaybeSecureString username, MaybeSecureString password, bool isTls)
{
_isTls = isTls;
_username = username;
_password = password;
}
public override void Dispose()
{
_username.Dispose();
_password.Dispose();
}
public override bool SupportsScheme(string scheme)
{
return !(_isTls && scheme == "npipe");
}
public override bool IsTlsCredentials()
{
return _isTls;
}
}
}