NewSessionTicket.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Tls
  6. {
  7. public sealed class NewSessionTicket
  8. {
  9. private readonly long m_ticketLifetimeHint;
  10. private readonly byte[] m_ticket;
  11. public NewSessionTicket(long ticketLifetimeHint, byte[] ticket)
  12. {
  13. this.m_ticketLifetimeHint = ticketLifetimeHint;
  14. this.m_ticket = ticket;
  15. }
  16. public long TicketLifetimeHint
  17. {
  18. get { return m_ticketLifetimeHint; }
  19. }
  20. public byte[] Ticket
  21. {
  22. get { return m_ticket; }
  23. }
  24. /// <summary>Encode this <see cref="NewSessionTicket"/> to a <see cref="Stream"/>.</summary>
  25. /// <param name="output">the <see cref="Stream"/> to encode to.</param>
  26. /// <exception cref="IOException"/>
  27. public void Encode(Stream output)
  28. {
  29. TlsUtilities.WriteUint32(TicketLifetimeHint, output);
  30. TlsUtilities.WriteOpaque16(Ticket, output);
  31. }
  32. /// <summary>Parse a <see cref="NewSessionTicket"/> from a <see cref="Stream"/>.</summary>
  33. /// <param name="input">the <see cref="Stream"/> to parse from.</param>
  34. /// <returns>a <see cref="NewSessionTicket"/> object.</returns>
  35. /// <exception cref="IOException"/>
  36. public static NewSessionTicket Parse(Stream input)
  37. {
  38. long ticketLifetimeHint = TlsUtilities.ReadUint32(input);
  39. byte[] ticket = TlsUtilities.ReadOpaque16(input);
  40. return new NewSessionTicket(ticketLifetimeHint, ticket);
  41. }
  42. }
  43. }
  44. #pragma warning restore
  45. #endif