@@ -19,7 +19,8 @@ internal sealed class KeyRingProvider : ICacheableKeyRingProvider, IKeyRingProvi
1919 private CacheableKeyRing ? _cacheableKeyRing ;
2020 private readonly object _cacheableKeyRingLockObj = new object ( ) ;
2121 private readonly IDefaultKeyResolver _defaultKeyResolver ;
22- private readonly KeyManagementOptions _keyManagementOptions ;
22+ private readonly bool _autoGenerateKeys ;
23+ private readonly TimeSpan _newKeyLifetime ;
2324 private readonly IKeyManager _keyManager ;
2425 private readonly ILogger _logger ;
2526
@@ -41,7 +42,9 @@ public KeyRingProvider(
4142 IDefaultKeyResolver defaultKeyResolver ,
4243 ILoggerFactory loggerFactory )
4344 {
44- _keyManagementOptions = new KeyManagementOptions ( keyManagementOptions . Value ) ; // clone so new instance is immutable
45+ var options = keyManagementOptions . Value ?? new ( ) ;
46+ _autoGenerateKeys = options . AutoGenerateKeys ;
47+ _newKeyLifetime = options . NewKeyLifetime ;
4548 _keyManager = keyManager ;
4649 CacheableKeyRingProvider = this ;
4750 _defaultKeyResolver = defaultKeyResolver ;
@@ -113,7 +116,7 @@ private CacheableKeyRing CreateCacheableKeyRingCore(DateTimeOffset now, IKey? ke
113116
114117 // We have been asked to generate a new key, but auto-generation of keys has been disabled.
115118 // We need to use the fallback key or fail.
116- if ( ! _keyManagementOptions . AutoGenerateKeys )
119+ if ( ! _autoGenerateKeys )
117120 {
118121 var keyToUse = defaultKey ?? defaultKeyPolicy . FallbackKey ;
119122 if ( keyToUse == null )
@@ -135,15 +138,15 @@ private CacheableKeyRing CreateCacheableKeyRingCore(DateTimeOffset now, IKey? ke
135138 {
136139 // The case where there's no default key is the easiest scenario, since it
137140 // means that we need to create a new key with immediate activation.
138- var newKey = _keyManager . CreateNewKey ( activationDate : now , expirationDate : now + _keyManagementOptions . NewKeyLifetime ) ;
141+ var newKey = _keyManager . CreateNewKey ( activationDate : now , expirationDate : now + _newKeyLifetime ) ;
139142 return CreateCacheableKeyRingCore ( now , keyJustAdded : newKey ) ; // recursively call
140143 }
141144 else
142145 {
143146 // If there is a default key, then the new key we generate should become active upon
144147 // expiration of the default key. The new key lifetime is measured from the creation
145148 // date (now), not the activation date.
146- var newKey = _keyManager . CreateNewKey ( activationDate : defaultKey . ExpirationDate , expirationDate : now + _keyManagementOptions . NewKeyLifetime ) ;
149+ var newKey = _keyManager . CreateNewKey ( activationDate : defaultKey . ExpirationDate , expirationDate : now + _newKeyLifetime ) ;
147150 return CreateCacheableKeyRingCore ( now , keyJustAdded : newKey ) ; // recursively call
148151 }
149152 }
0 commit comments