| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using CoreWCF.Runtime; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Security |
| | | 8 | | { |
| | | 9 | | public abstract class NonceCache |
| | | 10 | | { |
| | | 11 | | private TimeSpan _cachingTime; |
| | | 12 | | private int _maxCachedNonces; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// TThe max timespan after which a Nonce is deleted from the NonceCache. This value should be atleast twice the |
| | | 16 | | /// </summary> |
| | | 17 | | public TimeSpan CachingTimeSpan |
| | | 18 | | { |
| | | 19 | | get |
| | | 20 | | { |
| | 0 | 21 | | return _cachingTime; |
| | | 22 | | } |
| | | 23 | | set |
| | | 24 | | { |
| | 0 | 25 | | if (value < TimeSpan.Zero) |
| | | 26 | | { |
| | 0 | 27 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 28 | | SR.Format(SRCommon.SFxTimeoutOutOfRange0))); |
| | | 29 | | } |
| | | 30 | | |
| | 0 | 31 | | if (TimeoutHelper.IsTooLarge(value)) |
| | | 32 | | { |
| | 0 | 33 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 34 | | SRCommon.SFxTimeoutOutOfRangeTooBig)); |
| | | 35 | | } |
| | | 36 | | |
| | 0 | 37 | | _cachingTime = value; |
| | 0 | 38 | | } |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// The maximum size of the NonceCache. |
| | | 43 | | /// </summary> |
| | | 44 | | public int CacheSize |
| | | 45 | | { |
| | | 46 | | get |
| | | 47 | | { |
| | 0 | 48 | | return _maxCachedNonces; |
| | | 49 | | } |
| | | 50 | | set |
| | | 51 | | { |
| | 0 | 52 | | if (value < 0) |
| | | 53 | | { |
| | 0 | 54 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 55 | | SRCommon.ValueMustBeNonNegative)); |
| | | 56 | | } |
| | 0 | 57 | | _maxCachedNonces = value; |
| | 0 | 58 | | } |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | public abstract bool TryAddNonce(byte[] nonce); |
| | | 62 | | public abstract bool CheckNonce(byte[] nonce); |
| | | 63 | | } |
| | | 64 | | } |