Skip to content

Commit

Permalink
Use var instead of explicit type everywhere but Core
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisDyallo committed Aug 14, 2024
1 parent ae0a608 commit a6e1b42
Show file tree
Hide file tree
Showing 201 changed files with 1,536 additions and 1,583 deletions.
3 changes: 1 addition & 2 deletions Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
using System.Globalization;
using System.Linq;
using Microsoft.Extensions.Logging;
using Yubico.PlatformInterop;
using Yubico.Core.Logging;

using Yubico.PlatformInterop;
using static Yubico.PlatformInterop.NativeMethods;

namespace Yubico.Core.Devices.Hid
Expand Down
4 changes: 2 additions & 2 deletions Yubico.DotNetPolyfills/src/Contrib.Bcl.Ranges/Range.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ value is Range r &&
public (int Offset, int Length) GetOffsetAndLength(int length)
{
int start;
Index startIndex = Start;
var startIndex = Start;
if (startIndex.IsFromEnd)
{
start = length - startIndex.Value;
Expand All @@ -88,7 +88,7 @@ value is Range r &&
}

int end;
Index endIndex = End;
var endIndex = End;
if (endIndex.IsFromEnd)
{
end = length - endIndex.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public bool LaunchPinPopup(KeyEntryData keyEntryData)
return false;
}

DialogResult dResult = DialogResult.OK;
var dResult = DialogResult.OK;
do
{
_pinPopupForm.UpdateMessage(dResult, keyEntryData);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static bool RunGetAssertions(
// verification needed.
assertions = fido2Session.GetAssertions(getAssertionParameters);

foreach (GetAssertionData assertionData in assertions)
foreach (var assertionData in assertions)
{
byte[] hmacSecret = assertionData.AuthenticatorData.GetHmacSecretExtension(fido2Session.AuthProtocol);
hmacSecretList.Add(hmacSecret);
Expand Down Expand Up @@ -201,15 +201,15 @@ public static bool RunGetCredentialData(

returnValue.Add(new Tuple<int, int>(credCount, remainingCount));

IReadOnlyList<RelyingParty> rpList = fido2Session.EnumerateRelyingParties();
foreach (RelyingParty currentRp in rpList)
var rpList = fido2Session.EnumerateRelyingParties();
foreach (var currentRp in rpList)
{
returnValue.Add(currentRp);

IReadOnlyList<CredentialUserInfo> credentialList =
var credentialList =
fido2Session.EnumerateCredentialsForRelyingParty(currentRp);

foreach (CredentialUserInfo currentCredential in credentialList)
foreach (var currentCredential in credentialList)
{
returnValue.Add(currentCredential);
}
Expand Down Expand Up @@ -288,7 +288,7 @@ public static string GetLargeBlobEntry(
throw new ArgumentNullException(nameof(blobArray));
}

Memory<byte> plaintext = Memory<byte>.Empty;
var plaintext = Memory<byte>.Empty;
byte[] plainArray = Array.Empty<byte>();
entryIndex = -1;
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ResponseStatus RunFido2Reset(Func<KeyEntryData, bool> KeyCollector)
{
// The SDK comes with a listener that can tell when a YubiKey has
// been removed or inserted.
YubiKeyDeviceListener yubiKeyDeviceListener = YubiKeyDeviceListener.Instance;
var yubiKeyDeviceListener = YubiKeyDeviceListener.Instance;

yubiKeyDeviceListener.Arrived += YubiKeyInserted;
yubiKeyDeviceListener.Removed += YubiKeyRemoved;
Expand Down Expand Up @@ -153,7 +153,7 @@ public ResponseStatus RunFido2Reset(Func<KeyEntryData, bool> KeyCollector)
touchMessageTask.Start();

var resetCmd = new ResetCommand();
ResetResponse resetRsp = fido2Session.Connection.SendCommand(resetCmd);
var resetRsp = fido2Session.Connection.SendCommand(resetCmd);

return resetRsp.Status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ private void RunDefaultCollectCredential()
SampleMenu.WriteMessage(MessageType.Title, 0, "Enter account name");
_ = SampleMenu.ReadResponse(out string account);

_ = ChooseCredentialProperties.RunChooseTypeOption(_menuObject, out CredentialType? type);
_ = ChooseCredentialProperties.RunChooseTypeOption(_menuObject, out var type);

CredentialPeriod period = CredentialPeriod.Undefined;
var period = CredentialPeriod.Undefined;

if (type == CredentialType.Totp)
{
_ = ChooseCredentialProperties.RunChoosePeriodOption(_menuObject, out CredentialPeriod? credentialPeriod);
_ = ChooseCredentialProperties.RunChoosePeriodOption(_menuObject, out var credentialPeriod);
period = (CredentialPeriod)credentialPeriod;
}

Expand Down Expand Up @@ -230,7 +230,7 @@ private bool RunRenameCredentialMenuItem(int? index)
else
{
RunCollectCredential(_menuObject,
out Credential credential,
out var credential,
out string newIssuer,
out string newAccount);

Expand All @@ -256,13 +256,13 @@ private static void RunCollectCredential(
SampleMenu.WriteMessage(MessageType.Title, 0, "Enter current account name");
_ = SampleMenu.ReadResponse(out string currentAccount);

_ = ChooseCredentialProperties.RunChooseTypeOption(menuObject, out CredentialType? type);
_ = ChooseCredentialProperties.RunChooseTypeOption(menuObject, out var type);

CredentialPeriod period = CredentialPeriod.Undefined;
var period = CredentialPeriod.Undefined;

if (type == CredentialType.Totp)
{
_ = ChooseCredentialProperties.RunChoosePeriodOption(menuObject, out CredentialPeriod? credentialPeriod);
_ = ChooseCredentialProperties.RunChoosePeriodOption(menuObject, out var credentialPeriod);
period = credentialPeriod.Value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static bool RunAddTotpCredential(
}
else
{
Credential credential = CollectTotpCredential(menuObject);
var credential = CollectTotpCredential(menuObject);
oathSession.AddCredential(credential);
ReportResult(credential);
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public static bool RunAddHotpCredential(
}
else
{
Credential credential = CollectHotpCredential(menuObject);
var credential = CollectHotpCredential(menuObject);
oathSession.AddCredential(credential);
ReportResult(credential);
}
Expand All @@ -116,12 +116,12 @@ public static bool RunAddDefaultTotpCredential(

if (menuObject is null)
{
Credential credential = oathSession.AddCredential("Yubico", "[email protected]");
var credential = oathSession.AddCredential("Yubico", "[email protected]");
ReportResult(credential);
}
else
{
Credential credential = CollectDefaultTotpCredential();
var credential = CollectDefaultTotpCredential();
oathSession.AddCredential(credential);
ReportResult(credential);
}
Expand All @@ -144,7 +144,7 @@ public static bool RunAddDefaultHotpCredential(

if (menuObject is null)
{
Credential credential = oathSession.AddCredential(
var credential = oathSession.AddCredential(
"Yubico",
"[email protected]",
CredentialType.Hotp,
Expand All @@ -153,7 +153,7 @@ public static bool RunAddDefaultHotpCredential(
}
else
{
Credential credential = CollectDefaultHotpCredential();
var credential = CollectDefaultHotpCredential();
oathSession.AddCredential(credential);
ReportResult(credential);
}
Expand All @@ -176,14 +176,14 @@ public static bool RunAddCredentialFromQR(

if (menuObject is null)
{
Credential credential = oathSession.AddCredential(
var credential = oathSession.AddCredential(
"otpauth://totp/Yubico:[email protected]?secret=YY4KVNOUQ5IIUBAOGIDRYZ7FGY54VW54&issuer=Yubico&algorithm=SHA1&digits=6&period=30");
ReportResult(credential);
}
else
{
string stringFromUri = CollectStringFromUri();
Credential credential = oathSession.AddCredential(stringFromUri);
var credential = oathSession.AddCredential(stringFromUri);
ReportResult(credential);
}
}
Expand Down Expand Up @@ -254,9 +254,9 @@ private static Credential CollectTotpCredential(SampleMenu menuObject)
SampleMenu.WriteMessage(MessageType.Title, 0, "Enter account name");
_ = SampleMenu.ReadResponse(out string account);

_ = ChooseCredentialProperties.RunChoosePeriodOption(menuObject, out CredentialPeriod? period);
_ = ChooseCredentialProperties.RunChoosePeriodOption(menuObject, out var period);

_ = ChooseCredentialProperties.RunChooseAlgorithmOption(menuObject, out HashAlgorithm? algorithm);
_ = ChooseCredentialProperties.RunChooseAlgorithmOption(menuObject, out var algorithm);

SampleMenu.WriteMessage(MessageType.Title, 0, "Enter secret");
_ = SampleMenu.ReadResponse(out string secret);
Expand Down Expand Up @@ -290,7 +290,7 @@ private static Credential CollectHotpCredential(SampleMenu menuObject)
SampleMenu.WriteMessage(MessageType.Title, 0, "Enter account name");
_ = SampleMenu.ReadResponse(out string account);

_ = ChooseCredentialProperties.RunChooseAlgorithmOption(menuObject, out HashAlgorithm? algorithm);
_ = ChooseCredentialProperties.RunChooseAlgorithmOption(menuObject, out var algorithm);

SampleMenu.WriteMessage(MessageType.Title, 0, "Enter secret");
_ = SampleMenu.ReadResponse(out string secret);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public static bool RunCalculateCredentials(IYubiKeyDevice yubiKey, Func<KeyEntry
using var oathSession = new OathSession(yubiKey);
{
oathSession.KeyCollector = KeyCollectorDelegate;
IDictionary<Credential, Code> result = oathSession.CalculateAllCredentials();
ReportAllResults(result);
var results = oathSession.CalculateAllCredentials();
ReportAllResults(results);
}

return true;
Expand All @@ -49,7 +49,7 @@ public static bool RunCalculateOneCredential(
using var oathSession = new OathSession(yubiKey);
{
oathSession.KeyCollector = KeyCollectorDelegate;
Code code = oathSession.CalculateCredential(credential);
var code = oathSession.CalculateCredential(credential);
ReportOneResult(credential, code);
}

Expand All @@ -64,18 +64,18 @@ private static void ReportAllResults(IDictionary<Credential, Code> credentials)
{
_ = outputList.AppendLine($"Number of credentials: {credentials.Count}");
_ = outputList.AppendLine();
foreach (KeyValuePair<Credential, Code> pair in credentials)
foreach (var (credential, code) in credentials)
{
_ = outputList.AppendLine($"Issuer : {pair.Key.Issuer}");
_ = outputList.AppendLine($"Account : {pair.Key.AccountName}");
_ = outputList.AppendLine($"Type : {pair.Key.Type}");
_ = outputList.AppendLine($"Period : {(int?)pair.Key.Period}sec");
_ = outputList.AppendLine($"Digits : {pair.Key.Digits}");
_ = outputList.AppendLine($"Touch : {pair.Key.RequiresTouch}");
_ = outputList.AppendLine($"OTP code : {pair.Value.Value}");
_ = outputList.AppendLine($"ValidFrom : {pair.Value.ValidFrom}");
_ = outputList.AppendLine($"ValidUntil: {pair.Value.ValidUntil}");
_ = outputList.AppendLine($"Name : {pair.Key.Name}");
_ = outputList.AppendLine($"Issuer : {credential.Issuer}");
_ = outputList.AppendLine($"Account : {credential.AccountName}");
_ = outputList.AppendLine($"Type : {credential.Type}");
_ = outputList.AppendLine($"Period : {(int?)credential.Period}sec");
_ = outputList.AppendLine($"Digits : {credential.Digits}");
_ = outputList.AppendLine($"Touch : {credential.RequiresTouch}");
_ = outputList.AppendLine($"OTP code : {code.Value}");
_ = outputList.AppendLine($"ValidFrom : {code.ValidFrom}");
_ = outputList.AppendLine($"ValidUntil: {code.ValidUntil}");
_ = outputList.AppendLine($"Name : {credential.Name}");
_ = outputList.AppendLine();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static bool RunChooseCredential(

using var oathSession = new OathSession(yubiKey);
{
IList<Credential> credentials = oathSession.GetCredentials();
var credentials = oathSession.GetCredentials();

// Are there any?
if (credentials.Count == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static bool RunGetCredentials(IYubiKeyDevice yubiKey, Func<KeyEntryData,
using var oathSession = new OathSession(yubiKey);
{
oathSession.KeyCollector = KeyCollectorDelegate;
IList<Credential> result = oathSession.GetCredentials();
var result = oathSession.GetCredentials();
ReportResult(result);
}

Expand All @@ -42,7 +42,7 @@ private static void ReportResult(IList<Credential> credentials)
{
_ = outputList.AppendLine($"Number of credentials: {credentials.Count}");
_ = outputList.AppendLine();
foreach (Credential currentCredential in credentials)
foreach (var currentCredential in credentials)
{
_ = outputList.AppendLine($"Issuer : {currentCredential.Issuer}");
_ = outputList.AppendLine($"Account : {currentCredential.AccountName}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static bool RunRenameCredential(
{
oathSession.KeyCollector = KeyCollectorDelegate;

Credential renamedCredential = oathSession.RenameCredential(
var renamedCredential = oathSession.RenameCredential(
credential.Issuer,
credential.AccountName,
newIssuer,
Expand Down Expand Up @@ -85,13 +85,13 @@ private static void RunCollectCredential(
SampleMenu.WriteMessage(MessageType.Title, 0, "Enter current account name");
_ = SampleMenu.ReadResponse(out string currentAccount);

_ = ChooseCredentialProperties.RunChooseTypeOption(menuObject, out CredentialType? type);
_ = ChooseCredentialProperties.RunChooseTypeOption(menuObject, out var type);

CredentialPeriod period = CredentialPeriod.Undefined;
var period = CredentialPeriod.Undefined;

if (type == CredentialType.Totp)
{
_ = ChooseCredentialProperties.RunChoosePeriodOption(menuObject, out CredentialPeriod? credentialPeriod);
_ = ChooseCredentialProperties.RunChoosePeriodOption(menuObject, out var credentialPeriod);
period = credentialPeriod.Value;
}

Expand Down
Loading

0 comments on commit a6e1b42

Please sign in to comment.