/// <summary>
/// Turns encryption on/off on an already connected socket
/// </summary>
/// <param name="stream">The stream resource.</param>
/// <param name="enable">Enable/disable cryptography on the stream.</param>
/// <returns>Returns TRUE on success, FALSE if negotiation has failed or 0 if there isn't enough data and you should try again (only for non-blocking sockets).</returns>
public static PhpValue /*int|bool*/ stream_socket_enable_crypto(PhpResource stream, bool enable)
{
var s = SocketStream.GetValid(stream);
if (s != null)
{
// obtain crypto_method option
var crypto_method = default(CryptoMethod);
if (enable)
{
var ssl_options = s.Context.GetOptions("ssl");
if (ssl_options != null && ssl_options.TryGetValue("crypto_method", out var crypto_method_value))
{
crypto_method = (CryptoMethod)crypto_method_value.ToLong();
}
else
{
PhpException.InvalidArgument(nameof(crypto_method)); // 'crypto_method' must be specified when enabling encryption
return(false);
}
}
return(stream_socket_enable_crypto(s, enable, crypto_method, null));
}
//
return(false);
}