NewSessionTicket.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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.Crypto.Tls
  6. {
  7. public class NewSessionTicket
  8. {
  9. protected readonly long mTicketLifetimeHint;
  10. protected readonly byte[] mTicket;
  11. public NewSessionTicket(long ticketLifetimeHint, byte[] ticket)
  12. {
  13. this.mTicketLifetimeHint = ticketLifetimeHint;
  14. this.mTicket = ticket;
  15. }
  16. public virtual long TicketLifetimeHint
  17. {
  18. get { return mTicketLifetimeHint; }
  19. }
  20. public virtual byte[] Ticket
  21. {
  22. get { return mTicket; }
  23. }
  24. /**
  25. * Encode this {@link NewSessionTicket} to a {@link Stream}.
  26. *
  27. * @param output the {@link Stream} to encode to.
  28. * @throws IOException
  29. */
  30. public virtual void Encode(Stream output)
  31. {
  32. TlsUtilities.WriteUint32(mTicketLifetimeHint, output);
  33. TlsUtilities.WriteOpaque16(mTicket, output);
  34. }
  35. /**
  36. * Parse a {@link NewSessionTicket} from a {@link Stream}.
  37. *
  38. * @param input the {@link Stream} to parse from.
  39. * @return a {@link NewSessionTicket} object.
  40. * @throws IOException
  41. */
  42. public static NewSessionTicket Parse(Stream input)
  43. {
  44. long ticketLifetimeHint = TlsUtilities.ReadUint32(input);
  45. byte[] ticket = TlsUtilities.ReadOpaque16(input);
  46. return new NewSessionTicket(ticketLifetimeHint, ticket);
  47. }
  48. }
  49. }
  50. #pragma warning restore
  51. #endif