NewSessionTicket.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using System.IO;
  4. namespace Org.BouncyCastle.Crypto.Tls
  5. {
  6. public class NewSessionTicket
  7. {
  8. protected readonly long mTicketLifetimeHint;
  9. protected readonly byte[] mTicket;
  10. public NewSessionTicket(long ticketLifetimeHint, byte[] ticket)
  11. {
  12. this.mTicketLifetimeHint = ticketLifetimeHint;
  13. this.mTicket = ticket;
  14. }
  15. public virtual long TicketLifetimeHint
  16. {
  17. get { return mTicketLifetimeHint; }
  18. }
  19. public virtual byte[] Ticket
  20. {
  21. get { return mTicket; }
  22. }
  23. /**
  24. * Encode this {@link NewSessionTicket} to a {@link Stream}.
  25. *
  26. * @param output the {@link Stream} to encode to.
  27. * @throws IOException
  28. */
  29. public virtual void Encode(Stream output)
  30. {
  31. TlsUtilities.WriteUint32(mTicketLifetimeHint, output);
  32. TlsUtilities.WriteOpaque16(mTicket, output);
  33. }
  34. /**
  35. * Parse a {@link NewSessionTicket} from a {@link Stream}.
  36. *
  37. * @param input the {@link Stream} to parse from.
  38. * @return a {@link NewSessionTicket} object.
  39. * @throws IOException
  40. */
  41. public static NewSessionTicket Parse(Stream input)
  42. {
  43. long ticketLifetimeHint = TlsUtilities.ReadUint32(input);
  44. byte[] ticket = TlsUtilities.ReadOpaque16(input);
  45. return new NewSessionTicket(ticketLifetimeHint, ticket);
  46. }
  47. }
  48. }
  49. #endif