2
0

NonceCache.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Globalization;
  7. using System.Runtime;
  8. namespace System.ServiceModel.Security
  9. {
  10. public abstract class NonceCache
  11. {
  12. TimeSpan cachingTime;
  13. int maxCachedNonces;
  14. /// <summary>
  15. /// TThe max timespan after which a Nonce is deleted from the NonceCache. This value should be atleast twice the maxclock Skew added to the replayWindow size.
  16. /// </summary>
  17. public TimeSpan CachingTimeSpan
  18. {
  19. get
  20. {
  21. return this.cachingTime;
  22. }
  23. set
  24. {
  25. if (value < TimeSpan.Zero)
  26. {
  27. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  28. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  29. }
  30. if (TimeoutHelper.IsTooLarge(value))
  31. {
  32. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  33. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  34. }
  35. this.cachingTime = value;
  36. }
  37. }
  38. /// <summary>
  39. /// The maximum size of the NonceCache.
  40. /// </summary>
  41. public int CacheSize
  42. {
  43. get
  44. {
  45. return this.maxCachedNonces;
  46. }
  47. set
  48. {
  49. if (value < 0)
  50. {
  51. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  52. SR.GetString(SR.ValueMustBeNonNegative)));
  53. }
  54. this.maxCachedNonces = value;
  55. }
  56. }
  57. public abstract bool TryAddNonce(byte[] nonce);
  58. public abstract bool CheckNonce(byte[] nonce);
  59. }
  60. }