From 681174f15888224e48df51651b100f9363ed4b14 Mon Sep 17 00:00:00 2001 From: Raphael Beck Date: Tue, 2 Jul 2019 03:54:43 +0200 Subject: [PATCH] cleanup --- .../Extensions/RSAParametersExtensions.cs | 4 ++-- .../Extensions/StringExtensions.cs | 8 ++++---- .../Services/Convos/ConvoService.cs | 20 +++++++++---------- .../Services/Coupons/CouponService.cs | 2 +- .../Asymmetric/AsymmetricCryptographyRSA.cs | 8 ++++---- .../Messages/MessageCryptography.cs | 2 +- .../Symmetric/SymmetricCryptography.cs | 2 +- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/GlitchedEpistle.Client/Extensions/RSAParametersExtensions.cs b/GlitchedEpistle.Client/Extensions/RSAParametersExtensions.cs index 18feb03..d0acd58 100644 --- a/GlitchedEpistle.Client/Extensions/RSAParametersExtensions.cs +++ b/GlitchedEpistle.Client/Extensions/RSAParametersExtensions.cs @@ -20,9 +20,9 @@ public static class RSAParametersExtensions /// Invalid XML RSA key. public static RSAParameters FromXmlString(string xml) { - RSAParameters rsaParameters = new RSAParameters(); + var rsaParameters = new RSAParameters(); - XmlDocument xmlDoc = new XmlDocument(); + var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); if (xmlDoc.DocumentElement != null && xmlDoc.DocumentElement.Name == "RSAKeyValue") diff --git a/GlitchedEpistle.Client/Extensions/StringExtensions.cs b/GlitchedEpistle.Client/Extensions/StringExtensions.cs index 8d1445d..22957bb 100644 --- a/GlitchedEpistle.Client/Extensions/StringExtensions.cs +++ b/GlitchedEpistle.Client/Extensions/StringExtensions.cs @@ -38,9 +38,9 @@ public static bool NullOrEmpty(this string str) /// MD5 hash of the input string. public static string MD5(this string text, bool toLowercase = false) { - using (MD5 md5 = System.Security.Cryptography.MD5.Create()) + using (var md5 = System.Security.Cryptography.MD5.Create()) { - StringBuilder stringBuilder = new StringBuilder(32); + var stringBuilder = new StringBuilder(32); byte[] hash = md5.ComputeHash(text.EncodeToBytes()); for (int i = 0; i < hash.Length; i++) @@ -60,9 +60,9 @@ public static string MD5(this string text, bool toLowercase = false) /// SHA512 of the input string. public static string SHA512(this string text, bool toLowercase = false) { - using (SHA512 sha512 = System.Security.Cryptography.SHA512.Create()) + using (var sha512 = System.Security.Cryptography.SHA512.Create()) { - StringBuilder stringBuilder = new StringBuilder(128); + var stringBuilder = new StringBuilder(128); byte[] hash = sha512.ComputeHash(text.EncodeToBytes()); for (int i = 0; i < hash.Length; i++) diff --git a/GlitchedEpistle.Client/Services/Convos/ConvoService.cs b/GlitchedEpistle.Client/Services/Convos/ConvoService.cs index 48d06a6..b71ecf1 100644 --- a/GlitchedEpistle.Client/Services/Convos/ConvoService.cs +++ b/GlitchedEpistle.Client/Services/Convos/ConvoService.cs @@ -31,7 +31,7 @@ public class ConvoService : IConvoService /// null if creation failed; the created 's unique id. public async Task CreateConvo(ConvoCreationDto convoDto, string userId, string auth) { - RestRequest request = new RestRequest( + var request = new RestRequest( method: Method.POST, resource: new Uri("convos/create", UriKind.Relative) ); @@ -54,7 +54,7 @@ public async Task CreateConvo(ConvoCreationDto convoDto, string userId, /// Whether deletion was successful or not. public async Task DeleteConvo(string convoId, string totp, string userId, string auth) { - RestRequest request = new RestRequest( + var request = new RestRequest( method: Method.DELETE, resource: new Uri($"convos/{convoId}", UriKind.Relative) ); @@ -75,7 +75,7 @@ public async Task DeleteConvo(string convoId, string totp, string userId, /// Whether the message was posted successfully or not. public async Task PostMessage(string convoId, PostMessageParamsDto messageDto) { - RestRequest request = new RestRequest( + var request = new RestRequest( method: Method.POST, resource: new Uri($"convos/{convoId}", UriKind.Relative) ); @@ -96,7 +96,7 @@ public async Task PostMessage(string convoId, PostMessageParamsDto message /// The convo's metadata wrapped into a DTO (null if something failed). public async Task GetConvoMetadata(string convoId, string convoPasswordSHA512, string userId, string auth) { - RestRequest request = new RestRequest( + var request = new RestRequest( method: Method.GET, resource: new Uri($"convos/meta/{convoId}", UriKind.Relative) ); @@ -122,7 +122,7 @@ public async Task GetConvoMetadata(string convoId, string conv /// Whether the convo's metadata was changed successfully or not. public async Task ChangeConvoMetadata(string convoId, string convoPasswordSHA512, string userId, string auth, ConvoChangeMetadataDto metadata) { - RestRequest request = new RestRequest( + var request = new RestRequest( method: Method.PUT, resource: new Uri($"convos/meta/{convoId}", UriKind.Relative) ); @@ -147,7 +147,7 @@ public async Task ChangeConvoMetadata(string convoId, string convoPassword /// The retrieved s (null if everything is up to date or if something failed). public async Task GetConvoMessages(string convoId, string convoPasswordSHA512, string userId, string auth, string tailId = null) { - RestRequest request = new RestRequest( + var request = new RestRequest( method: Method.GET, resource: new Uri($"convos/{convoId}/{tailId}", UriKind.Relative) ); @@ -171,7 +171,7 @@ public async Task GetConvoMessages(string convoId, string convoPasswo /// The 's index integer; if something fails, -1 is returned. public async Task IndexOf(string convoId, string convoPasswordSHA512, string userId, string auth, string messageId) { - RestRequest request = new RestRequest( + var request = new RestRequest( method: Method.GET, resource: new Uri($"convos/indexof/{convoId}", UriKind.Relative) ); @@ -195,7 +195,7 @@ public async Task IndexOf(string convoId, string convoPasswordSHA512, strin /// Whether the was joined successfully or not. public async Task JoinConvo(string convoId, string convoPasswordSHA512, string userId, string auth) { - RestRequest request = new RestRequest( + var request = new RestRequest( method: Method.PUT, resource: new Uri($"convos/join/{convoId}", UriKind.Relative) ); @@ -218,7 +218,7 @@ public async Task JoinConvo(string convoId, string convoPasswordSHA512, st /// Whether the was left successfully or not. public async Task LeaveConvo(string convoId, string totp, string userId, string auth) { - RestRequest request = new RestRequest( + var request = new RestRequest( method: Method.PUT, resource: new Uri($"convos/leave/{convoId}", UriKind.Relative) ); @@ -243,7 +243,7 @@ public async Task LeaveConvo(string convoId, string totp, string userId, s /// Whether the user was kicked out successfully or not. public async Task KickUser(string convoId, string convoPasswordSHA512, string convoAdminId, string auth, string userIdToKick, bool permaBan) { - RestRequest request = new RestRequest( + var request = new RestRequest( method: Method.PUT, resource: new Uri($"convos/{convoId}/kick/{userIdToKick}", UriKind.Relative) ); diff --git a/GlitchedEpistle.Client/Services/Coupons/CouponService.cs b/GlitchedEpistle.Client/Services/Coupons/CouponService.cs index c3fe16f..f506e03 100644 --- a/GlitchedEpistle.Client/Services/Coupons/CouponService.cs +++ b/GlitchedEpistle.Client/Services/Coupons/CouponService.cs @@ -26,7 +26,7 @@ public class CouponService : ICouponService /// Whether the coupon code was redeemed successfully or not. public async Task UseCoupon(string code, string userId, string auth) { - RestRequest request = new RestRequest( + var request = new RestRequest( method: Method.PUT, resource: new Uri($"coupons/{code}", UriKind.Relative) ); diff --git a/GlitchedEpistle.Client/Services/Cryptography/Asymmetric/AsymmetricCryptographyRSA.cs b/GlitchedEpistle.Client/Services/Cryptography/Asymmetric/AsymmetricCryptographyRSA.cs index 377e1f3..66f9c21 100644 --- a/GlitchedEpistle.Client/Services/Cryptography/Asymmetric/AsymmetricCryptographyRSA.cs +++ b/GlitchedEpistle.Client/Services/Cryptography/Asymmetric/AsymmetricCryptographyRSA.cs @@ -26,7 +26,7 @@ public string Encrypt(string text, RSAParameters publicKey) } byte[] encryptedData; - using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) + using (var rsa = new RSACryptoServiceProvider()) { rsa.ImportParameters(publicKey); encryptedData = rsa.Encrypt(Encoding.UTF8.GetBytes(text), true); @@ -49,7 +49,7 @@ public string Decrypt(string encryptedText, RSAParameters privateKey) } byte[] data; - using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) + using (var rsa = new RSACryptoServiceProvider()) { rsa.ImportParameters(privateKey); if (rsa.PublicOnly) @@ -70,7 +70,7 @@ public string Decrypt(string encryptedText, RSAParameters privateKey) public byte[] Encrypt(byte[] data, RSAParameters publicKey) { byte[] encryptedData; - using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) + using (var rsa = new RSACryptoServiceProvider()) { rsa.ImportParameters(publicKey); encryptedData = rsa.Encrypt(data, true); @@ -88,7 +88,7 @@ public byte[] Encrypt(byte[] data, RSAParameters publicKey) public byte[] Decrypt(byte[] encryptedData, RSAParameters privateKey) { byte[] data; - using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) + using (var rsa = new RSACryptoServiceProvider()) { rsa.ImportParameters(privateKey); if (rsa.PublicOnly) diff --git a/GlitchedEpistle.Client/Services/Cryptography/Messages/MessageCryptography.cs b/GlitchedEpistle.Client/Services/Cryptography/Messages/MessageCryptography.cs index 5ab9560..6444294 100644 --- a/GlitchedEpistle.Client/Services/Cryptography/Messages/MessageCryptography.cs +++ b/GlitchedEpistle.Client/Services/Cryptography/Messages/MessageCryptography.cs @@ -57,7 +57,7 @@ public string EncryptMessage(string messageJson, RSAParameters recipientPublicRs try { byte[] data = gzip.Compress(Encoding.UTF8.GetBytes(messageJson), COMPRESSION_SETTINGS); - using (EncryptionResult encryptionResult = aes.Encrypt(data)) + using (var encryptionResult = aes.Encrypt(data)) { var stringBuilder = new StringBuilder(encryptionResult.EncryptedData.Length); stringBuilder.Append(Convert.ToBase64String(rsa.Encrypt(encryptionResult.Key, recipientPublicRsaKey))); diff --git a/GlitchedEpistle.Client/Services/Cryptography/Symmetric/SymmetricCryptography.cs b/GlitchedEpistle.Client/Services/Cryptography/Symmetric/SymmetricCryptography.cs index 6ee4c6e..261421c 100644 --- a/GlitchedEpistle.Client/Services/Cryptography/Symmetric/SymmetricCryptography.cs +++ b/GlitchedEpistle.Client/Services/Cryptography/Symmetric/SymmetricCryptography.cs @@ -90,7 +90,7 @@ public byte[] EncryptWithPassword(byte[] data, string password) { rng.GetBytes(salt); - using (Rfc2898DeriveBytes rfc = new Rfc2898DeriveBytes(password, salt, RFC_ITERATIONS)) + using (var rfc = new Rfc2898DeriveBytes(password, salt, RFC_ITERATIONS)) { aes.IV = rfc.GetBytes(16); aes.Key = rfc.GetBytes(32);