// 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 System.Collections.Generic; using System.Threading; namespace Microsoft.AspNetCore.DataProtection.KeyManagement { /// /// The basic interface for performing key management operations. /// /// /// Instantiations of this interface are expected to be thread-safe. /// public interface IKeyManager { /// /// Creates a new key with the specified activation and expiration dates and persists /// the new key to the underlying repository. /// /// The date on which encryptions to this key may begin. /// The date after which encryptions to this key may no longer take place. /// The newly-created IKey instance. IKey CreateNewKey(DateTimeOffset activationDate, DateTimeOffset expirationDate); /// /// Fetches all keys from the underlying repository. /// /// The collection of all keys. IReadOnlyCollection GetAllKeys(); /// /// Retrieves a token that signals that callers who have cached the return value of /// GetAllKeys should clear their caches. This could be in response to a call to /// CreateNewKey or RevokeKey, or it could be in response to some other external notification. /// Callers who are interested in observing this token should call this method before the /// corresponding call to GetAllKeys. /// /// /// The cache expiration token. When an expiration notification is triggered, any /// tokens previously returned by this method will become canceled, and tokens returned by /// future invocations of this method will themselves not trigger until the next expiration /// event. /// /// /// Implementations are free to return 'CancellationToken.None' from this method. /// Since this token is never guaranteed to fire, callers should still manually /// clear their caches at a regular interval. /// CancellationToken GetCacheExpirationToken(); /// /// Revokes a specific key and persists the revocation to the underlying repository. /// /// The id of the key to revoke. /// An optional human-readable reason for revocation. /// /// This method will not mutate existing IKey instances. After calling this method, /// all existing IKey instances should be discarded, and GetAllKeys should be called again. /// void RevokeKey(Guid keyId, string reason = null); /// /// Revokes all keys created before a specified date and persists the revocation to the /// underlying repository. /// /// The revocation date. All keys with a creation date before /// this value will be revoked. /// An optional human-readable reason for revocation. /// /// This method will not mutate existing IKey instances. After calling this method, /// all existing IKey instances should be discarded, and GetAllKeys should be called again. /// void RevokeAllKeys(DateTimeOffset revocationDate, string reason = null); } }