mono/mono — pull request #1399 by mythz (2014-11-11 18:13:31+00:00)
Title: Add missing System.Net.EncryptionPolicy enum and SslStream constructor

Add implementation of the [missing SslStream constructor](http://msdn.microsoft.com/en-us/library/dd990420(v=vs.110).aspx), e.g:

```csharp
sslStream = new SslStream(networkStream,
leaveInnerStreamOpen: false,
userCertificateValidationCallback: null,
userCertificateSelectionCallback: null,
encryptionPolicy: EncryptionPolicy.RequireEncryption);
```

which currently fails to build on Mono or run (when built with .NET) with:

```
Unhandled Exception: System.TypeLoadException: Could not load type 'System.Net.Security.EncryptionPolicy' from assembly 'System.dll, Version=4.0.0.0
```

Currently I'm resorting to this hack to support both .NET and Mono:

```csharp
if (Env.IsMono)
{
//Mono doesn't support EncryptionPolicy
sslStream = new SslStream(networkStream,
leaveInnerStreamOpen: false,
userCertificateValidationCallback: CertificateValidationCallback,
userCertificateSelectionCallback: CertificateSelectionCallback);
}
else
{
var ctor = typeof(SslStream).GetConstructors()
.First(x => x.GetParameters().Length == 5);

var policyType = AssemblyUtils.FindType("System.Net.Security.EncryptionPolicy");
var policyValue = Enum.Parse(policyType, "RequireEncryption");

sslStream = (SslStream)ctor.Invoke(new [] {
networkStream,
false,
CertificateValidationCallback,
CertificateSelectionCallback,
policyValue,
});
}
```

Which I prefer to avoid since the most common path in .NET has to resort to reflection in order to get it running in Mono as well.

## TODO Verify behavior

Currently the default constructor impl only allows `EncryptionPolicy.AllowNoEncryption`, e.g:

```csharp
if (encryptionPolicy != EncryptionPolicy.AllowNoEncryption)
throw new NotImplementedException();
```

But depending on the behavior of `SslStream` it may also be able to support `EncryptionPolicy. RequireEncryption`, hopefully someone familiar with this will know.