Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
GlitchedPolygons committed Jul 2, 2019
1 parent 562bb81 commit 681174f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions GlitchedEpistle.Client/Extensions/RSAParametersExtensions.cs
Expand Up @@ -20,9 +20,9 @@ public static class RSAParametersExtensions
/// <exception cref="InvalidDataException">Invalid XML RSA key.</exception>
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")
Expand Down
8 changes: 4 additions & 4 deletions GlitchedEpistle.Client/Extensions/StringExtensions.cs
Expand Up @@ -38,9 +38,9 @@ public static bool NullOrEmpty(this string str)
/// <returns>MD5 hash of the input string.</returns>
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++)
Expand All @@ -60,9 +60,9 @@ public static string MD5(this string text, bool toLowercase = false)
/// <returns>SHA512 of the input string.</returns>
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++)
Expand Down
20 changes: 10 additions & 10 deletions GlitchedEpistle.Client/Services/Convos/ConvoService.cs
Expand Up @@ -31,7 +31,7 @@ public class ConvoService : IConvoService
/// <returns><c>null</c> if creation failed; the created <see cref="Convo" />'s unique id.</returns>
public async Task<string> 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)
);
Expand All @@ -54,7 +54,7 @@ public async Task<string> CreateConvo(ConvoCreationDto convoDto, string userId,
/// <returns>Whether deletion was successful or not.</returns>
public async Task<bool> 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)
);
Expand All @@ -75,7 +75,7 @@ public async Task<bool> DeleteConvo(string convoId, string totp, string userId,
/// <returns>Whether the message was posted successfully or not.</returns>
public async Task<bool> PostMessage(string convoId, PostMessageParamsDto messageDto)
{
RestRequest request = new RestRequest(
var request = new RestRequest(
method: Method.POST,
resource: new Uri($"convos/{convoId}", UriKind.Relative)
);
Expand All @@ -96,7 +96,7 @@ public async Task<bool> PostMessage(string convoId, PostMessageParamsDto message
/// <returns>The convo's metadata wrapped into a DTO (<c>null</c> if something failed).</returns>
public async Task<ConvoMetadataDto> 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)
);
Expand All @@ -122,7 +122,7 @@ public async Task<ConvoMetadataDto> GetConvoMetadata(string convoId, string conv
/// <returns>Whether the convo's metadata was changed successfully or not.</returns>
public async Task<bool> 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)
);
Expand All @@ -147,7 +147,7 @@ public async Task<bool> ChangeConvoMetadata(string convoId, string convoPassword
/// <returns>The retrieved <see cref="Message" />s (<c>null</c> if everything is up to date or if something failed).</returns>
public async Task<Message[]> 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)
);
Expand All @@ -171,7 +171,7 @@ public async Task<Message[]> GetConvoMessages(string convoId, string convoPasswo
/// <returns>The <see cref="Message" />'s index integer; if something fails, <c>-1</c> is returned.</returns>
public async Task<int> 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)
);
Expand All @@ -195,7 +195,7 @@ public async Task<int> IndexOf(string convoId, string convoPasswordSHA512, strin
/// <returns>Whether the <see cref="Convo" /> was joined successfully or not.</returns>
public async Task<bool> 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)
);
Expand All @@ -218,7 +218,7 @@ public async Task<bool> JoinConvo(string convoId, string convoPasswordSHA512, st
/// <returns>Whether the <see cref="Convo" /> was left successfully or not.</returns>
public async Task<bool> 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)
);
Expand All @@ -243,7 +243,7 @@ public async Task<bool> LeaveConvo(string convoId, string totp, string userId, s
/// <returns>Whether the user was kicked out successfully or not.</returns>
public async Task<bool> 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)
);
Expand Down
2 changes: 1 addition & 1 deletion GlitchedEpistle.Client/Services/Coupons/CouponService.cs
Expand Up @@ -26,7 +26,7 @@ public class CouponService : ICouponService
/// <returns>Whether the coupon code was redeemed successfully or not.</returns>
public async Task<bool> 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)
);
Expand Down
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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)
Expand Down
Expand Up @@ -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)));
Expand Down
Expand Up @@ -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);
Expand Down

0 comments on commit 681174f

Please sign in to comment.