< Summary

Class:Azure.Storage.Cryptography.Models.EncryptionData
Assembly:Azure.Storage.Queues
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Common\src\Shared\ClientsideEncryption\Models\EncryptionData.cs
Covered lines:31
Uncovered lines:0
Coverable lines:31
Total lines:89
Line coverage:100% (31 of 31)
Covered branches:1
Total branches:2
Branch coverage:50% (1 of 2)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_EncryptionMode()-100%100%
get_WrappedContentKey()-100%100%
get_EncryptionAgent()-100%100%
get_ContentEncryptionIV()-100%100%
get_KeyWrappingMetadata()-100%100%
CreateInternalV1_0()-100%50%
get_AgentString()-100%100%
GenerateAgentString()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Common\src\Shared\ClientsideEncryption\Models\EncryptionData.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.Reflection;
 7using System.Runtime.InteropServices;
 8using System.Threading;
 9using System.Threading.Tasks;
 10using Azure.Core.Cryptography;
 11using Metadata = System.Collections.Generic.IDictionary<string, string>;
 12
 13namespace Azure.Storage.Cryptography.Models
 14{
 15    /// <summary>
 16    /// Represents the encryption data that is stored on the service.
 17    /// </summary>
 18    internal class EncryptionData
 19    {
 20        /// <summary>
 21        /// The blob encryption mode.
 22        /// </summary>
 2423        public string EncryptionMode { get; set; }
 24
 25        /// <summary>
 26        /// A <see cref="KeyEnvelope"/> object that stores the wrapping algorithm, key identifier and the encrypted key.
 27        /// </summary>
 2428        public KeyEnvelope WrappedContentKey { get; set; }
 29
 30        /// <summary>
 31        /// The encryption agent.
 32        /// </summary>
 2433        public EncryptionAgent EncryptionAgent { get; set; }
 34
 35        /// <summary>
 36        /// The content encryption IV.
 37        /// </summary>
 2438        public byte[] ContentEncryptionIV { get; set; }
 39
 40#pragma warning disable CA2227 // Collection properties should be read only
 41        /// <summary>
 42        /// Metadata for encryption. Currently used only for storing the encryption library, but may contain other data.
 43        /// </summary>
 2444        public Metadata KeyWrappingMetadata { get; set; }
 45#pragma warning restore CA2227 // Collection properties should be read only
 46
 47        internal static async Task<EncryptionData> CreateInternalV1_0(
 48            byte[] contentEncryptionIv,
 49            string keyWrapAlgorithm,
 50            byte[] contentEncryptionKey,
 51            IKeyEncryptionKey keyEncryptionKey,
 52            bool async,
 53            CancellationToken cancellationToken)
 654            => new EncryptionData()
 655            {
 656                EncryptionMode = Constants.ClientSideEncryption.EncryptionMode,
 657                ContentEncryptionIV = contentEncryptionIv,
 658                EncryptionAgent = new EncryptionAgent()
 659                {
 660                    EncryptionAlgorithm = ClientSideEncryptionAlgorithm.AesCbc256,
 661                    EncryptionVersion = ClientSideEncryptionVersion.V1_0
 662                },
 663                KeyWrappingMetadata = new Dictionary<string, string>()
 664                {
 665                    { Constants.ClientSideEncryption.AgentMetadataKey, AgentString }
 666                },
 667                WrappedContentKey = new KeyEnvelope()
 668                {
 669                    Algorithm = keyWrapAlgorithm,
 670                    EncryptedKey = async
 671                        ? await keyEncryptionKey.WrapKeyAsync(keyWrapAlgorithm, contentEncryptionKey, cancellationToken)
 672                        : keyEncryptionKey.WrapKey(keyWrapAlgorithm, contentEncryptionKey, cancellationToken),
 673                    KeyId = keyEncryptionKey.KeyId
 674                }
 675            };
 76
 77        /// <summary>
 78        /// Singleton string identifying this encryption library.
 79        /// </summary>
 880        private static string AgentString { get; } = GenerateAgentString();
 81
 82        private static string GenerateAgentString()
 83        {
 284            Assembly assembly = typeof(EncryptionData).Assembly;
 285            var platformInformation = $"({RuntimeInformation.FrameworkDescription}; {RuntimeInformation.OSDescription})"
 286            return $"azsdk-net-{assembly.GetName().Name}/{assembly.GetCustomAttribute<AssemblyInformationalVersionAttrib
 87        }
 88    }
 89}