mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 03:16:11 +00:00
Revert "Implement extension methods and PublicKeyInfo class"
This reverts commit 1d82735096.
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
using Xunit;
|
||||
using Xunit.Extensions;
|
||||
|
||||
namespace Octokit.Tests.Models
|
||||
{
|
||||
public class PublicKeyExtensionsTests
|
||||
{
|
||||
public class TheGetKeyDataAndNameMethod
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAA timothy.clem@gmail.com", "AAAAB3NzaC1yc2EAAAABIwAA", "timothy.clem@gmail.com")]
|
||||
[InlineData("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAA", "AAAAB3NzaC1yc2EAAAABIwAA", "")]
|
||||
[InlineData("ssh-dss AAAAB3NzaC1yc2EAAAABIwAA", "AAAAB3NzaC1yc2EAAAABIwAA", "")]
|
||||
[InlineData("ssh-dsa AAAAB3NzaC1yc2EAAAABIwAA", "AAAAB3NzaC1yc2EAAAABIwAA", "")]
|
||||
public void CanParseKeyData(string raw, string data, string name)
|
||||
{
|
||||
var key = new PublicKey(raw);
|
||||
|
||||
PublicKeyInfo keyInfo = key.GetKeyDataAndName();
|
||||
Assert.Equal(data, keyInfo.Data);
|
||||
Assert.Equal(name, keyInfo.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(null)]
|
||||
[InlineData("apsdfoihat")]
|
||||
public void ParsingBadDataReturnsNull(string key)
|
||||
{
|
||||
Assert.Null(new PublicKey(key).GetKeyDataAndName());
|
||||
}
|
||||
}
|
||||
|
||||
public class TheHasSameDataAsMethod
|
||||
{
|
||||
[Fact]
|
||||
public void ReturnsTrueWhenTwoKeysHaveTheSameData()
|
||||
{
|
||||
var key = new PublicKey("ssh-dsa AAAAB3NzaC1yc2EAAAABIwAA");
|
||||
var anotherKey = new PublicKey("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAA");
|
||||
|
||||
Assert.True(key.HasSameDataAs(anotherKey));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReturnsFalseWhenCompareKeyIsNull()
|
||||
{
|
||||
var key = new PublicKey("ssh-dsa AAAAB3NzaC1yc2EAAAABIwAA");
|
||||
|
||||
Assert.False(key.HasSameDataAs(null));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, "ssh-dsa AAAAB3NzaC1yc2EAAAABIwAA")]
|
||||
[InlineData("ssh-dsa AAAAB3NzaC1yc2EAAAABIwAA", null)]
|
||||
[InlineData("ssh-dsa AAAAB3NzaC1yc2EAAAABIwAA", "ssh-dsa AAAAB3NzaC1yc2EAAAABIwAB")]
|
||||
public void ReturnsFalseWhenTwoKeysHaveDifferentData(string firstKey, string secondKey)
|
||||
{
|
||||
var key = new PublicKey(firstKey);
|
||||
var anotherKey = new PublicKey(secondKey);
|
||||
|
||||
Assert.False(key.HasSameDataAs(anotherKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,6 @@
|
||||
<Compile Include="Exceptions\RateLimitExceededExceptionTests.cs" />
|
||||
<Compile Include="Exceptions\TwoFactorRequiredExceptionTests.cs" />
|
||||
<Compile Include="Helpers\NSubstituteExtensions.cs" />
|
||||
<Compile Include="Helpers\PublicKeyExtensionsTests.cs" />
|
||||
<Compile Include="Helpers\ReflectionExtensions.cs" />
|
||||
<Compile Include="Helpers\UnixTimestampExtensionsTests.cs" />
|
||||
<Compile Include="Helpers\UriExtensionsTests.cs" />
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Octokit
|
||||
/// Extract SSH key information from the API response
|
||||
/// </summary>
|
||||
/// <param name="sshKey">Key details received from API</param>
|
||||
[Obsolete("This method is obsolete. Please use PublicKey.GetKeyDataAndName() instead.")]
|
||||
[Obsolete("This method will be removed in a future release.")]
|
||||
public static SshKeyInfo GetKeyDataAndName(this SshKey sshKey)
|
||||
{
|
||||
Ensure.ArgumentNotNull(sshKey, "sshKey");
|
||||
@@ -36,7 +36,7 @@ namespace Octokit
|
||||
/// </summary>
|
||||
/// <param name="key">Reference SSH key</param>
|
||||
/// <param name="otherKey">Key to compare</param>
|
||||
[Obsolete("This method is obsolete. Please use PublicKey.HasSameDataAs() instead.")]
|
||||
[Obsolete("This method will be removed in a future release.")]
|
||||
public static bool HasSameDataAs(this SshKey key, SshKey otherKey)
|
||||
{
|
||||
Ensure.ArgumentNotNull(key, "key");
|
||||
@@ -46,7 +46,7 @@ namespace Octokit
|
||||
return keyData != null && keyData == otherKey.GetKeyData();
|
||||
}
|
||||
|
||||
[Obsolete("This method is obsolete. Please use PublicKey.GetKeyData() instead.")]
|
||||
[Obsolete("This method will be removed in a future release.")]
|
||||
static string GetKeyData(this SshKey key)
|
||||
{
|
||||
var keyInfo = key.GetKeyDataAndName();
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// Extensions for working with PublicKeys
|
||||
/// </summary>
|
||||
public static class PublicKeyExtensions
|
||||
{
|
||||
#if NETFX_CORE
|
||||
static readonly Regex keyRegex = new Regex(@"ssh-[rd]s[as] (?<data>\S+) ?(?<name>.*)$");
|
||||
#else
|
||||
static readonly Regex keyRegex = new Regex(@"ssh-[rd]s[as] (?<data>\S+) ?(?<name>.*)$", RegexOptions.Compiled);
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Gets Name and Data components of a a <see cref="PublicKey"/>
|
||||
/// </summary>
|
||||
/// <param name="key"><see cref="PublicKey"/> received from API</param>
|
||||
/// <returns><see cref="PublicKeyInfo"/> object representing the data and name components of the <see cref="PublicKey"/></returns>
|
||||
public static PublicKeyInfo GetKeyDataAndName(this PublicKey key)
|
||||
{
|
||||
Ensure.ArgumentNotNull(key, "sshKey");
|
||||
|
||||
var keyInfo = key.Key;
|
||||
if (keyInfo == null) return null;
|
||||
var match = keyRegex.Match(keyInfo);
|
||||
return (match.Success ? new PublicKeyInfo(match.Groups["data"].Value, match.Groups["name"].Value) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets data component from a <see cref="PublicKey"/>
|
||||
/// </summary>
|
||||
/// <param name="key"><see cref="PublicKey"/> received from API</param>
|
||||
static string GetKeyData(this PublicKey key)
|
||||
{
|
||||
var keyInfo = key.GetKeyDataAndName();
|
||||
return keyInfo == null ? null : keyInfo.Data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compare two <see cref="PublicKey"/>s to see if they have equal data components
|
||||
/// </summary>
|
||||
/// <param name="key">Reference <see cref="PublicKey"/></param>
|
||||
/// <param name="otherKey"><see cref="PublicKey"/> to compare</param>
|
||||
public static bool HasSameDataAs(this PublicKey key, PublicKey otherKey)
|
||||
{
|
||||
Ensure.ArgumentNotNull(key, "key");
|
||||
|
||||
if (otherKey == null) return false;
|
||||
var keyData = key.GetKeyData();
|
||||
return keyData != null && keyData == otherKey.GetKeyData();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the data and name parsed from a PublicKey.
|
||||
/// </summary>
|
||||
public class PublicKeyInfo
|
||||
{
|
||||
public PublicKeyInfo(string data, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNull(data, "data");
|
||||
Ensure.ArgumentNotNull(name, "name");
|
||||
|
||||
Data = data;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public string Data { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,6 @@ namespace Octokit
|
||||
{
|
||||
public PublicKey() { }
|
||||
|
||||
public PublicKey(string key)
|
||||
{
|
||||
Key = key;
|
||||
}
|
||||
|
||||
public PublicKey(int id, string key, string url, string title)
|
||||
{
|
||||
Id = id;
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Octokit
|
||||
/// <summary>
|
||||
/// Represents the data and name parsed from the Ssh key.
|
||||
/// </summary>
|
||||
[Obsolete("This helper class is obsolete. Please use PublicKeyInfo instead.")]
|
||||
[Obsolete("This class will be removed in a future release.")]
|
||||
public class SshKeyInfo
|
||||
{
|
||||
public SshKeyInfo(string data, string name)
|
||||
|
||||
@@ -456,8 +456,6 @@
|
||||
<Compile Include="Models\Request\UserRename.cs" />
|
||||
<Compile Include="Models\Response\UserRenameResponse.cs" />
|
||||
<Compile Include="Models\Request\NewPublicKey.cs" />
|
||||
<Compile Include="Helpers\PublicKeyExtensions.cs" />
|
||||
<Compile Include="Helpers\PublicKeyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -465,8 +465,6 @@
|
||||
<Compile Include="Models\Request\UserRename.cs" />
|
||||
<Compile Include="Models\Response\UserRenameResponse.cs" />
|
||||
<Compile Include="Models\Request\NewPublicKey.cs" />
|
||||
<Compile Include="Helpers\PublicKeyExtensions.cs" />
|
||||
<Compile Include="Helpers\PublicKeyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -461,8 +461,6 @@
|
||||
<Compile Include="Models\Request\UserRename.cs" />
|
||||
<Compile Include="Models\Response\UserRenameResponse.cs" />
|
||||
<Compile Include="Models\Request\NewPublicKey.cs" />
|
||||
<Compile Include="Helpers\PublicKeyExtensions.cs" />
|
||||
<Compile Include="Helpers\PublicKeyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -453,8 +453,6 @@
|
||||
<Compile Include="Models\Request\UserRename.cs" />
|
||||
<Compile Include="Models\Response\UserRenameResponse.cs" />
|
||||
<Compile Include="Models\Request\NewPublicKey.cs" />
|
||||
<Compile Include="Helpers\PublicKeyExtensions.cs" />
|
||||
<Compile Include="Helpers\PublicKeyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
|
||||
@@ -460,8 +460,6 @@
|
||||
<Compile Include="Models\Request\UserRename.cs" />
|
||||
<Compile Include="Models\Response\UserRenameResponse.cs" />
|
||||
<Compile Include="Models\Request\NewPublicKey.cs" />
|
||||
<Compile Include="Helpers\PublicKeyExtensions.cs" />
|
||||
<Compile Include="Helpers\PublicKeyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
|
||||
@@ -103,9 +103,7 @@
|
||||
<Compile Include="Helpers\ApiUrls.Authorizations.cs" />
|
||||
<Compile Include="Helpers\ConcurrentCache.cs" />
|
||||
<Compile Include="Helpers\HttpClientExtensions.cs" />
|
||||
<Compile Include="Helpers\PublicKeyExtensions.cs" />
|
||||
<Compile Include="Helpers\PropertyOrField.cs" />
|
||||
<Compile Include="Helpers\PublicKeyInfo.cs" />
|
||||
<Compile Include="Helpers\ReferenceExtensions.cs" />
|
||||
<Compile Include="Helpers\SerializeNullAttribute.cs" />
|
||||
<Compile Include="Helpers\WebHookConfigComparer.cs" />
|
||||
|
||||
Reference in New Issue
Block a user