/// <summary> /// Initializes a new instance of the <see cref="EncryptionPolicy"/> class. /// </summary> /// <param name="options">The options.</param> public EncryptionPolicy(Action <EncryptionPolicyOptions> options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } this.encryptionPolicyOptions = new EncryptionPolicyOptions(); options(this.encryptionPolicyOptions); this.encryptionPolicyOptions.Validate(); this.semaphoreSlim = new SemaphoreSlim(1); this.defaultSettings = new JsonSerializerSettings(); }
public EncryptionPolicy(IKey encryptionKey, IKeyResolver decryptionKeyResolver) { if (encryptionKey == null & decryptionKeyResolver == null) { throw new ArgumentException($"Neither {nameof(encryptionKey)} nor {nameof(decryptionKeyResolver)} has been set."); } this.cachedEncryptionKey = encryptionKey; this.encryptionPolicyOptions = new EncryptionPolicyOptions { KeyResolver = decryptionKeyResolver }; if (encryptionKey != null) { this.encryptionPolicyOptions.EncryptionKey = (token) => Task.FromResult(encryptionKey); } this.encryptionPolicyOptions.Validate(); this.semaphoreSlim = new SemaphoreSlim(1); this.defaultSettings = new JsonSerializerSettings(); }