< Summary

Class:Microsoft.AspNetCore.DataProtection.AzureDataProtectionKeyVaultKeyBuilderExtensions
Assembly:Azure.Extensions.AspNetCore.DataProtection.Keys
File(s):C:\Git\azure-sdk-for-net\sdk\extensions\Azure.Extensions.AspNetCore.DataProtection.Keys\src\AzureDataProtectionKeyVaultKeyBuilderExtensions.cs
Covered lines:0
Uncovered lines:11
Coverable lines:11
Total lines:56
Line coverage:0% (0 of 11)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ProtectKeysWithAzureKeyVault(...)-0%100%
ProtectKeysWithAzureKeyVault(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\extensions\Azure.Extensions.AspNetCore.DataProtection.Keys\src\AzureDataProtectionKeyVaultKeyBuilderExtensions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using Azure.Extensions.AspNetCore.DataProtection.Keys;
 6using Azure.Core;
 7using Azure.Core.Cryptography;
 8using Azure.Security.KeyVault.Keys.Cryptography;
 9using Microsoft.AspNetCore.DataProtection.KeyManagement;
 10using Microsoft.Extensions.DependencyInjection;
 11
 12#pragma warning disable AZC0001 // Extension methods have to be in the correct namespace to appear in intellisense.
 13namespace Microsoft.AspNetCore.DataProtection
 14#pragma warning disable
 15{
 16    /// <summary>
 17    /// Contains Azure KeyVault-specific extension methods for modifying a <see cref="IDataProtectionBuilder"/>.
 18    /// </summary>
 19    public static class AzureDataProtectionKeyVaultKeyBuilderExtensions
 20    {
 21        /// <summary>
 22        /// Configures the data protection system to protect keys with specified key in Azure KeyVault.
 23        /// </summary>
 24        /// <param name="builder">The builder instance to modify.</param>
 25        /// <param name="keyIdentifier">The Azure Key Vault key identifier used for key encryption.</param>
 26        /// <param name="tokenCredential">The token credential to use for authentication.</param>
 27        /// <returns>The value <paramref name="builder"/>.</returns>
 28        public static IDataProtectionBuilder ProtectKeysWithAzureKeyVault(this IDataProtectionBuilder builder, Uri keyId
 29        {
 030            Argument.AssertNotNull(keyIdentifier, nameof(keyIdentifier));
 031            return ProtectKeysWithAzureKeyVault(builder, keyIdentifier.ToString(), new KeyResolver(tokenCredential));
 32        }
 33
 34        /// <summary>
 35        /// Configures the data protection system to protect keys with specified key in Azure KeyVault.
 36        /// </summary>
 37        /// <param name="builder">The builder instance to modify.</param>
 38        /// <param name="keyResolver">The <see cref="IKeyEncryptionKeyResolver"/> to use for Key Vault access.</param>
 39        /// <param name="keyIdentifier">The Azure Key Vault key identifier used for key encryption.</param>
 40        /// <returns>The value <paramref name="builder"/>.</returns>
 41        public static IDataProtectionBuilder ProtectKeysWithAzureKeyVault(this IDataProtectionBuilder builder, string ke
 42        {
 043            Argument.AssertNotNull(builder, nameof(builder));
 044            Argument.AssertNotNull(keyResolver, nameof(keyResolver));
 045            Argument.AssertNotNullOrEmpty(keyIdentifier, nameof(keyIdentifier));
 46
 047            builder.Services.AddSingleton<IKeyEncryptionKeyResolver>(keyResolver);
 048            builder.Services.Configure<KeyManagementOptions>(options =>
 049            {
 050                options.XmlEncryptor = new AzureKeyVaultXmlEncryptor(keyResolver, keyIdentifier);
 051            });
 52
 053            return builder;
 54        }
 55    }
 56}