From 9e361d7ebf2562f7788f58170ae2031ba3c1a42f Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 6 Jul 2017 10:17:06 +1000 Subject: [PATCH] add .ConfigureAwait(false) (#11) --- docs/keyvault.md | 2 +- docs/messageid.md | 2 +- .../KeyVaultPlugin.cs | 16 ++++++++-------- .../KeyVaultSecretManager.cs | 8 ++++---- .../EncryptionTests.cs | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/keyvault.md b/docs/keyvault.md index c3e1cdf..b9d2e78 100644 --- a/docs/keyvault.md +++ b/docs/keyvault.md @@ -27,5 +27,5 @@ queueClient.RegisterPlugin(keyVaultPlugin); var message = new Message(Encoding.UTF8.GetBytes("Super secret message")); -await queueClient.SendAsync(message); +await queueClient.SendAsync(message).ConfigureAwait(false); ``` \ No newline at end of file diff --git a/docs/messageid.md b/docs/messageid.md index f36d64f..2e843f7 100644 --- a/docs/messageid.md +++ b/docs/messageid.md @@ -21,7 +21,7 @@ queueClient.RegisterPlugin(messageIdPlugin); var message = new Message(Encoding.UTF8.GetBytes("Message with GUID message ID")); -await queueClient.SendAsync(message); +await queueClient.SendAsync(message).ConfigureAwait(false); // message.MessageId will be assigned a GUID in a 32 digit format w/o hyphens or braces ``` diff --git a/src/Microsoft.Azure.ServiceBus.KeyVault/KeyVaultPlugin.cs b/src/Microsoft.Azure.ServiceBus.KeyVault/KeyVaultPlugin.cs index 85c7f32..10d9912 100644 --- a/src/Microsoft.Azure.ServiceBus.KeyVault/KeyVaultPlugin.cs +++ b/src/Microsoft.Azure.ServiceBus.KeyVault/KeyVaultPlugin.cs @@ -84,13 +84,13 @@ namespace Microsoft.Azure.ServiceBus.KeyVault return message; } - var secret = await secretManager.GetHashedSecret(secretName, secretVersion); + var secret = await secretManager.GetHashedSecret(secretName, secretVersion).ConfigureAwait(false); message.UserProperties.Add(KeyVaultMessageHeaders.InitializationVectorPropertyName, base64InitializationVector); message.UserProperties.Add(KeyVaultMessageHeaders.KeyNamePropertyName, secretName); message.UserProperties.Add(KeyVaultMessageHeaders.KeyVersionPropertyName, secretVersion); - message.Body = await KeyVaultPlugin.Encrypt(message.Body, secret, this.initializationVector); + message.Body = await KeyVaultPlugin.Encrypt(message.Body, secret, this.initializationVector).ConfigureAwait(false); return message; } catch (Exception ex) @@ -128,11 +128,11 @@ namespace Microsoft.Azure.ServiceBus.KeyVault { secretVersion = message.UserProperties[KeyVaultMessageHeaders.KeyVersionPropertyName] as string; message.UserProperties.Remove(KeyVaultMessageHeaders.KeyVersionPropertyName); - } + } - var secret = await secretManager.GetHashedSecret(secretName, secretVersion); + var secret = await secretManager.GetHashedSecret(secretName, secretVersion).ConfigureAwait(false); - var decryptedMessage = await KeyVaultPlugin.Decrypt(message.Body, secret, iV); + var decryptedMessage = await KeyVaultPlugin.Decrypt(message.Body, secret, iV).ConfigureAwait(false); message.Body = decryptedMessage; return message; @@ -166,7 +166,7 @@ namespace Microsoft.Azure.ServiceBus.KeyVault var encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); - return await PerformCryptography(encryptor, payload); + return await PerformCryptography(encryptor, payload).ConfigureAwait(false); } } @@ -182,7 +182,7 @@ namespace Microsoft.Azure.ServiceBus.KeyVault var decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); - return await PerformCryptography(decryptor, payload); + return await PerformCryptography(decryptor, payload).ConfigureAwait(false); } } @@ -193,7 +193,7 @@ namespace Microsoft.Azure.ServiceBus.KeyVault using (var cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write)) { // Write all data to the memory stream. - await cryptoStream.WriteAsync(data, 0, data.Length); + await cryptoStream.WriteAsync(data, 0, data.Length).ConfigureAwait(false); cryptoStream.FlushFinalBlock(); return memoryStream.ToArray(); } diff --git a/src/Microsoft.Azure.ServiceBus.KeyVault/KeyVaultSecretManager.cs b/src/Microsoft.Azure.ServiceBus.KeyVault/KeyVaultSecretManager.cs index 282ea8a..7fe19e6 100644 --- a/src/Microsoft.Azure.ServiceBus.KeyVault/KeyVaultSecretManager.cs +++ b/src/Microsoft.Azure.ServiceBus.KeyVault/KeyVaultSecretManager.cs @@ -51,7 +51,7 @@ namespace Microsoft.Azure.ServiceBus.KeyVault return secretCache[combinedNameAndVersion]; } - var secret = await GetSecretFromKeyVault(secretName, secretVersion); + var secret = await GetSecretFromKeyVault(secretName, secretVersion).ConfigureAwait(false); using (var sha256 = SHA256.Create()) { var secretAsBytes = Encoding.UTF8.GetBytes(secret); @@ -79,11 +79,11 @@ namespace Microsoft.Azure.ServiceBus.KeyVault SecretBundle secretResult; if (string.IsNullOrWhiteSpace(secretVersion)) { - secretResult = await keyVaultClient.GetSecretAsync(this.KeyVaultUrl, secretName); + secretResult = await keyVaultClient.GetSecretAsync(this.KeyVaultUrl, secretName).ConfigureAwait(false); } else { - secretResult = await keyVaultClient.GetSecretAsync(this.KeyVaultUrl, secretName, secretVersion); + secretResult = await keyVaultClient.GetSecretAsync(this.KeyVaultUrl, secretName, secretVersion).ConfigureAwait(false); } return secretResult.Value; } @@ -101,7 +101,7 @@ namespace Microsoft.Azure.ServiceBus.KeyVault try { - var result = await ctx.AcquireTokenAsync(resource, credential); + var result = await ctx.AcquireTokenAsync(resource, credential).ConfigureAwait(false); return result.AccessToken; } catch (Exception ex) diff --git a/test/Microsoft.Azure.ServiceBus.KeyVault.Test/EncryptionTests.cs b/test/Microsoft.Azure.ServiceBus.KeyVault.Test/EncryptionTests.cs index ae48cfb..353d7c8 100644 --- a/test/Microsoft.Azure.ServiceBus.KeyVault.Test/EncryptionTests.cs +++ b/test/Microsoft.Azure.ServiceBus.KeyVault.Test/EncryptionTests.cs @@ -23,7 +23,7 @@ namespace Microsoft.Azure.ServiceBus.KeyVault.Test using (var sha256 = SHA256.Create()) { hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(password)); - } + } var iV = KeyVaultPlugin.GenerateInitializationVector(); var encryptedPayload = await KeyVaultPlugin.Encrypt(payload, hash, iV);