Amazon.S3.Encryption.AmazonS3EncryptionClient.ProcessPreRequestHandlers C# (CSharp) Method

ProcessPreRequestHandlers() protected method

Performs encryption for PutObject and MultiPartUpload, also adding encryption information to object metadata or instruction file
protected ProcessPreRequestHandlers ( AmazonWebServiceRequest request ) : void
request Amazon.Runtime.AmazonWebServiceRequest AmazonWebServiceRequest on which encryption is performed
return void
        protected override void ProcessPreRequestHandlers(AmazonWebServiceRequest request)
        {
            base.ProcessPreRequestHandlers(request);

            var putObjectRequest = request as PutObjectRequest;
            if (putObjectRequest != null)
            {
                if (this.amazonS3CryptoConfig.StorageMode == CryptoStorageMode.InstructionFile)
                {
                    GenerateEncryptedObjectRequestUsingInstructionFile(putObjectRequest);
                }
                else
                {
                    GenerateEncryptedObjectRequestUsingMetadata(putObjectRequest);
                }
            }

            var initiateMultiPartRequest = request as InitiateMultipartUploadRequest;
            if (initiateMultiPartRequest != null)
            {
                EncryptionInstructions instructions = EncryptionUtils.GenerateInstructions(this.encryptionMaterials);

                if (this.amazonS3CryptoConfig.StorageMode == CryptoStorageMode.ObjectMetadata)
                {
                    EncryptionUtils.UpdateMetadataWithEncryptionInstructions(initiateMultiPartRequest, instructions);
                }

                initiateMultiPartRequest.EnvelopeKey = instructions.EnvelopeKey;
                initiateMultiPartRequest.IV = instructions.InitializationVector;
            }

            var uploadPartRequest = request as UploadPartRequest;
            if (uploadPartRequest != null)
            {
                GenerateEncryptedUploadPartRequest(uploadPartRequest);
            }
        }