DtlsEpoch.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Tls
  7. {
  8. internal sealed class DtlsEpoch
  9. {
  10. private readonly DtlsReplayWindow m_replayWindow = new DtlsReplayWindow();
  11. private readonly int m_epoch;
  12. private readonly TlsCipher m_cipher;
  13. private long m_sequenceNumber = 0;
  14. internal DtlsEpoch(int epoch, TlsCipher cipher)
  15. {
  16. if (epoch < 0)
  17. throw new ArgumentException("must be >= 0", "epoch");
  18. if (cipher == null)
  19. throw new ArgumentNullException("cipher");
  20. this.m_epoch = epoch;
  21. this.m_cipher = cipher;
  22. }
  23. /// <exception cref="IOException"/>
  24. internal long AllocateSequenceNumber()
  25. {
  26. lock (this)
  27. {
  28. if (m_sequenceNumber >= (1L << 48))
  29. throw new TlsFatalAlert(AlertDescription.internal_error);
  30. return m_sequenceNumber++;
  31. }
  32. }
  33. internal TlsCipher Cipher
  34. {
  35. get { return m_cipher; }
  36. }
  37. internal int Epoch
  38. {
  39. get { return m_epoch; }
  40. }
  41. internal DtlsReplayWindow ReplayWindow
  42. {
  43. get { return m_replayWindow; }
  44. }
  45. internal long SequenceNumber
  46. {
  47. get { lock (this) return m_sequenceNumber; }
  48. set { lock (this) this.m_sequenceNumber = value; }
  49. }
  50. }
  51. }
  52. #pragma warning restore
  53. #endif