SecurityTokenAttachmentMode.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Security
  5. {
  6. using System.ComponentModel;
  7. public enum SecurityTokenAttachmentMode
  8. {
  9. Signed,
  10. Endorsing,
  11. SignedEndorsing,
  12. SignedEncrypted
  13. }
  14. static class SecurityTokenAttachmentModeHelper
  15. {
  16. internal static bool IsDefined(SecurityTokenAttachmentMode value)
  17. {
  18. return value == SecurityTokenAttachmentMode.Endorsing
  19. || value == SecurityTokenAttachmentMode.Signed
  20. || value == SecurityTokenAttachmentMode.SignedEncrypted
  21. || value == SecurityTokenAttachmentMode.SignedEndorsing;
  22. }
  23. internal static void Validate(SecurityTokenAttachmentMode value)
  24. {
  25. if (!IsDefined(value))
  26. {
  27. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnumArgumentException("value", (int)value,
  28. typeof(SecurityTokenAttachmentMode)));
  29. }
  30. }
  31. internal static void Categorize(SecurityTokenAttachmentMode value,
  32. out bool isBasic, out bool isSignedButNotBasic, out ReceiveSecurityHeaderBindingModes mode)
  33. {
  34. SecurityTokenAttachmentModeHelper.Validate(value);
  35. switch (value)
  36. {
  37. case SecurityTokenAttachmentMode.Endorsing:
  38. isBasic = false;
  39. isSignedButNotBasic = false;
  40. mode = ReceiveSecurityHeaderBindingModes.Endorsing;
  41. break;
  42. case SecurityTokenAttachmentMode.Signed:
  43. isBasic = false;
  44. isSignedButNotBasic = true;
  45. mode = ReceiveSecurityHeaderBindingModes.Signed;
  46. break;
  47. case SecurityTokenAttachmentMode.SignedEncrypted:
  48. isBasic = true;
  49. isSignedButNotBasic = false;
  50. mode = ReceiveSecurityHeaderBindingModes.Basic;
  51. break;
  52. case SecurityTokenAttachmentMode.SignedEndorsing:
  53. isBasic = false;
  54. isSignedButNotBasic = true;
  55. mode = ReceiveSecurityHeaderBindingModes.SignedEndorsing;
  56. break;
  57. default:
  58. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
  59. }
  60. }
  61. }
  62. }