TlsSessionImpl.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.Crypto.Tls
  6. {
  7. internal class TlsSessionImpl
  8. : TlsSession
  9. {
  10. internal readonly byte[] mSessionID;
  11. internal readonly SessionParameters mSessionParameters;
  12. internal bool mResumable;
  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.mSessionID = Arrays.Clone(sessionID);
  20. this.mSessionParameters = sessionParameters;
  21. this.mResumable = sessionID.Length > 0
  22. && null != sessionParameters
  23. && sessionParameters.IsExtendedMasterSecret;
  24. }
  25. public virtual SessionParameters ExportSessionParameters()
  26. {
  27. lock (this)
  28. {
  29. return this.mSessionParameters == null ? null : this.mSessionParameters.Copy();
  30. }
  31. }
  32. public virtual byte[] SessionID
  33. {
  34. get { lock (this) return mSessionID; }
  35. }
  36. public virtual void Invalidate()
  37. {
  38. lock (this) this.mResumable = false;
  39. }
  40. public virtual bool IsResumable
  41. {
  42. get { lock (this) return mResumable; }
  43. }
  44. }
  45. }
  46. #pragma warning restore
  47. #endif