public KeyRingProvider(IKeyManager keyManager, KeyManagementOptions keyManagementOptions, IServiceProvider services)
 {
     _keyManagementOptions = new KeyManagementOptions(keyManagementOptions); // clone so new instance is immutable
     _keyManager = keyManager;
     _cacheableKeyRingProvider = services?.GetService<ICacheableKeyRingProvider>() ?? this;
     _logger = services?.GetLogger<KeyRingProvider>();
     _defaultKeyResolver = services?.GetService<IDefaultKeyResolver>()
         ?? new DefaultKeyResolver(_keyManagementOptions.KeyPropagationWindow, _keyManagementOptions.MaxServerClockSkew, services);
 }
Example #2
0
 public KeyRingProvider(IKeyManager keyManager, KeyManagementOptions keyManagementOptions, IServiceProvider services)
 {
     _keyManagementOptions     = new KeyManagementOptions(keyManagementOptions); // clone so new instance is immutable
     _keyManager               = keyManager;
     _cacheableKeyRingProvider = services?.GetService <ICacheableKeyRingProvider>() ?? this;
     _logger             = services?.GetLogger <KeyRingProvider>();
     _defaultKeyResolver = services?.GetService <IDefaultKeyResolver>()
                           ?? new DefaultKeyResolver(_keyManagementOptions.KeyPropagationWindow, _keyManagementOptions.MaxServerClockSkew, services);
 }
Example #3
0
        private static KeyRingProvider CreateKeyRingProvider(ICacheableKeyRingProvider cacheableKeyRingProvider)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <ICacheableKeyRingProvider>(cacheableKeyRingProvider);
            return(new KeyRingProvider(
                       keyManager: null,
                       keyManagementOptions: null,
                       services: serviceCollection.BuildServiceProvider()));
        }
Example #4
0
    private static KeyRingProvider CreateKeyRingProvider(ICacheableKeyRingProvider cacheableKeyRingProvider)
    {
        var mockEncryptorFactory = new Mock <IAuthenticatedEncryptorFactory>();

        mockEncryptorFactory.Setup(m => m.CreateEncryptorInstance(It.IsAny <IKey>())).Returns(new Mock <IAuthenticatedEncryptor>().Object);
        var options = new KeyManagementOptions();

        options.AuthenticatedEncryptorFactories.Add(mockEncryptorFactory.Object);

        return(new KeyRingProvider(
                   keyManager: null,
                   keyManagementOptions: Options.Create(options),
                   defaultKeyResolver: null,
                   loggerFactory: NullLoggerFactory.Instance)
        {
            CacheableKeyRingProvider = cacheableKeyRingProvider
        });
    }
 private static KeyRingProvider CreateKeyRingProvider(ICacheableKeyRingProvider cacheableKeyRingProvider)
 {
     var serviceCollection = new ServiceCollection();
     serviceCollection.AddInstance<ICacheableKeyRingProvider>(cacheableKeyRingProvider);
     return new KeyRingProvider(
         keyManager: null,
         keyManagementOptions: null,
         services: serviceCollection.BuildServiceProvider());
 }