Skip to content

Commit 55ec1c8

Browse files
stephenhaunts_cpstephenhaunts_cp
authored andcommitted
Do a coding standards sweep with resharper.
1 parent 4126125 commit 55ec1c8

27 files changed

+290
-431
lines changed

Safe Pad Client Library/CryptoProviders/AES.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323

2424
namespace HauntedHouseSoftware.SecureNotePad.CryptoProviders
2525
{
26-
public class AES : IAES
26+
public class Aes : IAes
2727
{
2828
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
2929
public byte[] Encrypt(byte[] dataToEncrypt, string password, byte[] salt, int pbkdfRounds)
3030
{
3131
if (dataToEncrypt == null)
3232
{
33-
throw new ArgumentNullException("dataToEncrypt");
33+
throw new ArgumentNullException(nameof(dataToEncrypt));
3434
}
3535

3636
if (dataToEncrypt.Length == 0)
@@ -40,7 +40,7 @@ public byte[] Encrypt(byte[] dataToEncrypt, string password, byte[] salt, int pb
4040

4141
if (string.IsNullOrEmpty(password))
4242
{
43-
throw new ArgumentNullException("password");
43+
throw new ArgumentNullException(nameof(password));
4444
}
4545

4646
try
@@ -76,7 +76,7 @@ public byte[] Decrypt(byte[] dataToDecrypt, string password, byte[] salt, int pb
7676
{
7777
if (dataToDecrypt == null)
7878
{
79-
throw new ArgumentNullException("dataToDecrypt");
79+
throw new ArgumentNullException(nameof(dataToDecrypt));
8080
}
8181

8282
if (dataToDecrypt.Length == 0)
@@ -86,7 +86,7 @@ public byte[] Decrypt(byte[] dataToDecrypt, string password, byte[] salt, int pb
8686

8787
if (string.IsNullOrEmpty(password))
8888
{
89-
throw new ArgumentNullException("password");
89+
throw new ArgumentNullException(nameof(password));
9090
}
9191

9292
try

Safe Pad Client Library/CryptoProviders/IAES.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
namespace HauntedHouseSoftware.SecureNotePad.CryptoProviders
2121
{
22-
public interface IAES
22+
public interface IAes
2323
{
2424
byte[] Decrypt(byte[] dataToDecrypt, string password, byte[] salt, int pbkdfRounds);
2525
byte[] Encrypt(byte[] dataToEncrypt, string password, byte[] salt, int pbkdfRounds);

Safe Pad Client Library/CryptoProviders/SaltParseException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Runtime.Serialization;
43

4+
// ReSharper disable once CheckNamespace
55
namespace BCrypt.Net
66
{
77
/// <summary>Exception for signalling parse errors. </summary>

Safe Pad Client Library/CryptoProviders/SecureHash.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public byte[] ComputeHash(byte[] toBeHashed)
2828
{
2929
if (toBeHashed == null)
3030
{
31-
throw new ArgumentNullException("toBeHashed");
31+
throw new ArgumentNullException(nameof(toBeHashed));
3232
}
3333

3434
using (var mySha256 = SHA256.Create())

Safe Pad Client Library/DomainObjects/Application Settings/ApplicationSettings.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
* Authors: Stephen Haunts
1919
*/
2020

21-
using System;
2221
using System.Collections.ObjectModel;
2322
using System.Windows.Forms;
24-
using HauntedHouseSoftware.SecureNotePad.DomainObjects.Notebook;
2523

2624
namespace HauntedHouseSoftware.SecureNotePad.DomainObjects
2725
{
@@ -45,7 +43,7 @@ public ApplicationSettings()
4543
public byte ForegroundColorGreen { get; set; }
4644
public byte ForegroundColorBlue { get; set; }
4745

48-
public bool DetectURL { get; set; }
46+
public bool DetectUrl { get; set; }
4947

5048
public bool WordWrap { get; set; }
5149

Safe Pad Client Library/DomainObjects/Application Settings/SettingsWriter.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,9 @@
2424

2525
namespace HauntedHouseSoftware.SecureNotePad.DomainObjects
2626
{
27-
public sealed class SettingsWriter
27+
public static class SettingsWriter
2828
{
29-
private SettingsWriter()
30-
{
31-
}
32-
public static string AssemblyDirectory
33-
{
34-
get
35-
{
36-
return AppDomain.CurrentDomain.BaseDirectory;
37-
}
38-
}
29+
public static string AssemblyDirectory => AppDomain.CurrentDomain.BaseDirectory;
3930

4031
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
4132
public static void WriteSettingsFile(ApplicationSettings settings)
@@ -58,7 +49,7 @@ public static void WriteSettingsFile(ApplicationSettings settings)
5849
}
5950
catch
6051
{
61-
return;
52+
// ignored
6253
}
6354
}
6455

Safe Pad Client Library/DomainObjects/ByteHelpers.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,18 @@
2222

2323
namespace HauntedHouseSoftware.SecureNotePad.DomainObjects
2424
{
25-
public sealed class ByteHelpers
25+
public static class ByteHelpers
2626
{
27-
private ByteHelpers()
28-
{
29-
}
30-
3127
public static bool ByteArrayCompare(byte[] a1, byte[] a2)
3228
{
3329
if (a1 == null)
3430
{
35-
throw new ArgumentNullException("a1");
31+
throw new ArgumentNullException(nameof(a1));
3632
}
3733

3834
if (a2 == null)
3935
{
40-
throw new ArgumentNullException("a2");
36+
throw new ArgumentNullException(nameof(a2));
4137
}
4238

4339
IStructuralEquatable eqa1 = a1;
@@ -65,12 +61,12 @@ public static byte[] Combine(byte[] first, byte[] second)
6561
{
6662
if (first == null)
6763
{
68-
throw new ArgumentNullException("first");
64+
throw new ArgumentNullException(nameof(first));
6965
}
7066

7167
if (second == null)
7268
{
73-
throw new ArgumentNullException("second");
69+
throw new ArgumentNullException(nameof(second));
7470
}
7571

7672
var ret = new byte[first.Length + second.Length];

Safe Pad Client Library/DomainObjects/Document.cs

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@
2020
using System;
2121
using HauntedHouseSoftware.SecureNotePad.CryptoProviders;
2222
using HauntedHouseSoftware.SecureNotePad.DomainObjects.FileFormat;
23-
using System.Text;
2423
using System.Security.Cryptography;
24+
using Aes = HauntedHouseSoftware.SecureNotePad.CryptoProviders.Aes;
2525

2626
namespace HauntedHouseSoftware.SecureNotePad.DomainObjects
2727
{
2828
public class Document : IDocument
2929
{
30-
private readonly IAES _aes;
31-
private readonly ISecureHash _secureHash;
30+
private readonly IAes _aes;
3231
private IPassword _password;
33-
private readonly ICompression _compression;
3432
private readonly IFileProxy _fileProxy;
3533

3634
private const byte Major = 1;
@@ -45,14 +43,14 @@ public Document(IPassword password)
4543
throw new ArgumentNullException(nameof(password));
4644
}
4745

48-
_aes = new AES();
49-
_secureHash = new BCryptHash();
46+
_aes = new Aes();
47+
SecureHashProvider = new BCryptHash();
5048
_password = password;
5149
_fileProxy = new FileProxy();
52-
_compression = new GZipCompression();
50+
CompressionProvider = new GZipCompression();
5351
}
5452

55-
public Document(IAES aes, ISecureHash hash, ICompression compression, IPassword password, IFileProxy fileProxy)
53+
public Document(IAes aes, ISecureHash hash, ICompression compression, IPassword password, IFileProxy fileProxy)
5654
{
5755
if (aes == null)
5856
{
@@ -80,49 +78,25 @@ public Document(IAES aes, ISecureHash hash, ICompression compression, IPassword
8078
}
8179

8280
_aes = aes;
83-
_secureHash = hash;
84-
_compression = compression;
81+
SecureHashProvider = hash;
82+
CompressionProvider = compression;
8583
_password = password;
8684
_fileProxy = fileProxy;
8785
}
8886

89-
protected IAES AesProvider
90-
{
91-
get
92-
{
93-
return _aes;
94-
}
95-
}
87+
protected IAes AesProvider => _aes;
9688

97-
protected ISecureHash SecureHashProvider
98-
{
99-
get
100-
{
101-
return _secureHash;
102-
}
103-
}
89+
protected ISecureHash SecureHashProvider { get; }
10490

105-
protected ICompression CompressionProvider
106-
{
107-
get
108-
{
109-
return _compression;
110-
}
111-
}
91+
protected ICompression CompressionProvider { get; }
11292

113-
protected IPassword Password
114-
{
115-
get
116-
{
117-
return _password;
118-
}
119-
}
93+
protected IPassword Password => _password;
12094

12195
public void Load(string fileName)
12296
{
12397
if (string.IsNullOrEmpty(fileName))
12498
{
125-
throw new ArgumentNullException("fileName");
99+
throw new ArgumentNullException(nameof(fileName));
126100
}
127101

128102
LoadDocument(fileName, _password);
@@ -140,12 +114,12 @@ public void Load(string fileName, IPassword cachedPassword)
140114
{
141115
if (string.IsNullOrEmpty(fileName))
142116
{
143-
throw new ArgumentNullException("fileName");
117+
throw new ArgumentNullException(nameof(fileName));
144118
}
145119

146120
if (cachedPassword == null)
147121
{
148-
throw new ArgumentNullException("cachedPassword");
122+
throw new ArgumentNullException(nameof(cachedPassword));
149123
}
150124

151125
LoadDocument(fileName, cachedPassword);
@@ -157,7 +131,7 @@ public void Save(string fileName)
157131

158132
if (string.IsNullOrEmpty(fileName))
159133
{
160-
throw new ArgumentNullException("fileName");
134+
throw new ArgumentNullException(nameof(fileName));
161135
}
162136

163137
var salt = GenerateSalt(32);
@@ -180,7 +154,7 @@ private void SaveFormattedFile(string fileName, byte[] encrypted3, byte[] hash,
180154

181155
private byte[] EncryptData(byte[] salt)
182156
{
183-
var compressed = _compression.Compress(EncodedData);
157+
var compressed = CompressionProvider.Compress(EncodedData);
184158
var encrypted = _aes.Encrypt(compressed, Convert.ToBase64String(_password.CombinedPasswords), salt, 100000);
185159

186160
return encrypted;

Safe Pad Client Library/DomainObjects/FileFormat/FileLoaderBase.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-

2-
3-
using System;
4-
using HauntedHouseSoftware.SecureNotePad.CryptoProviders;
5-
6-
/**
1+
/**
72
* Safe Pad, a double encrypted note pad that uses 2 passwords to protect your documents and help you keep your privacy.
83
*
94
* Copyright (C) 2016 Stephen Haunts
@@ -22,33 +17,37 @@
2217
*
2318
* Authors: Stephen Haunts
2419
*/
20+
21+
using System;
22+
using HauntedHouseSoftware.SecureNotePad.CryptoProviders;
23+
2524
namespace HauntedHouseSoftware.SecureNotePad.DomainObjects.FileFormat
2625
{
2726
public class FileLoaderBase
2827
{
29-
protected IAES _aes;
30-
protected ISecureHash _secureHash;
31-
protected IPassword _password;
32-
protected ICompression _compression;
28+
protected IAes Aes;
29+
protected ISecureHash SecureHash;
30+
protected IPassword Password;
31+
protected ICompression Compression;
3332

3433
public FileLoaderBase(IPassword password)
3534
{
3635
if (password == null)
3736
{
38-
throw new ArgumentNullException("password");
37+
throw new ArgumentNullException(nameof(password));
3938
}
4039

41-
_aes = new AES();
42-
_secureHash = new SecureHash();
43-
_password = password;
44-
_compression = new GZipCompression();
40+
Aes = new Aes();
41+
SecureHash = new SecureHash();
42+
Password = password;
43+
Compression = new GZipCompression();
4544
}
4645

4746
public byte[] Load(byte[] byteStream, int workFactor)
4847
{
4948
if (byteStream == null)
5049
{
51-
throw new ArgumentNullException("byteStream");
50+
throw new ArgumentNullException(nameof(byteStream));
5251
}
5352

5453
var versionNumber = ByteHelpers.CreateSpecialByteArray(2);
@@ -64,7 +63,7 @@ public byte[] Load(byte[] byteStream, int workFactor)
6463

6564
private void CheckFileIntegrity(byte[] hash, byte[] encrypted)
6665
{
67-
var computedhash = _secureHash.ComputeHash(encrypted);
66+
var computedhash = SecureHash.ComputeHash(encrypted);
6867

6968
if (!ByteHelpers.ByteArrayCompare(computedhash, hash))
7069
{
@@ -75,9 +74,9 @@ private void CheckFileIntegrity(byte[] hash, byte[] encrypted)
7574
private byte[] DecryptData(byte[] encrypted, byte[] salt, int workFactor)
7675
{
7776

78-
var decrypted = _aes.Decrypt(encrypted, Convert.ToBase64String(_password.CombinedPasswords), salt, workFactor);
77+
var decrypted = Aes.Decrypt(encrypted, Convert.ToBase64String(Password.CombinedPasswords), salt, workFactor);
7978

80-
var decompressed = _compression.Decompress(decrypted);
79+
var decompressed = Compression.Decompress(decrypted);
8180

8281
return decompressed;
8382
}

Safe Pad Client Library/DomainObjects/FileFormat/GZipCompression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public byte[] Compress(byte[] input)
3131
{
3232
if (input == null)
3333
{
34-
throw new ArgumentNullException("input");
34+
throw new ArgumentNullException(nameof(input));
3535
}
3636

3737
byte[] output;
@@ -55,7 +55,7 @@ public byte[] Decompress(byte[] input)
5555
{
5656
if (input == null)
5757
{
58-
throw new ArgumentNullException("input");
58+
throw new ArgumentNullException(nameof(input));
5959
}
6060

6161
var output = new List<byte>();

0 commit comments

Comments
 (0)