Update var usage based on ReSharper "when apparent" rules

This commit is contained in:
Alex Barney 2019-12-28 15:16:21 -07:00
parent 496250f094
commit 5e4ea459cb
11 changed files with 21 additions and 21 deletions

View File

@ -301,7 +301,7 @@ namespace LibHacBuild
public void PrintResults()
{
Logger.Normal("SHA-1:");
using (SHA1 sha = SHA1.Create())
using (var sha = SHA1.Create())
{
foreach (string filename in Directory.EnumerateFiles(ArtifactsDirectory))
{

View File

@ -73,7 +73,7 @@ namespace LibHacBuild
public static string CalcPsmdcpName(string libDir)
{
using (SHA256 sha = SHA256.Create())
using (var sha = SHA256.Create())
{
foreach (string file in Directory.EnumerateFiles(libDir))
{
@ -104,7 +104,7 @@ namespace LibHacBuild
foreach (XElement rs in doc.Root.Elements(ns + "Relationship"))
{
using (SHA256 sha = SHA256.Create())
using (var sha = SHA256.Create())
{
if (rs.Attribute("Target").Value.Contains(".psmdcp"))
{

View File

@ -15,7 +15,7 @@ namespace LibHac.Crypto.Detail
Debug.Assert(key.Length == Aes.KeySize128);
Debug.Assert(iv.IsEmpty || iv.Length == Aes.BlockSize);
System.Security.Cryptography.Aes aes = System.Security.Cryptography.Aes.Create();
var aes = System.Security.Cryptography.Aes.Create();
if (aes == null) throw new CryptographicException("Unable to create AES object");
aes.Key = key.ToArray();

View File

@ -34,7 +34,7 @@ namespace LibHac.Crypto.Detail
ref Vector128<byte> outBlock = ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(output));
Vector128<byte> byteSwapMask = Vector128.Create((ulong)0x706050403020100, 0x8090A0B0C0D0E0F).AsByte();
Vector128<ulong> inc = Vector128.Create((ulong)0, 1);
var inc = Vector128.Create((ulong)0, 1);
Vector128<byte> iv = Iv;
Vector128<ulong> bSwappedIv = Ssse3.Shuffle(iv, byteSwapMask).AsUInt64();

View File

@ -12,7 +12,7 @@ namespace LibHac
public static void DecryptEcb(byte[] key, byte[] src, int srcIndex, byte[] dest, int destIndex, int length)
{
using (Aes aes = Aes.Create())
using (var aes = Aes.Create())
{
if (aes == null) throw new CryptographicException("Unable to create AES object");
aes.Key = key;
@ -27,7 +27,7 @@ namespace LibHac
public static void EncryptEcb(byte[] key, byte[] src, int srcIndex, byte[] dest, int destIndex, int length)
{
using (Aes aes = Aes.Create())
using (var aes = Aes.Create())
{
if (aes == null) throw new CryptographicException("Unable to create AES object");
aes.Key = key;
@ -42,7 +42,7 @@ namespace LibHac
public static void DecryptCbc(byte[] key, byte[] iv, byte[] src, int srcIndex, byte[] dest, int destIndex, int length)
{
using (Aes aes = Aes.Create())
using (var aes = Aes.Create())
{
if (aes == null) throw new CryptographicException("Unable to create AES object");
aes.Key = key;
@ -58,7 +58,7 @@ namespace LibHac
public static void EncryptCbc(byte[] key, byte[] iv, byte[] src, int srcIndex, byte[] dest, int destIndex, int length)
{
using (Aes aes = Aes.Create())
using (var aes = Aes.Create())
{
if (aes == null) throw new CryptographicException("Unable to create AES object");
aes.Key = key;
@ -140,7 +140,7 @@ namespace LibHac
public static Validity Rsa2048Pkcs1Verify(byte[] data, byte[] signature, byte[] modulus)
{
using (RSA rsa = RSA.Create())
using (var rsa = RSA.Create())
{
rsa.ImportParameters(new RSAParameters { Exponent = new byte[] { 1, 0, 1 }, Modulus = modulus });
@ -152,7 +152,7 @@ namespace LibHac
public static Validity Rsa2048PssVerify(byte[] data, byte[] signature, byte[] modulus)
{
using (RSA rsa = RSA.Create())
using (var rsa = RSA.Create())
{
rsa.ImportParameters(new RSAParameters { Exponent = new byte[] { 1, 0, 1 }, Modulus = modulus });
@ -164,7 +164,7 @@ namespace LibHac
public static byte[] DecryptTitleKey(byte[] titleKeyblock, RSAParameters rsaParams)
{
RSA rsa = RSA.Create();
var rsa = RSA.Create();
rsa.ImportParameters(rsaParams);
return rsa.Decrypt(titleKeyblock, RSAEncryptionPadding.OaepSHA256);
@ -172,7 +172,7 @@ namespace LibHac
private static RSAParameters RecoverRsaParameters(BigInteger n, BigInteger e, BigInteger d)
{
using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
using (var rng = RandomNumberGenerator.Create())
{
BigInteger k = d * e - 1;

View File

@ -24,7 +24,7 @@ namespace LibHac.FsSystem
if (counter.Length != BlockSizeBytes)
throw new ArgumentException($"{nameof(counter)} must be {BlockSizeBytes} bytes long");
Aes aes = Aes.Create();
var aes = Aes.Create();
if (aes == null) throw new CryptographicException("Unable to create AES object");
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.None;

View File

@ -49,7 +49,7 @@ namespace LibHac.FsSystem
if (key1?.Length != BlockSizeBytes || key2?.Length != BlockSizeBytes)
throw new ArgumentException($"Each key must be {BlockSizeBytes} bytes long");
Aes aes = Aes.Create();
var aes = Aes.Create();
if (aes == null) throw new CryptographicException("Unable to create AES object");
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.None;

View File

@ -19,7 +19,7 @@ namespace LibHac
private static object InitializeJaggedArray(Type type, int index, int[] lengths)
{
Array array = Array.CreateInstance(type, lengths[index]);
var array = Array.CreateInstance(type, lengths[index]);
Type elementType = type.GetElementType();
if (elementType == null) return array;

View File

@ -32,7 +32,7 @@ namespace hactoolnet
logger.SetTotal(iterations);
Stopwatch encryptWatch = Stopwatch.StartNew();
var encryptWatch = Stopwatch.StartNew();
for (int i = 0; i < iterations; i++)
{
src.CopyTo(dst);

View File

@ -87,7 +87,7 @@ namespace hactoolnet
byte[] ticketBytes = ticket.GetBytes();
builder.AddFile($"{ticket.RightsId.ToHexString()}.tik", new MemoryStream(ticketBytes).AsIFile(OpenMode.ReadWrite));
Assembly thisAssembly = Assembly.GetExecutingAssembly();
var thisAssembly = Assembly.GetExecutingAssembly();
Stream cert = thisAssembly.GetManifestResourceStream("hactoolnet.CA00000003_XS00000020");
builder.AddFile($"{ticket.RightsId.ToHexString()}.cert", cert.AsIFile(OpenMode.Read));

View File

@ -219,7 +219,7 @@ namespace LibHac.Tests
[MemberData(nameof(NormalizedPathTestItemsU8NoMountName))]
public static void NormalizePathU8NoMountName(string path, string expected, Result expectedResult)
{
U8String u8Path = path.ToU8String();
var u8Path = path.ToU8String();
Span<byte> buffer = stackalloc byte[0x301];
Result rc = PathTools.Normalize(buffer, out _, u8Path, false);
@ -237,7 +237,7 @@ namespace LibHac.Tests
[MemberData(nameof(NormalizedPathTestItemsU8MountName))]
public static void NormalizePathU8MountName(string path, string expected, Result expectedResult)
{
U8String u8Path = path.ToU8String();
var u8Path = path.ToU8String();
Span<byte> buffer = stackalloc byte[0x301];
Result rc = PathTools.Normalize(buffer, out _, u8Path, true);
@ -263,7 +263,7 @@ namespace LibHac.Tests
[MemberData(nameof(NormalizedPathTestItemsU8TooShort))]
public static void NormalizePathU8TooShortDest(string path, string expected, int destSize)
{
U8String u8Path = path.ToU8String();
var u8Path = path.ToU8String();
Span<byte> buffer = stackalloc byte[destSize];