diff --git a/src/Microsoft.AspNetCore.DataProtection/KeyManagement/DefaultKeyServices.cs b/src/Microsoft.AspNetCore.DataProtection/KeyManagement/DefaultKeyServices.cs deleted file mode 100644 index 1fe5f0a5..00000000 --- a/src/Microsoft.AspNetCore.DataProtection/KeyManagement/DefaultKeyServices.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNetCore.Cryptography; -using Microsoft.AspNetCore.DataProtection.KeyManagement.Internal; -using Microsoft.AspNetCore.DataProtection.Repositories; -using Microsoft.AspNetCore.DataProtection.XmlEncryption; -using Microsoft.Extensions.DependencyInjection; - -namespace Microsoft.AspNetCore.DataProtection.KeyManagement -{ - internal sealed class DefaultKeyServices : IDefaultKeyServices - { - private readonly Lazy _keyEncryptorLazy; - private readonly Lazy _keyRepositoryLazy; - - public DefaultKeyServices(IServiceProvider services, ServiceDescriptor keyEncryptorDescriptor, ServiceDescriptor keyRepositoryDescriptor) - { - if (keyEncryptorDescriptor != null) - { - // optional - CryptoUtil.Assert(keyEncryptorDescriptor.ServiceType == typeof(IXmlEncryptor), "Bad service type."); - _keyEncryptorLazy = GetLazyForService(services, keyEncryptorDescriptor); - } - - CryptoUtil.Assert(keyRepositoryDescriptor.ServiceType == typeof(IXmlRepository), "Bad service type."); - _keyRepositoryLazy = GetLazyForService(services, keyRepositoryDescriptor); - } - - /// - /// Gets the default service (could return null). - /// - /// - public IXmlEncryptor GetKeyEncryptor() - { - return (IXmlEncryptor)_keyEncryptorLazy?.Value; - } - - /// - /// Gets the default service (must not be null). - /// - /// - public IXmlRepository GetKeyRepository() - { - return (IXmlRepository)_keyRepositoryLazy.Value ?? CryptoUtil.Fail("GetKeyRepository returned null."); - } - - private static Lazy GetLazyForService(IServiceProvider services, ServiceDescriptor descriptor) - { - CryptoUtil.Assert(descriptor != null && descriptor.Lifetime == ServiceLifetime.Singleton, "Descriptor must represent singleton."); - CryptoUtil.Assert(descriptor.ImplementationFactory != null, "Descriptor must have an implementation factory."); - - // pull the factory out so we don't close over the whole descriptor instance - Func wrapped = descriptor.ImplementationFactory; - return new Lazy(() => wrapped(services)); - } - } -} diff --git a/src/Microsoft.AspNetCore.DataProtection/KeyManagement/Internal/IDefaultKeyServices.cs b/src/Microsoft.AspNetCore.DataProtection/KeyManagement/Internal/IDefaultKeyServices.cs deleted file mode 100644 index 0552187f..00000000 --- a/src/Microsoft.AspNetCore.DataProtection/KeyManagement/Internal/IDefaultKeyServices.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNetCore.DataProtection.Repositories; -using Microsoft.AspNetCore.DataProtection.XmlEncryption; - -namespace Microsoft.AspNetCore.DataProtection.KeyManagement.Internal -{ - /// - /// Provides default implementations of the services required by an . - /// - public interface IDefaultKeyServices - { - /// - /// Gets the default service (could return null). - /// - /// - IXmlEncryptor GetKeyEncryptor(); - - /// - /// Gets the default service (must not be null). - /// - /// - IXmlRepository GetKeyRepository(); - } -}