DecryptedHeader.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Security
  5. {
  6. using System.Xml;
  7. using System.ServiceModel.Channels;
  8. using System.ServiceModel;
  9. sealed class DecryptedHeader : ReadableMessageHeader
  10. {
  11. XmlDictionaryReader cachedReader;
  12. readonly byte[] decryptedBuffer;
  13. readonly string id;
  14. readonly string name;
  15. readonly string namespaceUri;
  16. readonly string actor;
  17. readonly bool mustUnderstand;
  18. readonly bool relay;
  19. readonly bool isRefParam;
  20. readonly MessageVersion version;
  21. readonly XmlAttributeHolder[] envelopeAttributes;
  22. readonly XmlAttributeHolder[] headerAttributes;
  23. readonly XmlDictionaryReaderQuotas quotas;
  24. public DecryptedHeader(byte[] decryptedBuffer,
  25. XmlAttributeHolder[] envelopeAttributes, XmlAttributeHolder[] headerAttributes,
  26. MessageVersion version, SignatureTargetIdManager idManager, XmlDictionaryReaderQuotas quotas)
  27. {
  28. if (quotas == null)
  29. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("quotas");
  30. this.decryptedBuffer = decryptedBuffer;
  31. this.version = version;
  32. this.envelopeAttributes = envelopeAttributes;
  33. this.headerAttributes = headerAttributes;
  34. this.quotas = quotas;
  35. XmlDictionaryReader reader = CreateReader();
  36. reader.MoveToStartElement();
  37. this.name = reader.LocalName;
  38. this.namespaceUri = reader.NamespaceURI;
  39. MessageHeader.GetHeaderAttributes(reader, version, out this.actor, out this.mustUnderstand, out this.relay, out this.isRefParam);
  40. this.id = idManager.ExtractId(reader);
  41. this.cachedReader = reader;
  42. }
  43. public override string Actor
  44. {
  45. get
  46. {
  47. return this.actor;
  48. }
  49. }
  50. public string Id
  51. {
  52. get
  53. {
  54. return this.id;
  55. }
  56. }
  57. public override bool IsReferenceParameter
  58. {
  59. get
  60. {
  61. return this.isRefParam;
  62. }
  63. }
  64. public override bool MustUnderstand
  65. {
  66. get
  67. {
  68. return this.mustUnderstand;
  69. }
  70. }
  71. public override string Name
  72. {
  73. get
  74. {
  75. return this.name;
  76. }
  77. }
  78. public override string Namespace
  79. {
  80. get
  81. {
  82. return this.namespaceUri;
  83. }
  84. }
  85. public override bool Relay
  86. {
  87. get
  88. {
  89. return this.relay;
  90. }
  91. }
  92. XmlDictionaryReader CreateReader()
  93. {
  94. return ContextImportHelper.CreateSplicedReader(
  95. this.decryptedBuffer,
  96. this.envelopeAttributes,
  97. this.headerAttributes, null, this.quotas);
  98. }
  99. public override XmlDictionaryReader GetHeaderReader()
  100. {
  101. if (this.cachedReader != null)
  102. {
  103. XmlDictionaryReader cachedReader = this.cachedReader;
  104. this.cachedReader = null;
  105. return cachedReader;
  106. }
  107. XmlDictionaryReader reader = CreateReader();
  108. reader.MoveToContent();
  109. return reader;
  110. }
  111. public override bool IsMessageVersionSupported(MessageVersion messageVersion)
  112. {
  113. return this.version.Equals( messageVersion );
  114. }
  115. }
  116. }