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