#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Tls
{
public sealed class KeyShareEntry
{
private static bool CheckKeyExchangeLength(int length)
{
return 0 < length && length < (1 << 16);
}
private readonly int m_namedGroup;
private readonly byte[] m_keyExchange;
///
///
public KeyShareEntry(int namedGroup, byte[] keyExchange)
{
if (!TlsUtilities.IsValidUint16(namedGroup))
throw new ArgumentException("should be a uint16", "namedGroup");
if (null == keyExchange)
throw new ArgumentNullException("keyExchange");
if (!CheckKeyExchangeLength(keyExchange.Length))
throw new ArgumentException("must have length from 1 to (2^16 - 1)", "keyExchange");
this.m_namedGroup = namedGroup;
this.m_keyExchange = keyExchange;
}
///
public int NamedGroup
{
get { return m_namedGroup; }
}
public byte[] KeyExchange
{
get { return m_keyExchange; }
}
/// Encode this to a .
/// the to encode to.
///
public void Encode(Stream output)
{
TlsUtilities.WriteUint16(NamedGroup, output);
TlsUtilities.WriteOpaque16(KeyExchange, output);
}
/// Parse a from a .
/// the to parse from.
/// a object.
///
public static KeyShareEntry Parse(Stream input)
{
int namedGroup = TlsUtilities.ReadUint16(input);
byte[] keyExchange = TlsUtilities.ReadOpaque16(input, 1);
return new KeyShareEntry(namedGroup, keyExchange);
}
}
}
#pragma warning restore
#endif