@@ -19,7 +19,8 @@ internal sealed class KeyRingProvider : ICacheableKeyRingProvider, IKeyRingProvi
19
19
private CacheableKeyRing ? _cacheableKeyRing ;
20
20
private readonly object _cacheableKeyRingLockObj = new object ( ) ;
21
21
private readonly IDefaultKeyResolver _defaultKeyResolver ;
22
- private readonly KeyManagementOptions _keyManagementOptions ;
22
+ private readonly bool _autoGenerateKeys ;
23
+ private readonly TimeSpan _newKeyLifetime ;
23
24
private readonly IKeyManager _keyManager ;
24
25
private readonly ILogger _logger ;
25
26
@@ -41,7 +42,9 @@ public KeyRingProvider(
41
42
IDefaultKeyResolver defaultKeyResolver ,
42
43
ILoggerFactory loggerFactory )
43
44
{
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 ;
45
48
_keyManager = keyManager ;
46
49
CacheableKeyRingProvider = this ;
47
50
_defaultKeyResolver = defaultKeyResolver ;
@@ -113,7 +116,7 @@ private CacheableKeyRing CreateCacheableKeyRingCore(DateTimeOffset now, IKey? ke
113
116
114
117
// We have been asked to generate a new key, but auto-generation of keys has been disabled.
115
118
// We need to use the fallback key or fail.
116
- if ( ! _keyManagementOptions . AutoGenerateKeys )
119
+ if ( ! _autoGenerateKeys )
117
120
{
118
121
var keyToUse = defaultKey ?? defaultKeyPolicy . FallbackKey ;
119
122
if ( keyToUse == null )
@@ -135,15 +138,15 @@ private CacheableKeyRing CreateCacheableKeyRingCore(DateTimeOffset now, IKey? ke
135
138
{
136
139
// The case where there's no default key is the easiest scenario, since it
137
140
// 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 ) ;
139
142
return CreateCacheableKeyRingCore ( now , keyJustAdded : newKey ) ; // recursively call
140
143
}
141
144
else
142
145
{
143
146
// If there is a default key, then the new key we generate should become active upon
144
147
// expiration of the default key. The new key lifetime is measured from the creation
145
148
// 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 ) ;
147
150
return CreateCacheableKeyRingCore ( now , keyJustAdded : newKey ) ; // recursively call
148
151
}
149
152
}
0 commit comments