< Summary

Class:Azure.Storage.Queues.QueueClientSideDecryptor
Assembly:Azure.Storage.Queues
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Queues\src\QueueClientSideDecryptor.cs
Covered lines:0
Uncovered lines:41
Coverable lines:41
Total lines:88
Line coverage:0% (0 of 41)
Covered branches:0
Total branches:8
Branch coverage:0% (0 of 8)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Options()-0%100%
.ctor(...)-0%100%
ClientSideDecryptMessagesInternal()-0%0%
ClientSideDecryptMessagesInternal()-0%0%
ClientSideDecryptInternal()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Queues\src\QueueClientSideDecryptor.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.IO;
 7using System.Text;
 8using System.Threading;
 9using System.Threading.Tasks;
 10using Azure.Storage.Cryptography;
 11using Azure.Storage.Queues.Models;
 12using Azure.Storage.Queues.Specialized;
 13using Azure.Storage.Queues.Specialized.Models;
 14
 15namespace Azure.Storage.Queues
 16{
 17    internal class QueueClientSideDecryptor
 18    {
 19        private readonly ClientSideDecryptor _decryptor;
 020        public QueueClientSideEncryptionOptions Options { get; }
 21
 022        public QueueClientSideDecryptor(QueueClientSideEncryptionOptions options)
 23        {
 024            _decryptor = new ClientSideDecryptor(options);
 025            Options = options;
 026        }
 27
 28        public async Task<QueueMessage[]> ClientSideDecryptMessagesInternal(QueueMessage[] messages, bool async, Cancell
 29        {
 030            var filteredMessages = new List<QueueMessage>();
 031            foreach (var message in messages)
 32            {
 33                try
 34                {
 035                    message.MessageText = await ClientSideDecryptInternal(message.MessageText, async, cancellationToken)
 036                    filteredMessages.Add(message);
 037                }
 038                catch (Exception e) when (Options.UsingDecryptionFailureHandler)
 39                {
 040                    Options.OnDecryptionFailed(message, e);
 041                }
 042            }
 043            return filteredMessages.ToArray();
 044        }
 45        public async Task<PeekedMessage[]> ClientSideDecryptMessagesInternal(PeekedMessage[] messages, bool async, Cance
 46        {
 047            var filteredMessages = new List<PeekedMessage>();
 048            foreach (var message in messages)
 49            {
 50                try
 51                {
 052                    message.MessageText = await ClientSideDecryptInternal(message.MessageText, async, cancellationToken)
 053                    filteredMessages.Add(message);
 054                }
 055                catch (Exception e) when (Options.UsingDecryptionFailureHandler)
 56                {
 057                    Options.OnDecryptionFailed(message, e);
 058                }
 059            }
 060            return filteredMessages.ToArray();
 061        }
 62
 63        private async Task<string> ClientSideDecryptInternal(string downloadedMessage, bool async, CancellationToken can
 64        {
 065            if (!EncryptedMessageSerializer.TryDeserialize(downloadedMessage, out var encryptedMessage))
 66            {
 067                return downloadedMessage; // not recognized as client-side encrypted message
 68            }
 69
 070            var encryptedMessageStream = new MemoryStream(Convert.FromBase64String(encryptedMessage.EncryptedMessageText
 071            var decryptedMessageStream = await _decryptor.DecryptInternal(
 072                encryptedMessageStream,
 073                encryptedMessage.EncryptionData,
 074                ivInStream: false,
 075                noPadding: false,
 076                async: async,
 077                cancellationToken).ConfigureAwait(false);
 78            // if we got back the stream we put in, then we couldn't decrypt and are supposed to return the original
 79            // message to the user
 080            if (encryptedMessageStream == decryptedMessageStream)
 81            {
 082                return downloadedMessage;
 83            }
 84
 085            return new StreamReader(decryptedMessageStream, Encoding.UTF8).ReadToEnd();
 086        }
 87    }
 88}