diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-07-12 15:15:36 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-07-12 15:15:36 +0700 |
commit | 68c795fe81277f73aeb90d8ad4c6f4305f32c906 (patch) | |
tree | 59643344aafef91bbd4c4a3a7973deba3d837a00 /crypto/src/tls/NewSessionTicket.cs | |
parent | TLS test tweaks (diff) | |
download | BouncyCastle.NET-ed25519-68c795fe81277f73aeb90d8ad4c6f4305f32c906.tar.xz |
Port of new TLS API from bc-java
Diffstat (limited to 'crypto/src/tls/NewSessionTicket.cs')
-rw-r--r-- | crypto/src/tls/NewSessionTicket.cs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/crypto/src/tls/NewSessionTicket.cs b/crypto/src/tls/NewSessionTicket.cs new file mode 100644 index 000000000..6e2a01305 --- /dev/null +++ b/crypto/src/tls/NewSessionTicket.cs @@ -0,0 +1,47 @@ +using System; +using System.IO; + +namespace Org.BouncyCastle.Tls +{ + public sealed class NewSessionTicket + { + private readonly long m_ticketLifetimeHint; + private readonly byte[] m_ticket; + + public NewSessionTicket(long ticketLifetimeHint, byte[] ticket) + { + this.m_ticketLifetimeHint = ticketLifetimeHint; + this.m_ticket = ticket; + } + + public long TicketLifetimeHint + { + get { return m_ticketLifetimeHint; } + } + + public byte[] Ticket + { + get { return m_ticket; } + } + + /// <summary>Encode this <see cref="NewSessionTicket"/> to a <see cref="Stream"/>.</summary> + /// <param name="output">the <see cref="Stream"/> to encode to.</param> + /// <exception cref="IOException"/> + public void Encode(Stream output) + { + TlsUtilities.WriteUint32(TicketLifetimeHint, output); + TlsUtilities.WriteOpaque16(Ticket, output); + } + + /// <summary>Parse a <see cref="NewSessionTicket"/> from a <see cref="Stream"/>.</summary> + /// <param name="input">the <see cref="Stream"/> to parse from.</param> + /// <returns>a <see cref="NewSessionTicket"/> object.</returns> + /// <exception cref="IOException"/> + public static NewSessionTicket Parse(Stream input) + { + long ticketLifetimeHint = TlsUtilities.ReadUint32(input); + byte[] ticket = TlsUtilities.ReadOpaque16(input); + return new NewSessionTicket(ticketLifetimeHint, ticket); + } + } +} |