Skip to content

Commit 45e69fa

Browse files
author
Cory Thompson
committed
Code cleanup
1 parent 902d6f3 commit 45e69fa

13 files changed

+57
-90
lines changed

WebPush.Test/ECKeyHelperTest.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Org.BouncyCastle.Crypto;
1+
using Org.BouncyCastle.Crypto;
72
using Org.BouncyCastle.Crypto.Parameters;
3+
using System.Linq;
84
using WebPush.Util;
95
using Xunit;
106

@@ -44,16 +40,17 @@ public void TestGenerateKeys()
4440
{
4541
AsymmetricCipherKeyPair keys = ECKeyHelper.GenerateKeys();
4642

47-
byte[] publicKey = ((ECPublicKeyParameters) keys.Public).Q.GetEncoded(false);
48-
byte[] privateKey = ((ECPrivateKeyParameters) keys.Private).D.ToByteArrayUnsigned();
43+
byte[] publicKey = ((ECPublicKeyParameters)keys.Public).Q.GetEncoded(false);
44+
byte[] privateKey = ((ECPrivateKeyParameters)keys.Private).D.ToByteArrayUnsigned();
4945

5046
int publicKeyLength = publicKey.Length;
5147
int privateKeyLength = privateKey.Length;
5248

5349
Assert.Equal(65, publicKeyLength);
5450
Assert.Equal(32, privateKeyLength);
5551

56-
; }
52+
;
53+
}
5754

5855
[Fact]
5956
public void TestGenerateKeysNoCache()
@@ -66,7 +63,7 @@ public void TestGenerateKeysNoCache()
6663

6764
byte[] publicKey2 = ((ECPublicKeyParameters)keys2.Public).Q.GetEncoded(false);
6865
byte[] privateKey2 = ((ECPrivateKeyParameters)keys2.Private).D.ToByteArrayUnsigned();
69-
66+
7067
Assert.False(publicKey1.SequenceEqual(publicKey2));
7168
Assert.False(privateKey1.SequenceEqual(privateKey2));
7269
}

WebPush.Test/JWSSignerTest.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
using System;
1+
using Org.BouncyCastle.Crypto.Parameters;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.Text;
5-
using System.Threading.Tasks;
6-
using Org.BouncyCastle.Crypto.Parameters;
74
using WebPush.Util;
85
using Xunit;
96

@@ -45,7 +42,6 @@ public void TestGenerateSignature()
4542
byte[] decodedSignature = UrlBase64.Decode(signature);
4643
int decodedSignatureLength = decodedSignature.Length;
4744

48-
4945
bool isSignatureLengthValid = decodedSignatureLength == 66 || decodedSignatureLength == 64;
5046
Assert.Equal(true, isSignatureLengthValid);
5147
}

WebPush.Test/UrlBase64Test.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Linq;
1+
using System.Linq;
32
using WebPush.Util;
43
using Xunit;
54

@@ -10,7 +9,7 @@ public class UrlBase64Test
109
[Fact]
1110
public void TestBase64UrlDecode()
1211
{
13-
byte[] expected = new byte[3] {181, 235, 45};
12+
byte[] expected = new byte[3] { 181, 235, 45 };
1413
byte[] actual = UrlBase64.Decode(@"test");
1514
Assert.True(actual.SequenceEqual(expected));
1615
}
@@ -19,9 +18,8 @@ public void TestBase64UrlDecode()
1918
public void TestBase64UrlEncode()
2019
{
2120
string expected = @"test";
22-
string actual = UrlBase64.Encode(new byte[3] {181, 235, 45});
21+
string actual = UrlBase64.Encode(new byte[3] { 181, 235, 45 });
2322
Assert.Equal(expected, actual);
2423
}
25-
2624
}
2725
}

WebPush.Test/VapidHelperTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class VapidHelperTest
1010
private const string VALID_AUDIENCE = "http://example.com";
1111
private const string VALID_SUBJECT = "http://example.com/example";
1212
private const string VALID_SUBJECT_MAILTO = "mailto:example@example.com";
13-
13+
1414
[Fact]
1515
public void TestGenerateVapidKeys()
1616
{
@@ -38,7 +38,7 @@ public void TestGetVapidHeaders()
3838
string publicKey = UrlBase64.Encode(new byte[65]);
3939
string privatekey = UrlBase64.Encode(new byte[32]);
4040
Dictionary<string, string> headers = VapidHelper.GetVapidHeaders(VALID_AUDIENCE, VALID_SUBJECT, publicKey, privatekey);
41-
41+
4242
Assert.True(headers.ContainsKey("Authorization"));
4343
Assert.True(headers.ContainsKey("Crypto-Key"));
4444
}

WebPush.Test/WebPushClientTest.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Net.Http;
5-
using WebPush;
65
using Xunit;
76

87
namespace WebPush.Test
@@ -19,7 +18,6 @@ public class WebPushClientTest
1918
private const string TEST_FCM_ENDPOINT =
2019
@"https://fcm.googleapis.com/fcm/send/efz_TLX_rLU:APA91bE6U0iybLYvv0F3mf6";
2120

