Skip to content

Commit

Permalink
Removed unnecessary return from SendPlaintextStreamAsync and SendCiph…
Browse files Browse the repository at this point in the history
…ertextStreamAsync methods

Signed-off-by: Whit Waldo <[email protected]>
  • Loading branch information
WhitWaldo committed Jan 4, 2024
1 parent db1489b commit b563cba
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/Dapr.Client/DaprClientGrpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,9 +1414,9 @@ private async Task<ReadOnlyMemory<byte>> EncryptDataAsync(string vaultResourceNa
var receiveResult = Task.FromResult(RetrieveEncryptedStreamAsync(duplexStream, cancellationToken));
await Task.WhenAll(
//Stream the plaintext data to the sidecar in chunks
Task.FromResult(SendPlaintextStreamAsync(plaintextStream,
SendPlaintextStreamAsync(plaintextStream,
encryptionOptions.StreamingBlockSizeInBytes, duplexStream, encryptRequestOptions,
cancellationToken)),
cancellationToken),
//At the same time, retrieve the encrypted response from the sidecar
receiveResult);

Expand Down Expand Up @@ -1478,8 +1478,8 @@ public override async IAsyncEnumerable<ReadOnlyMemory<byte>> EncryptAsync(string
var receiveResult = Task.FromResult(RetrieveEncryptedStreamAsync(duplexStream, cancellationToken));
await Task.WhenAll(
//Stream the plaintext data to the sidecar in chunks
Task.FromResult(SendPlaintextStreamAsync(plaintextStream, encryptionOptions.StreamingBlockSizeInBytes,
duplexStream, encryptRequestOptions, cancellationToken)),
SendPlaintextStreamAsync(plaintextStream, encryptionOptions.StreamingBlockSizeInBytes,
duplexStream, encryptRequestOptions, cancellationToken),
//At the same time, retrieve the encrypted response from the sidecar
receiveResult);

Expand All @@ -1493,11 +1493,11 @@ await Task.WhenAll(
/// <summary>
/// Sends the plaintext bytes in chunks to the sidecar to be encrypted.
/// </summary>
private async IAsyncEnumerable<byte[]> SendPlaintextStreamAsync(Stream plaintextStream,
private async Task SendPlaintextStreamAsync(Stream plaintextStream,
int streamingBlockSizeInBytes,
AsyncDuplexStreamingCall<Autogenerated.EncryptRequest, Autogenerated.EncryptResponse> duplexStream,
Autogenerated.EncryptRequestOptions encryptRequestOptions,
[EnumeratorCancellation] CancellationToken cancellationToken)
CancellationToken cancellationToken)
{
//Start with passing the metadata about the encryption request itself in the first message
await duplexStream.RequestStream.WriteAsync(
Expand Down Expand Up @@ -1525,15 +1525,11 @@ await duplexStream.RequestStream.WriteAsync(

//Increment the sequence number
sequenceNumber++;

//Yield an empty byte array to satisfy the return type though it's unused
yield return Array.Empty<byte>();
}
}

//Send the completion message
await duplexStream.RequestStream.CompleteAsync();
yield break; //End the async enumeration
}

/// <summary>
Expand Down Expand Up @@ -1571,8 +1567,8 @@ public override async IAsyncEnumerable<ReadOnlyMemory<byte>> DecryptAsync(string
var receiveResult = Task.FromResult(RetrieveDecryptedStreamAsync(duplexStream, cancellationToken));
await Task.WhenAll(
//Stream the ciphertext data to the sidecar in chunks
Task.FromResult(SendCiphertextStreamAsync(ciphertextStream, decryptionOptions.StreamingBlockSizeInBytes,
duplexStream, decryptRequestOptions, cancellationToken)),
SendCiphertextStreamAsync(ciphertextStream, decryptionOptions.StreamingBlockSizeInBytes,
duplexStream, decryptRequestOptions, cancellationToken),
//At the same time, retrieve the decrypted response from the sidecar
receiveResult
);
Expand All @@ -1594,11 +1590,11 @@ public override IAsyncEnumerable<ReadOnlyMemory<byte>> DecryptAsync(string vault
/// <summary>
/// Sends the ciphertext bytes in chunks to the sidecar to be decrypted.
/// </summary>
private async IAsyncEnumerable<ReadOnlyMemory<byte>> SendCiphertextStreamAsync(Stream ciphertextStream,
private async Task SendCiphertextStreamAsync(Stream ciphertextStream,
int streamingBlockSizeInBytes,
AsyncDuplexStreamingCall<Autogenerated.DecryptRequest, Autogenerated.DecryptResponse> duplexStream,
Autogenerated.DecryptRequestOptions decryptRequestOptions,
[EnumeratorCancellation] CancellationToken cancellationToken)
CancellationToken cancellationToken)
{
//Start with passing the metadata about the decryption request itself in the first message
await duplexStream.RequestStream.WriteAsync(
Expand All @@ -1624,15 +1620,11 @@ await duplexStream.RequestStream.WriteAsync(new Autogenerated.DecryptRequest

//Increment the sequence number
sequenceNumber++;

//Yield an empty byte array to satisfy the return type through it's unused
yield return Array.Empty<byte>();
}
}

//Send the completion message
await duplexStream.RequestStream.CompleteAsync();
yield break; // End the async enumeration
}

/// <summary>
Expand Down Expand Up @@ -1691,8 +1683,8 @@ private async Task<ReadOnlyMemory<byte>> DecryptDataAsync(string vaultResourceNa
var receiveResult = Task.FromResult(RetrieveDecryptedStreamAsync(duplexStream, cancellationToken));
await Task.WhenAll(
//Stream the ciphertext data to the sidecar in chunks
Task.FromResult(SendCiphertextStreamAsync(ciphertextStream, decryptionOptions.StreamingBlockSizeInBytes,
duplexStream, decryptRequestOptions, cancellationToken)),
SendCiphertextStreamAsync(ciphertextStream, decryptionOptions.StreamingBlockSizeInBytes,
duplexStream, decryptRequestOptions, cancellationToken),
//At the same time, retrieve the encrypted response from the sidecar
receiveResult);

Expand Down

0 comments on commit b563cba

Please sign in to comment.