public static XmlAttributeHolder[] ReadAttributes(XmlDictionaryReader reader, ref int maxSizeOfHeaders)
 {
     if (reader.AttributeCount == 0)
     {
         return emptyArray;
     }
     XmlAttributeHolder[] holderArray = new XmlAttributeHolder[reader.AttributeCount];
     reader.MoveToFirstAttribute();
     for (int i = 0; i < holderArray.Length; i++)
     {
         string namespaceURI = reader.NamespaceURI;
         string localName = reader.LocalName;
         string prefix = reader.Prefix;
         string s = string.Empty;
         while (reader.ReadAttributeValue())
         {
             if (s.Length == 0)
             {
                 s = reader.Value;
             }
             else
             {
                 s = s + reader.Value;
             }
         }
         Deduct(prefix, ref maxSizeOfHeaders);
         Deduct(localName, ref maxSizeOfHeaders);
         Deduct(namespaceURI, ref maxSizeOfHeaders);
         Deduct(s, ref maxSizeOfHeaders);
         holderArray[i] = new XmlAttributeHolder(prefix, localName, namespaceURI, s);
         reader.MoveToNextAttribute();
     }
     reader.MoveToElement();
     return holderArray;
 }
 internal static XmlDictionaryReader CreateSplicedReader(byte[] decryptedBuffer, XmlAttributeHolder[] outerContext1, XmlAttributeHolder[] outerContext2, XmlAttributeHolder[] outerContext3, XmlDictionaryReaderQuotas quotas)
 {
     MemoryStream stream = new MemoryStream();
     XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(stream);
     writer.WriteStartElement("x");
     WriteNamespaceDeclarations(outerContext1, writer);
     writer.WriteStartElement("y");
     WriteNamespaceDeclarations(outerContext2, writer);
     writer.WriteStartElement("z");
     WriteNamespaceDeclarations(outerContext3, writer);
     writer.WriteString(" ");
     writer.WriteEndElement();
     writer.WriteEndElement();
     writer.WriteEndElement();
     writer.Flush();
     XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(SpliceBuffers(decryptedBuffer, stream.GetBuffer(), (int) stream.Length, 3), quotas);
     reader.ReadStartElement("x");
     reader.ReadStartElement("y");
     reader.ReadStartElement("z");
     if (reader.NodeType != XmlNodeType.Element)
     {
         reader.MoveToContent();
     }
     return reader;
 }
 public static void WriteAttributes(XmlAttributeHolder[] attributes, XmlWriter writer)
 {
     for (int i = 0; i < attributes.Length; i++)
     {
         attributes[i].WriteTo(writer);
     }
 }
 public BufferedHeader(MessageVersion version, XmlBuffer buffer, XmlDictionaryReader reader, XmlAttributeHolder[] envelopeAttributes, XmlAttributeHolder[] headerAttributes)
 {
     this.streamed = true;
     this.buffer = buffer;
     this.version = version;
     MessageHeader.GetHeaderAttributes(reader, version, out this.actor, out this.mustUnderstand, out this.relay, out this.isRefParam);
     this.name = reader.LocalName;
     this.ns = reader.NamespaceURI;
     this.bufferIndex = buffer.SectionCount;
     XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);
     writer.WriteStartElement("Envelope");
     if (envelopeAttributes != null)
     {
         XmlAttributeHolder.WriteAttributes(envelopeAttributes, writer);
     }
     writer.WriteStartElement("Header");
     if (headerAttributes != null)
     {
         XmlAttributeHolder.WriteAttributes(headerAttributes, writer);
     }
     writer.WriteNode(reader, false);
     writer.WriteEndElement();
     writer.WriteEndElement();
     buffer.CloseSection();
 }
 private static void WriteNamespaceDeclarations(XmlAttributeHolder[] attributes, XmlWriter writer)
 {
     if (attributes != null)
     {
         for (int i = 0; i < attributes.Length; i++)
         {
             XmlAttributeHolder holder = attributes[i];
             if (IsNamespaceDeclaration(holder.Prefix, holder.LocalName))
             {
                 holder.WriteTo(writer);
             }
         }
     }
 }
        public DecryptedHeader(byte[] decryptedBuffer,
            XmlAttributeHolder[] envelopeAttributes, XmlAttributeHolder[] headerAttributes,
            MessageVersion version, SignatureTargetIdManager idManager, XmlDictionaryReaderQuotas quotas)
        {
            if (quotas == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("quotas");

            this.decryptedBuffer = decryptedBuffer;
            this.version = version;
            this.envelopeAttributes = envelopeAttributes;
            this.headerAttributes = headerAttributes;
            this.quotas = quotas;

            XmlDictionaryReader reader = CreateReader();
            reader.MoveToStartElement();

            this.name = reader.LocalName;
            this.namespaceUri = reader.NamespaceURI;
            MessageHeader.GetHeaderAttributes(reader, version, out this.actor, out this.mustUnderstand, out this.relay, out this.isRefParam);
            this.id = idManager.ExtractId(reader);

            this.cachedReader = reader;
        }
        internal static XmlDictionaryReader CreateSplicedReader(byte[] decryptedBuffer,
            XmlAttributeHolder[] outerContext1, XmlAttributeHolder[] outerContext2, XmlAttributeHolder[] outerContext3, XmlDictionaryReaderQuotas quotas)
        {
            const string wrapper1 = "x";
            const string wrapper2 = "y";
            const string wrapper3 = "z";
            const int wrappingDepth = 3;

            MemoryStream stream = new MemoryStream();
            XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(stream);
            writer.WriteStartElement(wrapper1);
            WriteNamespaceDeclarations(outerContext1, writer);
            writer.WriteStartElement(wrapper2);
            WriteNamespaceDeclarations(outerContext2, writer);
            writer.WriteStartElement(wrapper3);
            WriteNamespaceDeclarations(outerContext3, writer);
            writer.WriteString(" "); // ensure non-empty element
            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.Flush();

            byte[] splicedBuffer = SpliceBuffers(decryptedBuffer, stream.GetBuffer(), (int) stream.Length, wrappingDepth);
            XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(splicedBuffer, quotas);
            reader.ReadStartElement(wrapper1);
            reader.ReadStartElement(wrapper2);
            reader.ReadStartElement(wrapper3);
            if (reader.NodeType != XmlNodeType.Element)
            {
                reader.MoveToContent();
            }
            return reader;
        }
 public static string GetAttribute(XmlAttributeHolder[] attributes, string localName, string ns)
 {
     for (int i = 0; i < attributes.Length; i++)
     {
         if ((attributes[i].LocalName == localName) && (attributes[i].NamespaceUri == ns))
         {
             return attributes[i].Value;
         }
     }
     return null;
 }
        public BufferedHeader(MessageVersion version, XmlBuffer buffer, XmlDictionaryReader reader, XmlAttributeHolder[] envelopeAttributes, XmlAttributeHolder[] headerAttributes)
        {
            _streamed = true;
            _buffer = buffer;
            _version = version;
            GetHeaderAttributes(reader, version, out _actor, out _mustUnderstand, out _relay, out _isRefParam);
            _name = reader.LocalName;
            _ns = reader.NamespaceURI;
            Fx.Assert(_name != null, "");
            Fx.Assert(_ns != null, "");
            _bufferIndex = buffer.SectionCount;
            XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);

            // Write an enclosing Envelope tag
            writer.WriteStartElement(MessageStrings.Envelope);
            if (envelopeAttributes != null)
                XmlAttributeHolder.WriteAttributes(envelopeAttributes, writer);

            // Write and enclosing Header tag
            writer.WriteStartElement(MessageStrings.Header);
            if (headerAttributes != null)
                XmlAttributeHolder.WriteAttributes(headerAttributes, writer);

            writer.WriteNode(reader, false);

            writer.WriteEndElement();
            writer.WriteEndElement();

            buffer.CloseSection();
        }