in src/Internal/SetupEncryptionHandlerV2.cs [213:240]
private static void UpdateRequestInputStream(UploadPartRequest request, UploadPartEncryptionContext contextForEncryption, EncryptionInstructions instructions)
{
if (contextForEncryption.CryptoStream == null)
{
request.InputStream = EncryptionUtils.EncryptUploadPartRequestUsingInstructionsV2(request.InputStream, instructions);
}
else
{
request.InputStream = contextForEncryption.CryptoStream;
}
// Clear the buffer filled for retry request
var aesGcmEncryptCachingStream = request.InputStream as AesGcmEncryptCachingStream;
if (aesGcmEncryptCachingStream != null)
{
aesGcmEncryptCachingStream.ClearReadBufferToPosition();
}
var aesGcmEncryptStream = request.InputStream as AesGcmEncryptStream;
if (aesGcmEncryptStream != null)
{
// The stream is reused across multi part uploads to maintain the encryption state.
// The SDK will attempt to close the stream after the part is upload but setting
// DisableDispose to true for anything besides the last part will make the
// disable a noop.
aesGcmEncryptStream.DisableDispose = !request.IsLastPart;
}
}