TlsSessionImpl.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using Org.BouncyCastle.Utilities;
  4. namespace Org.BouncyCastle.Crypto.Tls
  5. {
  6. internal class TlsSessionImpl
  7. : TlsSession
  8. {
  9. internal readonly byte[] mSessionID;
  10. internal SessionParameters mSessionParameters;
  11. internal TlsSessionImpl(byte[] sessionID, SessionParameters sessionParameters)
  12. {
  13. if (sessionID == null)
  14. throw new ArgumentNullException("sessionID");
  15. if (sessionID.Length < 1 || sessionID.Length > 32)
  16. throw new ArgumentException("must have length between 1 and 32 bytes, inclusive", "sessionID");
  17. this.mSessionID = Arrays.Clone(sessionID);
  18. this.mSessionParameters = sessionParameters;
  19. }
  20. public virtual SessionParameters ExportSessionParameters()
  21. {
  22. lock (this)
  23. {
  24. return this.mSessionParameters == null ? null : this.mSessionParameters.Copy();
  25. }
  26. }
  27. public virtual byte[] SessionID
  28. {
  29. get { lock (this) return mSessionID; }
  30. }
  31. public virtual void Invalidate()
  32. {
  33. lock (this)
  34. {
  35. if (this.mSessionParameters != null)
  36. {
  37. this.mSessionParameters.Clear();
  38. this.mSessionParameters = null;
  39. }
  40. }
  41. }
  42. public virtual bool IsResumable
  43. {
  44. get { lock (this) return this.mSessionParameters != null; }
  45. }
  46. }
  47. }
  48. #endif