TlsSessionImpl.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Tls
  6. {
  7. internal class TlsSessionImpl
  8. : TlsSession
  9. {
  10. private readonly byte[] m_sessionID;
  11. private readonly SessionParameters m_sessionParameters;
  12. private bool m_resumable;
  13. internal TlsSessionImpl(byte[] sessionID, SessionParameters sessionParameters)
  14. {
  15. if (sessionID == null)
  16. throw new ArgumentNullException("sessionID");
  17. if (sessionID.Length > 32)
  18. throw new ArgumentException("cannot be longer than 32 bytes", "sessionID");
  19. this.m_sessionID = Arrays.Clone(sessionID);
  20. this.m_sessionParameters = sessionParameters;
  21. this.m_resumable = sessionID.Length > 0 && null != sessionParameters;
  22. }
  23. public SessionParameters ExportSessionParameters()
  24. {
  25. lock (this)
  26. {
  27. return m_sessionParameters == null ? null : m_sessionParameters.Copy();
  28. }
  29. }
  30. public byte[] SessionID
  31. {
  32. get { lock (this) return m_sessionID; }
  33. }
  34. public void Invalidate()
  35. {
  36. lock (this)
  37. {
  38. this.m_resumable = false;
  39. }
  40. }
  41. public bool IsResumable
  42. {
  43. get { lock (this) return m_resumable; }
  44. }
  45. }
  46. }
  47. #pragma warning restore
  48. #endif