/
NetNamedPipeSecurity.cs
65 lines (58 loc) · 2 KB
/
NetNamedPipeSecurity.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.ServiceModel.Channels;
namespace System.ServiceModel
{
[SupportedOSPlatform("windows")]
public sealed class NetNamedPipeSecurity
{
internal const NetNamedPipeSecurityMode DefaultMode = NetNamedPipeSecurityMode.Transport;
private NetNamedPipeSecurityMode _mode;
private NamedPipeTransportSecurity _transport = new NamedPipeTransportSecurity();
public NetNamedPipeSecurity()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
throw ExceptionHelper.PlatformNotSupported(SR.Format(SR.PlatformNotSupported_NetNamedPipe));
}
_mode = DefaultMode;
}
[DefaultValue(DefaultMode)]
public NetNamedPipeSecurityMode Mode
{
get { return _mode; }
set
{
if (!NetNamedPipeSecurityModeHelper.IsDefined(value))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
}
_mode = value;
}
}
public NamedPipeTransportSecurity Transport
{
get { return _transport; }
set
{
if (value == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
_transport = value;
}
}
internal WindowsStreamSecurityBindingElement CreateTransportSecurity()
{
if (_mode == NetNamedPipeSecurityMode.Transport)
{
return _transport.CreateTransportProtectionAndAuthentication();
}
else
{
return null;
}
}
}
}