Skip to content

Commit d7dc070

Browse files
committed
Move all interop code under Interop namespace
Move all the platform specific interop code to the `Interop` namespace and also group the P/Invoke calls into classes representing the modules/libraries/headers the original C functions live in.
1 parent 48553d0 commit d7dc070

File tree

22 files changed

+334
-332
lines changed

22 files changed

+334
-332
lines changed

src/shared/Microsoft.Git.CredentialManager.Tests/Commands/EraseCommandTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT license.
33
using System.Threading.Tasks;
44
using Microsoft.Git.CredentialManager.Commands;
5-
using Microsoft.Git.CredentialManager.SecureStorage;
65
using Microsoft.Git.CredentialManager.Tests.Objects;
76
using Moq;
87
using Xunit;

src/shared/Microsoft.Git.CredentialManager.Tests/Commands/StoreCommandTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT license.
33
using System.Threading.Tasks;
44
using Microsoft.Git.CredentialManager.Commands;
5-
using Microsoft.Git.CredentialManager.SecureStorage;
65
using Microsoft.Git.CredentialManager.Tests.Objects;
76
using Moq;
87
using Xunit;

src/shared/Microsoft.Git.CredentialManager.Tests/SecureStorage/MacOSKeychainTests.cs renamed to src/shared/Microsoft.Git.CredentialManager.Tests/Interop/MacOS/MacOSKeychainTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Licensed under the MIT license.
33
using System;
44
using Xunit;
5-
using Microsoft.Git.CredentialManager.SecureStorage;
5+
using Microsoft.Git.CredentialManager.Interop.MacOS;
66

7-
namespace Microsoft.Git.CredentialManager.Tests.SecureStorage
7+
namespace Microsoft.Git.CredentialManager.Tests.Interop.MacOS
88
{
99
public class MacOSKeychainTests
1010
{
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Licensed under the MIT license.
33
using System;
44
using Xunit;
5-
using Microsoft.Git.CredentialManager.SecureStorage;
5+
using Microsoft.Git.CredentialManager.Interop.Windows;
66

7-
namespace Microsoft.Git.CredentialManager.Tests.SecureStorage
7+
namespace Microsoft.Git.CredentialManager.Tests.Interop.Windows
88
{
99
public class WindowsCredentialManagerTests
1010
{

src/shared/Microsoft.Git.CredentialManager/Application.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.ComponentModel;
55
using System.Threading.Tasks;
66
using Microsoft.Git.CredentialManager.Commands;
7-
using Microsoft.Git.CredentialManager.SecureStorage;
87

98
namespace Microsoft.Git.CredentialManager
109
{

src/shared/Microsoft.Git.CredentialManager/CommandContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Text;
8-
using Microsoft.Git.CredentialManager.SecureStorage;
8+
using Microsoft.Git.CredentialManager.Interop.MacOS;
9+
using Microsoft.Git.CredentialManager.Interop.Windows;
910

1011
namespace Microsoft.Git.CredentialManager
1112
{

src/shared/Microsoft.Git.CredentialManager/Commands/EraseCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT license.
33
using System;
44
using System.Threading.Tasks;
5-
using Microsoft.Git.CredentialManager.SecureStorage;
65

76
namespace Microsoft.Git.CredentialManager.Commands
87
{

src/shared/Microsoft.Git.CredentialManager/Commands/GetCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT license.
33
using System.Collections.Generic;
44
using System.Threading.Tasks;
5-
using Microsoft.Git.CredentialManager.SecureStorage;
65

76
namespace Microsoft.Git.CredentialManager.Commands
87
{

src/shared/Microsoft.Git.CredentialManager/GitCredential.cs renamed to src/shared/Microsoft.Git.CredentialManager/Credential.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,46 @@
66

77
namespace Microsoft.Git.CredentialManager
88
{
9+
/// <summary>
10+
/// Represents a simple credential; user name and password pair.
11+
/// </summary>
12+
public interface ICredential
13+
{
14+
/// <summary>
15+
/// User name.
16+
/// </summary>
17+
string UserName { get; }
18+
19+
/// <summary>
20+
/// Password.
21+
/// </summary>
22+
string Password { get; }
23+
}
24+
925
/// <summary>
1026
/// Represents a credential (username/password pair) that Git can use to authenticate to a remote repository.
1127
/// </summary>
12-
public class GitCredential : SecureStorage.ICredential
28+
public class GitCredential : ICredential
1329
{
1430
public GitCredential(string userName, string password)
1531
{
1632
UserName = userName;
1733
Password = password;
1834
}
1935

20-
/// <summary>
21-
/// User name.
22-
/// </summary>
2336
public string UserName { get; }
2437

25-
/// <summary>
26-
/// Password.
27-
/// </summary>
2838
public string Password { get; }
39+
}
2940

41+
public static class CredentialExtensions
42+
{
3043
/// <summary>
31-
/// Returns the base-64 encoded, {username}:{password} formatted string of this `<see cref="GitCredential"/>`.
44+
/// Returns the base-64 encoded, {username}:{password} formatted string of this `<see cref="ICredential"/>`.
3245
/// </summary>
33-
public string ToBase64String()
46+
public static string ToBase64String(this ICredential credential)
3447
{
35-
string basicAuthValue = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", UserName, Password);
48+
string basicAuthValue = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", credential.UserName, credential.Password);
3649
byte[] authBytes = Encoding.UTF8.GetBytes(basicAuthValue);
3750
return Convert.ToBase64String(authBytes);
3851
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
3-
namespace Microsoft.Git.CredentialManager.SecureStorage
3+
4+
namespace Microsoft.Git.CredentialManager
45
{
56
/// <summary>
67
/// Represents a secure storage location for <see cref="ICredential"/>s.

0 commit comments

Comments
 (0)