< Summary

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

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_EncryptionMode()-0%100%
get_WrappedContentKey()-0%100%
get_EncryptionAgent()-0%100%
get_ContentEncryptionIV()-0%100%
get_KeyWrappingMetadata()-0%100%
CreateInternalV1_0()-0%0%
get_AgentString()-0%100%
GenerateAgentString()-0%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>
 023        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>
 028        public KeyEnvelope WrappedContentKey { get; set; }
 29
 30        /// <summary>
 31        /// The encryption agent.
 32        /// </summary>
 033        public EncryptionAgent EncryptionAgent { get; set; }
 34
 35        /// <summary>
 36        /// The content encryption IV.
 37        /// </summary>
 038        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>
 044        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)
 054            => new EncryptionData()
 055            {
 056                EncryptionMode = Constants.ClientSideEncryption.EncryptionMode,
 057                ContentEncryptionIV = contentEncryptionIv,
 058                EncryptionAgent = new EncryptionAgent()
 059                {
 060                    EncryptionAlgorithm = ClientSideEncryptionAlgorithm.AesCbc256,
 061                    EncryptionVersion = ClientSideEncryptionVersion.V1_0
 062                },
 063                KeyWrappingMetadata = new Dictionary<string, string>()
 064                {
 065                    { Constants.ClientSideEncryption.AgentMetadataKey, AgentString }
 066                },
 067                WrappedContentKey = new KeyEnvelope()
 068                {
 069                    Algorithm = keyWrapAlgorithm,
 070                    EncryptedKey = async
 071                        ? await keyEncryptionKey.WrapKeyAsync(keyWrapAlgorithm, contentEncryptionKey, cancellationToken)
 072                        : keyEncryptionKey.WrapKey(keyWrapAlgorithm, contentEncryptionKey, cancellationToken),
 073                    KeyId = keyEncryptionKey.KeyId
 074                }
 075            };
 76
 77        /// <summary>
 78        /// Singleton string identifying this encryption library.
 79        /// </summary>
 080        private static string AgentString { get; } = GenerateAgentString();
 81
 82        private static string GenerateAgentString()
 83        {
 084            Assembly assembly = typeof(EncryptionData).Assembly;
 085            var platformInformation = $"({RuntimeInformation.FrameworkDescription}; {RuntimeInformation.OSDescription})"
 086            return $"azsdk-net-{assembly.GetName().Name}/{assembly.GetCustomAttribute<AssemblyInformationalVersionAttrib
 87        }
 88    }
 89}