22-
2321
[Fact]
2422
public void TestSetGCMAPIKey()
2523
{
@@ -103,7 +101,7 @@ public void TestSetGCMAPiKeyNonGCMPushService()
103101
public void TestSetVapidDetails()
104102
{
105103
WebPushClient client = new WebPushClient();
106-
104+
107105
client.SetVapidDetails("mailto:example@example.com", TEST_PUBLIC_KEY, TEST_PRIVATE_KEY);
108106

109107
PushSubscription subscription = new PushSubscription(TEST_FCM_ENDPOINT, TEST_PUBLIC_KEY, TEST_PRIVATE_KEY);

WebPush/Model/PushSubscription.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
7-
namespace WebPush
1+
namespace WebPush
82
{
93
public class PushSubscription
104
{
@@ -14,7 +8,6 @@ public class PushSubscription
148

159
public PushSubscription()
1610
{
17-
1811
}
1912

2013
public PushSubscription(string endpoint, string p256dh, string auth)

WebPush/Model/VapidDetails.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ public class VapidDetails
88

99
public VapidDetails()
1010
{
11-
1211
}
1312

1413
/// <param name="subject">This should be a URL or a 'mailto:' email address</param>

WebPush/Util/ECKeyHelper.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
using System;
2-
using System.IO;
3-
using Org.BouncyCastle.Asn1;
1+
using Org.BouncyCastle.Asn1;
42
using Org.BouncyCastle.Asn1.Nist;
53
using Org.BouncyCastle.Asn1.X9;
64
using Org.BouncyCastle.Crypto;
7-
using Org.BouncyCastle.Crypto.Generators;
85
using Org.BouncyCastle.Crypto.Parameters;
96
using Org.BouncyCastle.OpenSsl;
107
using Org.BouncyCastle.Security;
8+
using System;
9+
using System.IO;
1110

1211
namespace WebPush.Util
1312
{

WebPush/Util/Encryptor.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Security.Cryptography;
6-
using System.Text;
7-
using Org.BouncyCastle.Crypto;
1+
using Org.BouncyCastle.Crypto;
82
using Org.BouncyCastle.Crypto.Engines;
93
using Org.BouncyCastle.Crypto.Modes;
104
using Org.BouncyCastle.Crypto.Parameters;
115
using Org.BouncyCastle.Security;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Security.Cryptography;
10+
using System.Text;
1211

1312
// @LogicSoftware
1413
// Originally from https://github.com/LogicSoftware/WebPushEncryption/blob/master/src/Encryptor.cs

WebPush/Util/JWSSigner.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
using System;
1+
using Org.BouncyCastle.Crypto.Parameters;
2+
using Org.BouncyCastle.Crypto.Signers;
3+
using Org.BouncyCastle.Math;
4+
using System;
25
using System.Collections.Generic;
36
using System.Linq;
47
using System.Security.Cryptography;
58
using System.Text;
6-
using Org.BouncyCastle.Crypto.Parameters;
7-
using Org.BouncyCastle.Crypto.Signers;
8-
using Org.BouncyCastle.Math;
9-
using Org.BouncyCastle.Security;
109

1110
namespace WebPush.Util
1211
{
@@ -27,7 +26,6 @@ public JWSSigner(ECPrivateKeyParameters privateKey)
2726
/// <returns></returns>
2827
public string GenerateSignature(Dictionary<string, object> header, Dictionary<string, object> payload)
2928
{
30-
3129
string securedInput = SecureInput(header, payload);
3230
byte[] message = Encoding.UTF8.GetBytes(securedInput);
3331

WebPush/Util/UrlBase64.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public static class UrlBase64
1111
/// <returns></returns>
1212
public static byte[] Decode(string base64)
1313
{
14-
1514
base64 = base64.Replace('-', '+').Replace('_', '/');
1615

1716
while (base64.Length % 4 != 0)
@@ -21,7 +20,7 @@ public static byte[] Decode(string base64)
2120
}
2221

2322
/// <summary>
24-
/// Encodes bytes into url-safe base64 string
23+
/// Encodes bytes into url-safe base64 string
2524
/// </summary>
2625
/// <param name="data"></param>
2726
/// <returns></returns>

WebPush/VapidHelper.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Security.Cryptography;
5-
using System.Text;
6-
using System.Threading.Tasks;
7-
using Org.BouncyCastle.Crypto;
1+
using Org.BouncyCastle.Crypto;
82
using Org.BouncyCastle.Crypto.Parameters;
3+
using System;
4+
using System.Collections.Generic;
95
using WebPush.Util;
106

117
namespace WebPush
@@ -32,7 +28,7 @@ public static VapidDetails GenerateVapidKeys()
3228

3329
/// <summary>
3430
/// This method takes the required VAPID parameters and returns the required
35-
/// header to be added to a Web Push Protocol Request.
31+
/// header to be added to a Web Push Protocol Request.
3632
/// </summary>
3733
/// <param name="audience">This must be the origin of the push service.</param>
3834
/// <param name="subject">This should be a URL or a 'mailto:' email address</param>
@@ -91,7 +87,6 @@ public static void ValidateAudience(string audience)
9187
{
9288
throw new ArgumentException(@"VAPID audience is not a url.");
9389
}
94-
9590
}
9691

9792
public static void ValidateSubject(string subject)
@@ -130,7 +125,6 @@ public static void ValidatePublicKey(string publicKey)
130125
}
131126
}
132127

133-
134128
public static void ValidatePrivateKey(string privateKey)
135129
{
136130
if (String.IsNullOrEmpty(privateKey))
@@ -140,7 +134,6 @@ public static void ValidatePrivateKey(string privateKey)
140134

141135
byte[] decodedPrivateKey = UrlBase64.Decode(privateKey);
142136

143-
144137
if (decodedPrivateKey.Length != 32)
145138
{
146139
throw new ArgumentException(@"Vapid private key should be 32 bytes long when decoded.");

0 commit comments

Comments
 (0)