public void ChangeSecurityProtocol(SecurityOptions options) {
if (options == null)
throw new ArgumentNullException();
if (m_Options != null && m_Options.Protocol != SecureProtocol.None)
throw new ArgumentException("Only changing from a normal connection to a secure connection is supported.");
if (base.ProtocolType != ProtocolType.Tcp && options.Protocol != SecureProtocol.None)
throw new SecurityException("Security protocols require underlying TCP connections!");
// check SecurityOptions structure
if (options.Protocol != SecureProtocol.None) {
if (options.Entity == ConnectionEnd.Server && options.Certificate == null)
throw new ArgumentException("The certificate cannot be set to a null reference when creating a server socket.");
if (options.Certificate != null && !options.Certificate.HasPrivateKey())
throw new ArgumentException("If a certificate is specified, it must have a private key.");
if (((int)options.AllowedAlgorithms & (int)SslAlgorithms.NULL_COMPRESSION) == 0)
throw new ArgumentException("The allowed algorithms field must contain at least one compression algorithm.");
if (((int)options.AllowedAlgorithms ^ (int)SslAlgorithms.NULL_COMPRESSION) == 0)
throw new ArgumentException("The allowed algorithms field must contain at least one cipher suite.");
if (options.VerificationType == CredentialVerification.Manual && options.Verifier == null)
throw new ArgumentException("A CertVerifyEventHandler is required when using manual certificate verification.");
}
m_Options = (SecurityOptions)options.Clone();
if (options.Protocol != SecureProtocol.None) {
if (this.Connected)
m_Controller = new SocketController(this, base.InternalSocket, options);
}
}
/// <summary>