| | | 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 System; |
| | | 5 | | using System.ComponentModel; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Security |
| | | 8 | | { |
| | | 9 | | public enum SecurityTokenAttachmentMode |
| | | 10 | | { |
| | | 11 | | Signed, |
| | | 12 | | Endorsing, |
| | | 13 | | SignedEndorsing, |
| | | 14 | | SignedEncrypted |
| | | 15 | | } |
| | | 16 | | |
| | | 17 | | internal static class SecurityTokenAttachmentModeHelper |
| | | 18 | | { |
| | | 19 | | internal static bool IsDefined(SecurityTokenAttachmentMode value) |
| | | 20 | | { |
| | 192 | 21 | | return value == SecurityTokenAttachmentMode.Endorsing |
| | 192 | 22 | | || value == SecurityTokenAttachmentMode.Signed |
| | 192 | 23 | | || value == SecurityTokenAttachmentMode.SignedEncrypted |
| | 192 | 24 | | || value == SecurityTokenAttachmentMode.SignedEndorsing; |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | internal static void Validate(SecurityTokenAttachmentMode value) |
| | | 28 | | { |
| | 192 | 29 | | if (!IsDefined(value)) |
| | | 30 | | { |
| | 0 | 31 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnumArgumentException(nameof(value) |
| | 0 | 32 | | typeof(SecurityTokenAttachmentMode))); |
| | | 33 | | } |
| | 192 | 34 | | } |
| | | 35 | | |
| | | 36 | | internal static void Categorize(SecurityTokenAttachmentMode value, |
| | | 37 | | out bool isBasic, out bool isSignedButNotBasic, out ReceiveSecurityHeaderBindingModes mode) |
| | | 38 | | { |
| | 64 | 39 | | Validate(value); |
| | | 40 | | |
| | | 41 | | switch (value) |
| | | 42 | | { |
| | | 43 | | case SecurityTokenAttachmentMode.Endorsing: |
| | 23 | 44 | | isBasic = false; |
| | 23 | 45 | | isSignedButNotBasic = false; |
| | 23 | 46 | | mode = ReceiveSecurityHeaderBindingModes.Endorsing; |
| | 23 | 47 | | break; |
| | | 48 | | case SecurityTokenAttachmentMode.Signed: |
| | 28 | 49 | | isBasic = false; |
| | 28 | 50 | | isSignedButNotBasic = true; |
| | 28 | 51 | | mode = ReceiveSecurityHeaderBindingModes.Signed; |
| | 28 | 52 | | break; |
| | | 53 | | case SecurityTokenAttachmentMode.SignedEncrypted: |
| | 13 | 54 | | isBasic = true; |
| | 13 | 55 | | isSignedButNotBasic = false; |
| | 13 | 56 | | mode = ReceiveSecurityHeaderBindingModes.Basic; |
| | 13 | 57 | | break; |
| | | 58 | | case SecurityTokenAttachmentMode.SignedEndorsing: |
| | 0 | 59 | | isBasic = false; |
| | 0 | 60 | | isSignedButNotBasic = true; |
| | 0 | 61 | | mode = ReceiveSecurityHeaderBindingModes.SignedEndorsing; |
| | 0 | 62 | | break; |
| | | 63 | | default: |
| | 0 | 64 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 65 | | } |
| | | 66 | | } |
| | | 67 | | } |
| | | 68 | | } |