Skip to content

Commit

Permalink
fix IDE0007everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
dlech committed Feb 5, 2022
1 parent 281e06f commit 1b92974
Show file tree
Hide file tree
Showing 43 changed files with 481 additions and 505 deletions.
8 changes: 6 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
###############################
# Core EditorConfig Options #
###############################
Expand All @@ -14,4 +14,8 @@ indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8-bom

[*.cs]

# IDE0007: Use implicit type
dotnet_diagnostic.IDE0007.severity = suggestion
24 changes: 11 additions & 13 deletions SshAgentLib/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void AddKey(ISshKey key)

/* handle constraints */

foreach (KeyConstraint constraint in key.Constraints)
foreach (var constraint in key.Constraints)
{
if (
constraint.Type == KeyConstraintType.SSH_AGENT_CONSTRAIN_CONFIRM
Expand Down Expand Up @@ -296,7 +296,7 @@ void onTimerElapsed(object s, ElapsedEventArgs e)
}

/* first remove matching key if it exists */
ISshKey matchingKey = keyList.Get(key.Version, key.GetPublicKeyBlob());
var matchingKey = keyList.Get(key.Version, key.GetPublicKeyBlob());
RemoveKey(matchingKey);

keyList.Add(key);
Expand Down Expand Up @@ -325,7 +325,7 @@ public void RemoveAllKeys(SshVersion aVersion)

var removeKeyList = ListKeys(aVersion);

foreach (ISshKey key in removeKeyList)
foreach (var key in removeKeyList)
{
RemoveKey(key);
}
Expand Down Expand Up @@ -353,7 +353,7 @@ public void Lock(byte[] aPassphrase)

if (aPassphrase != null)
{
foreach (byte b in aPassphrase)
foreach (var b in aPassphrase)
{
lockedPassphrase.AppendChar((char)b);
}
Expand Down Expand Up @@ -382,9 +382,9 @@ public void Unlock(byte[] aPassphrase)
throw new PassphraseException();
}

IntPtr lockedPassPtr = Marshal.SecureStringToGlobalAllocUnicode(lockedPassphrase);
var lockedPassPtr = Marshal.SecureStringToGlobalAllocUnicode(lockedPassphrase);

for (int i = 0; i < lockedPassphrase.Length; i++)
for (var i = 0; i < lockedPassphrase.Length; i++)
{
var lockedPassChar = Marshal.ReadInt16(lockedPassPtr, i * 2);

Expand Down Expand Up @@ -580,7 +580,7 @@ public void AnswerMessage(Stream messageStream, Process process = null)
encryptedChallenge.Length
);

using (MD5 md5 = MD5.Create())
using (var md5 = MD5.Create())
{
var md5Buffer = new byte[48];
decryptedChallenge.CopyTo(md5Buffer, 0);
Expand Down Expand Up @@ -762,15 +762,13 @@ public void AnswerMessage(Stream messageStream, Process process = null)
goto default;
}

bool constrained = header.Message == Message.SSH2_AGENTC_ADD_ID_CONSTRAINED;
var constrained = header.Message == Message.SSH2_AGENTC_ADD_ID_CONSTRAINED;

try
{
var publicKeyParams = messageParser.ReadSsh2PublicKeyData(
out OpensshCertificate cert
);
var publicKeyParams = messageParser.ReadSsh2PublicKeyData(out var cert);
var keyPair = messageParser.ReadSsh2KeyData(publicKeyParams);
SshKey key = new SshKey(SshVersion.SSH2, keyPair, null, cert)
var key = new SshKey(SshVersion.SSH2, keyPair, null, cert)
{
Comment = messageParser.ReadString(),
Source = "External client"
Expand All @@ -780,7 +778,7 @@ out OpensshCertificate cert
{
while (messageParser.BaseStream.Position < header.BlobLength + 4)
{
KeyConstraint constraint = new KeyConstraint
var constraint = new KeyConstraint
{
Type = (KeyConstraintType)messageParser.ReadByte()
};
Expand Down
28 changes: 13 additions & 15 deletions SshAgentLib/AgentClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// AgentClient.cs
//
// Author(s): David Lechner <[email protected]>
Expand Down Expand Up @@ -161,7 +161,7 @@ public void RemoveKey(ISshKey key)

public void RemoveAllKeys(SshVersion version)
{
BlobBuilder builder = new BlobBuilder();
var builder = new BlobBuilder();
ICollection<ISshKey> keys = null;
if (KeyRemoved != null)
keys = ListKeys(version);
Expand All @@ -186,7 +186,7 @@ public void RemoveAllKeys(SshVersion version)

public ICollection<ISshKey> ListKeys(SshVersion aVersion)
{
BlobBuilder builder = new BlobBuilder();
var builder = new BlobBuilder();
switch (aVersion)
{
case SshVersion.SSH1:
Expand All @@ -198,7 +198,7 @@ public ICollection<ISshKey> ListKeys(SshVersion aVersion)
default:
throw new Exception(cUnsupportedSshVersion);
}
BlobParser replyParser = SendMessage(builder);
var replyParser = SendMessage(builder);
var keyCollection = new List<ISshKey>();
var header = replyParser.ReadHeader();
switch (aVersion)
Expand Down Expand Up @@ -228,9 +228,7 @@ public ICollection<ISshKey> ListKeys(SshVersion aVersion)
{
var publicKeyBlob = replyParser.ReadBlob();
var publicKeyParser = new BlobParser(publicKeyBlob);
var publicKeyParams = publicKeyParser.ReadSsh2PublicKeyData(
out OpensshCertificate cert
);
var publicKeyParams = publicKeyParser.ReadSsh2PublicKeyData(out var cert);
var comment = replyParser.ReadString();
keyCollection.Add(
new SshKey(SshVersion.SSH2, publicKeyParams, null, comment, cert)
Expand All @@ -245,7 +243,7 @@ out OpensshCertificate cert

public byte[] SignRequest(ISshKey aKey, byte[] aSignData)
{
BlobBuilder builder = new BlobBuilder();
var builder = new BlobBuilder();
switch (aKey.Version)
{
case SshVersion.SSH1:
Expand All @@ -272,7 +270,7 @@ public byte[] SignRequest(ISshKey aKey, byte[] aSignData)
throw new Exception(cUnsupportedSshVersion);
}

BlobParser replyParser = SendMessage(builder);
var replyParser = SendMessage(builder);
var header = replyParser.ReadHeader();

switch (aKey.Version)
Expand All @@ -283,9 +281,9 @@ public byte[] SignRequest(ISshKey aKey, byte[] aSignData)
throw new AgentFailureException();
}

byte[] response = new byte[16];
var response = new byte[16];

for (int i = 0; i < 16; i++)
for (var i = 0; i < 16; i++)
{
response[i] = replyParser.ReadByte();
}
Expand All @@ -309,7 +307,7 @@ public void Lock(byte[] passphrase)
throw new ArgumentNullException(nameof(passphrase));
}

BlobBuilder builder = new BlobBuilder();
var builder = new BlobBuilder();
builder.AddBlob(passphrase);
builder.InsertHeader(Agent.Message.SSH_AGENTC_LOCK);
SendMessageAndCheckSuccess(builder);
Expand All @@ -322,7 +320,7 @@ public void Unlock(byte[] passphrase)
throw new ArgumentNullException(nameof(passphrase));
}

BlobBuilder builder = new BlobBuilder();
var builder = new BlobBuilder();
builder.AddBlob(passphrase);
builder.InsertHeader(Agent.Message.SSH_AGENTC_UNLOCK);
SendMessageAndCheckSuccess(builder);
Expand Down Expand Up @@ -450,7 +448,7 @@ private void FireKeyAdded(ISshKey key)
{
if (KeyAdded != null)
{
SshKeyEventArgs args = new SshKeyEventArgs(key);
var args = new SshKeyEventArgs(key);
KeyAdded(this, args);
}
}
Expand All @@ -459,7 +457,7 @@ private void FireKeyRemoved(ISshKey key)
{
if (KeyRemoved != null)
{
SshKeyEventArgs args = new SshKeyEventArgs(key);
var args = new SshKeyEventArgs(key);
KeyRemoved(this, args);
}
}
Expand Down
8 changes: 4 additions & 4 deletions SshAgentLib/BlobBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void AddStringBlob(string value)
/// <param name="value"></param>
public void AddBigIntBlob(BigInteger value)
{
byte[] bytes = value.ToByteArray();
var bytes = value.ToByteArray();
AddBlob(bytes);
}

Expand All @@ -118,10 +118,10 @@ public void AddBigIntBlob(BigInteger value)
/// <param name="value"></param>
public void AddSsh1BigIntBlob(BigInteger value)
{
ushort size = (ushort)(value.BitLength);
var size = (ushort)(value.BitLength);
AddUInt8((byte)((size >> 8) & 0xFF));
AddUInt8((byte)(size & 0xFF));
byte[] bytes = value.ToByteArrayUnsigned();
var bytes = value.ToByteArrayUnsigned();
byteList.AddRange(bytes);
}

Expand Down Expand Up @@ -153,7 +153,7 @@ public void InsertHeader(Agent.Message message, int headerData)
public void InsertHeader(Agent.Message message)
{
byteList.Insert(0, (byte)message);
byte[] blobLength = byteList.Count.ToBytes();
var blobLength = byteList.Count.ToBytes();
byteList.InsertRange(0, blobLength);
}

Expand Down
6 changes: 3 additions & 3 deletions SshAgentLib/BlobParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public override ulong ReadUInt64()

public Agent.BlobHeader ReadHeader()
{
Agent.BlobHeader header = new Agent.BlobHeader
var header = new Agent.BlobHeader
{
BlobLength = ReadInt32(),
Message = (Agent.Message)ReadByte()
Expand Down Expand Up @@ -401,7 +401,7 @@ public AsymmetricCipherKeyPair ReadSsh2KeyData(AsymmetricKeyParameter publicKeyP
var dsaX = new BigInteger(1, ReadBlob()); // private key

var dsaPublicKeyParams = publicKeyParameter as DsaPublicKeyParameters;
DsaPrivateKeyParameters dsaPrivateKeyParams = new DsaPrivateKeyParameters(
var dsaPrivateKeyParams = new DsaPrivateKeyParameters(
dsaX,
dsaPublicKeyParams.Parameters
);
Expand All @@ -413,7 +413,7 @@ public AsymmetricCipherKeyPair ReadSsh2KeyData(AsymmetricKeyParameter publicKeyP
var ecdsaPrivate = new BigInteger(1, ReadBlob());

var ecPublicKeyParams = publicKeyParameter as ECPublicKeyParameters;
ECPrivateKeyParameters ecPrivateKeyParams = new ECPrivateKeyParameters(
var ecPrivateKeyParams = new ECPrivateKeyParameters(
ecdsaPrivate,
ecPublicKeyParams.Parameters
);
Expand Down
Loading

0 comments on commit 1b92974

Please sign in to comment.