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/PskIdentity.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/PskIdentity.cs')
-rw-r--r-- | crypto/src/tls/PskIdentity.cs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/crypto/src/tls/PskIdentity.cs b/crypto/src/tls/PskIdentity.cs new file mode 100644 index 000000000..9b24527bb --- /dev/null +++ b/crypto/src/tls/PskIdentity.cs @@ -0,0 +1,47 @@ +using System; +using System.IO; + +namespace Org.BouncyCastle.Tls +{ + public sealed class PskIdentity + { + private readonly byte[] m_identity; + private readonly long m_obfuscatedTicketAge; + + public PskIdentity(byte[] identity, long obfuscatedTicketAge) + { + if (null == identity) + throw new ArgumentNullException("identity"); + if (identity.Length < 1 || !TlsUtilities.IsValidUint16(identity.Length)) + throw new ArgumentException("should have length from 1 to 65535", "identity"); + if (!TlsUtilities.IsValidUint32(obfuscatedTicketAge)) + throw new ArgumentException("should be a uint32", "obfuscatedTicketAge"); + + this.m_identity = identity; + this.m_obfuscatedTicketAge = obfuscatedTicketAge; + } + + public byte[] Identity + { + get { return m_identity; } + } + + public long ObfuscatedTicketAge + { + get { return m_obfuscatedTicketAge; } + } + + public void Encode(Stream output) + { + TlsUtilities.WriteOpaque16(Identity, output); + TlsUtilities.WriteUint32(ObfuscatedTicketAge, output); + } + + public static PskIdentity Parse(Stream input) + { + byte[] identity = TlsUtilities.ReadOpaque16(input, 1); + long obfuscatedTicketAge = TlsUtilities.ReadUint32(input); + return new PskIdentity(identity, obfuscatedTicketAge); + } + } +} |