Esempio n. 1
0
        public BufferedHeader(MessageVersion version, XmlBuffer buffer, XmlDictionaryReader reader, XmlAttributeHolder[] envelopeAttributes, XmlAttributeHolder[] headerAttributes)
        {
            streamed     = true;
            this.buffer  = buffer;
            this.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();
        }
Esempio n. 2
0
        protected virtual XmlDictionaryReader OnGetReaderAtBodyContents()
        {
            XmlBuffer           buffer = new XmlBuffer(0x7fffffff);
            XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            if (this.Version.Envelope != EnvelopeVersion.None)
            {
                this.OnWriteStartEnvelope(writer);
                this.OnWriteStartBody(writer);
            }
            this.OnWriteBodyContents(writer);
            if (this.Version.Envelope != EnvelopeVersion.None)
            {
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            buffer.CloseSection();
            buffer.Close();
            XmlDictionaryReader reader = buffer.GetReader(0);

            if (this.Version.Envelope != EnvelopeVersion.None)
            {
                reader.ReadStartElement();
                reader.ReadStartElement();
            }
            reader.MoveToContent();
            return(reader);
        }
 public SecurityVerifiedMessage(Message messageToProcess, ReceiveSecurityHeader securityHeader)
     : base(messageToProcess)
 {
     ReceivedSecurityHeader = securityHeader;
     if (securityHeader.RequireMessageProtection)
     {
         XmlDictionaryReader messageReader;
         BufferedMessage     bufferedMessage = InnerMessage as BufferedMessage;
         if (bufferedMessage != null && Headers.ContainsOnlyBufferedMessageHeaders)
         {
             messageReader = bufferedMessage.GetMessageReader();
         }
         else
         {
             _messageBuffer = new XmlBuffer(int.MaxValue);
             XmlDictionaryWriter writer = _messageBuffer.OpenSection(ReceivedSecurityHeader.ReaderQuotas);
             InnerMessage.WriteMessage(writer);
             _messageBuffer.CloseSection();
             _messageBuffer.Close();
             messageReader = _messageBuffer.GetReader(0);
         }
         MoveToSecurityHeader(messageReader, securityHeader.HeaderIndex, true);
         _cachedReaderAtSecurityHeader = messageReader;
         _state = BodyState.Buffered;
     }
     else
     {
         _envelopeAttributes = XmlAttributeHolder.emptyArray;
         _headerAttributes   = XmlAttributeHolder.emptyArray;
         _bodyAttributes     = XmlAttributeHolder.emptyArray;
         _canDelegateCreateBufferedCopyToInnerMessage = true;
     }
 }
Esempio n. 4
0
        public static ReceivedFault CreateFault11(XmlDictionaryReader reader, int maxBufferSize)
        {
            string str;
            string str2;

            reader.ReadStartElement(XD.MessageDictionary.Fault, XD.Message11Dictionary.Namespace);
            reader.ReadStartElement(XD.Message11Dictionary.FaultCode, XD.Message11Dictionary.FaultNamespace);
            XmlUtil.ReadContentAsQName(reader, out str2, out str);
            FaultCode code = new FaultCode(str2, str);

            reader.ReadEndElement();
            string xmlLang = reader.XmlLang;

            reader.MoveToContent();
            FaultReasonText translation = new FaultReasonText(reader.ReadElementContentAsString(XD.Message11Dictionary.FaultString.Value, XD.Message11Dictionary.FaultNamespace.Value), xmlLang);
            string          actor       = "";

            if (reader.IsStartElement(XD.Message11Dictionary.FaultActor, XD.Message11Dictionary.FaultNamespace))
            {
                actor = reader.ReadElementContentAsString();
            }
            XmlBuffer detail = null;

            if (reader.IsStartElement(XD.Message11Dictionary.FaultDetail, XD.Message11Dictionary.FaultNamespace))
            {
                detail = new XmlBuffer(maxBufferSize);
                detail.OpenSection(reader.Quotas).WriteNode(reader, false);
                detail.CloseSection();
                detail.Close();
            }
            reader.ReadEndElement();
            return(new ReceivedFault(code, new FaultReason(translation), actor, actor, detail, EnvelopeVersion.Soap11));
        }
 // Saves the element in the reader to the buffer (attributes preserved)
 // Type is populated from type attribute on reader
 // Reader must be positioned at an element
 public XmlSyndicationContent(XmlReader reader)
 {
     if (reader == null)
     {
         throw new ArgumentNullException(nameof(reader));
     }
     SyndicationFeedFormatter.MoveToStartElement(reader);
     if (reader.HasAttributes)
     {
         while (reader.MoveToNextAttribute())
         {
             string name  = reader.LocalName;
             string ns    = reader.NamespaceURI;
             string value = reader.Value;
             if (name == Atom10Constants.TypeTag && ns == string.Empty)
             {
                 _type = value;
             }
             else if (!FeedUtils.IsXmlns(name, ns))
             {
                 base.AttributeExtensions.Add(new XmlQualifiedName(name, ns), value);
             }
         }
         reader.MoveToElement();
     }
     _type          = string.IsNullOrEmpty(_type) ? Atom10Constants.XmlMediaType : _type;
     _contentBuffer = new XmlBuffer(int.MaxValue);
     using (XmlDictionaryWriter writer = _contentBuffer.OpenSection(XmlDictionaryReaderQuotas.Max))
     {
         writer.WriteNode(reader, false);
     }
     _contentBuffer.CloseSection();
     _contentBuffer.Close();
 }
Esempio n. 6
0
 internal static void CloseBuffer(XmlBuffer buffer, XmlDictionaryWriter extWriter)
 {
     if (buffer != null)
     {
         extWriter.WriteEndElement();
         buffer.CloseSection();
         buffer.Close();
     }
 }
Esempio n. 7
0
        internal MessageBuffer OnCreateBufferedCopy(int maxBufferSize, XmlDictionaryReaderQuotas quotas)
        {
            XmlBuffer           msgBuffer = new XmlBuffer(maxBufferSize);
            XmlDictionaryWriter writer    = msgBuffer.OpenSection(quotas);

            this.OnWriteMessage(writer);
            msgBuffer.CloseSection();
            msgBuffer.Close();
            return(new DefaultMessageBuffer(this, msgBuffer));
        }
Esempio n. 8
0
        public virtual XmlDictionaryReader GetAddressHeaderReader()
        {
            XmlBuffer           buffer = new XmlBuffer(int.MaxValue);
            XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            WriteAddressHeader(writer);
            buffer.CloseSection();
            buffer.Close();
            return(buffer.GetReader(0));
        }
        private XmlDictionaryReader GetComparableReader()
        {
            XmlBuffer           buffer = new XmlBuffer(0x7fffffff);
            XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            ParameterHeader.WriteStartHeader(writer, this, AddressingVersion.WSAddressingAugust2004);
            ParameterHeader.WriteHeaderContents(writer, this);
            writer.WriteEndElement();
            buffer.CloseSection();
            buffer.Close();
            return(buffer.GetReader(0));
        }
Esempio n. 10
0
        private static ReceivedFault CreateFault12Driver(XmlDictionaryReader reader, int maxBufferSize, EnvelopeVersion version)
        {
            reader.ReadStartElement(XD.MessageDictionary.Fault, version.DictionaryNamespace);
            reader.ReadStartElement(XD.Message12Dictionary.FaultCode, version.DictionaryNamespace);
            FaultCode code = ReadFaultCode12Driver(reader, version);

            reader.ReadEndElement();
            List <FaultReasonText> translations = new List <FaultReasonText>();

            if (reader.IsEmptyElement)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.AtLeastOneFaultReasonMustBeSpecified));
            }
            else
            {
                reader.ReadStartElement(XD.Message12Dictionary.FaultReason, version.DictionaryNamespace);
                while (reader.IsStartElement(XD.Message12Dictionary.FaultText, version.DictionaryNamespace))
                {
                    translations.Add(ReadTranslation12(reader));
                }

                reader.ReadEndElement();
            }

            string actor = "";
            string node  = "";

            if (reader.IsStartElement(XD.Message12Dictionary.FaultNode, version.DictionaryNamespace))
            {
                node = reader.ReadElementContentAsString();
            }

            if (reader.IsStartElement(XD.Message12Dictionary.FaultRole, version.DictionaryNamespace))
            {
                actor = reader.ReadElementContentAsString();
            }

            XmlBuffer detail = null;

            if (reader.IsStartElement(XD.Message12Dictionary.FaultDetail, version.DictionaryNamespace))
            {
                detail = new XmlBuffer(maxBufferSize);
                XmlDictionaryWriter writer = detail.OpenSection(reader.Quotas);
                writer.WriteNode(reader, false);
                detail.CloseSection();
                detail.Close();
            }
            reader.ReadEndElement();
            FaultReason reason = new FaultReason(translations);

            return(new ReceivedFault(code, reason, actor, node, detail, version));
        }
Esempio n. 11
0
        protected virtual XmlDictionaryReader OnGetReaderAtDetailContents()
        {
            XmlBuffer           detailBuffer = new XmlBuffer(int.MaxValue);
            XmlDictionaryWriter writer       = detailBuffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            OnWriteDetail(writer, EnvelopeVersion.Soap12);  // Wrap in soap 1.2 by default
            detailBuffer.CloseSection();
            detailBuffer.Close();
            XmlDictionaryReader reader = detailBuffer.GetReader(0);

            reader.Read(); // Skip the detail element
            return(reader);
        }
Esempio n. 12
0
 internal BodyWriter OnCreateBufferedCopy(int maxBufferSize, XmlDictionaryReaderQuotas quotas)
 {
     XmlBuffer buffer = new XmlBuffer(maxBufferSize);
     using (XmlDictionaryWriter writer = buffer.OpenSection(quotas))
     {
         writer.WriteStartElement("a");
         OnWriteBodyContents(writer);
         writer.WriteEndElement();
     }
     buffer.CloseSection();
     buffer.Close();
     return new BufferedBodyWriter(buffer);
 }
        protected virtual XmlDictionaryReader OnGetReaderAtDetailContents()
        {
            XmlBuffer           buffer = new XmlBuffer(0x7fffffff);
            XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            this.OnWriteDetail(writer, EnvelopeVersion.Soap12);
            buffer.CloseSection();
            buffer.Close();
            XmlDictionaryReader reader = buffer.GetReader(0);

            reader.Read();
            return(reader);
        }
Esempio n. 14
0
        public static XmlDictionaryReader GetReaderAtDetailContentsFeb2005(string detailName, string detailNamespace, XmlDictionaryReader headerReader)
        {
            XmlDictionaryReader reader;

            try
            {
                WsrmFeb2005Dictionary dictionary   = XD.WsrmFeb2005Dictionary;
                XmlDictionaryString   namespaceUri = dictionary.Namespace;
                XmlBuffer             buffer       = null;
                int sectionIndex = 0;
                int depth        = headerReader.Depth;
                headerReader.ReadFullStartElement(dictionary.SequenceFault, namespaceUri);
                while (headerReader.Depth > depth)
                {
                    if (((headerReader.NodeType == XmlNodeType.Element) && (headerReader.NamespaceURI == detailNamespace)) && (headerReader.LocalName == detailName))
                    {
                        if (buffer != null)
                        {
                            return(null);
                        }
                        buffer = new XmlBuffer(0x7fffffff);
                        try
                        {
                            sectionIndex = buffer.SectionCount;
                            buffer.OpenSection(headerReader.Quotas).WriteNode(headerReader, false);
                            continue;
                        }
                        finally
                        {
                            buffer.CloseSection();
                        }
                    }
                    if (headerReader.Depth == depth)
                    {
                        break;
                    }
                    headerReader.Read();
                }
                if (buffer == null)
                {
                    return(null);
                }
                buffer.Close();
                reader = buffer.GetReader(sectionIndex);
            }
            finally
            {
                headerReader.Close();
            }
            return(reader);
        }
 private void EnsureContentBuffer()
 {
     if (this.contentBuffer == null)
     {
         XmlBuffer buffer = new XmlBuffer(0x7fffffff);
         using (XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max))
         {
             base.WriteTo(writer, "content", "http://www.w3.org/2005/Atom");
         }
         buffer.CloseSection();
         buffer.Close();
         this.contentBuffer = buffer;
     }
 }
Esempio n. 16
0
 private async Task EnsureContentBufferAsync()
 {
     if (_contentBuffer == null)
     {
         XmlBuffer tmp = new XmlBuffer(int.MaxValue);
         using (XmlDictionaryWriter writer = tmp.OpenSection(XmlDictionaryReaderQuotas.Max))
         {
             await WriteToAsync(writer, Atom10Constants.ContentTag, Atom10Constants.Atom10Namespace).ConfigureAwait(false);
         }
         tmp.CloseSection();
         tmp.Close();
         _contentBuffer = tmp;
     }
 }
Esempio n. 17
0
        internal BodyWriter OnCreateBufferedCopy(int maxBufferSize, XmlDictionaryReaderQuotas quotas)
        {
            XmlBuffer buffer = new XmlBuffer(maxBufferSize);

            using (XmlDictionaryWriter writer = buffer.OpenSection(quotas))
            {
                writer.WriteStartElement("a");
                OnWriteBodyContents(writer);
                writer.WriteEndElement();
            }
            buffer.CloseSection();
            buffer.Close();
            return(new BufferedBodyWriter(buffer));
        }
Esempio n. 18
0
 private void EnsureContentBuffer()
 {
     if (_contentBuffer == null)
     {
         XmlBuffer tmp = new XmlBuffer(int.MaxValue);
         using (XmlDictionaryWriter writer = tmp.OpenSection(XmlDictionaryReaderQuotas.Max))
         {
             this.WriteTo(writer, Atom10Constants.ContentTag, Atom10Constants.Atom10Namespace);
         }
         tmp.CloseSection();
         tmp.Close();
         _contentBuffer = tmp;
     }
 }
Esempio n. 19
0
        XmlDictionaryReader GetComparableReader()
        {
            XmlBuffer           buffer = new XmlBuffer(int.MaxValue);
            XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            // WSAddressingAugust2004 does not write the IsReferenceParameter attribute,
            // and that's good for a consistent comparable form
            ParameterHeader.WriteStartHeader(writer, this, AddressingVersion.WSAddressingAugust2004);
            ParameterHeader.WriteHeaderContents(writer, this);
            writer.WriteEndElement();
            buffer.CloseSection();
            buffer.Close();
            return(buffer.GetReader(0));
        }
Esempio n. 20
0
        public BufferedAddressHeader(XmlDictionaryReader reader)
        {
            buffer = new XmlBuffer(int.MaxValue);
            XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);

            Fx.Assert(reader.NodeType == XmlNodeType.Element, "");
            name = reader.LocalName;
            ns   = reader.NamespaceURI;
            Fx.Assert(name != null, "");
            Fx.Assert(ns != null, "");
            writer.WriteNode(reader, false);
            buffer.CloseSection();
            buffer.Close();
            isReferenceProperty = false;
        }
 private void EnsureBuffer()
 {
     if (_buffer == null)
     {
         _buffer = new XmlBuffer(int.MaxValue);
         using (XmlDictionaryWriter writer = _buffer.OpenSection(XmlDictionaryReaderQuotas.Max))
         {
             writer.WriteStartElement(Rss20Constants.ExtensionWrapperTag);
             WriteTo(writer);
             writer.WriteEndElement();
         }
         _buffer.CloseSection();
         _buffer.Close();
         _bufferElementIndex = 0;
     }
 }
 static XmlBuffer CreateXmlBuffer(XmlDictionaryReader unparsedExtensionsReader, int maxExtensionSize)
 {
     XmlBuffer buffer = new XmlBuffer(maxExtensionSize);
     using (XmlDictionaryWriter writer = buffer.OpenSection(unparsedExtensionsReader.Quotas))
     {
         writer.WriteStartElement(Rss20Constants.ExtensionWrapperTag);
         while (unparsedExtensionsReader.IsStartElement())
         {
             writer.WriteNode(unparsedExtensionsReader, false);
         }
         writer.WriteEndElement();
     }
     buffer.CloseSection();
     buffer.Close();
     return buffer;
 }
Esempio n. 23
0
        public void WriteBodyToSign(Stream canonicalStream)
        {
            SetBodyId();

            _fullBodyBuffer = new XmlBuffer(int.MaxValue);
            XmlDictionaryWriter canonicalWriter = _fullBodyBuffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            canonicalWriter.StartCanonicalization(canonicalStream, false, null);
            WriteInnerMessageWithId(canonicalWriter);
            canonicalWriter.EndCanonicalization();
            canonicalWriter.Flush();
            _fullBodyBuffer.CloseSection();
            _fullBodyBuffer.Close();

            _state = BodyState.Signed;
        }
        static XmlBuffer CreateXmlBuffer(XmlDictionaryReader unparsedExtensionsReader, int maxExtensionSize)
        {
            XmlBuffer buffer = new XmlBuffer(maxExtensionSize);

            using (XmlDictionaryWriter writer = buffer.OpenSection(unparsedExtensionsReader.Quotas))
            {
                writer.WriteStartElement(Rss20Constants.ExtensionWrapperTag);
                while (unparsedExtensionsReader.IsStartElement())
                {
                    writer.WriteNode(unparsedExtensionsReader, false);
                }
                writer.WriteEndElement();
            }
            buffer.CloseSection();
            buffer.Close();
            return(buffer);
        }
 public SyndicationElementExtension(XmlReader xmlReader)
 {
     if (xmlReader == null)
     {
         throw new ArgumentNullException(nameof(xmlReader));
     }
     SyndicationFeedFormatter.MoveToStartElement(xmlReader);
     _outerName      = xmlReader.LocalName;
     _outerNamespace = xmlReader.NamespaceURI;
     _buffer         = new XmlBuffer(int.MaxValue);
     using (XmlDictionaryWriter writer = _buffer.OpenSection(XmlDictionaryReaderQuotas.Max))
     {
         writer.WriteStartElement(Rss20Constants.ExtensionWrapperTag);
         writer.WriteNode(xmlReader, false);
         writer.WriteEndElement();
     }
     _buffer.CloseSection();
     _buffer.Close();
     _bufferElementIndex = 0;
 }
Esempio n. 26
0
 public SyndicationElementExtension(XmlReader xmlReader)
 {
     if (xmlReader == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xmlReader");
     }
     SyndicationFeedFormatter.MoveToStartElement(xmlReader);
     this.outerName      = xmlReader.LocalName;
     this.outerNamespace = xmlReader.NamespaceURI;
     this.buffer         = new XmlBuffer(int.MaxValue);
     using (XmlDictionaryWriter writer = this.buffer.OpenSection(XmlDictionaryReaderQuotas.Max))
     {
         writer.WriteStartElement(Rss20Constants.ExtensionWrapperTag);
         writer.WriteNode(xmlReader, false);
         writer.WriteEndElement();
     }
     buffer.CloseSection();
     buffer.Close();
     this.bufferElementIndex = 0;
 }
Esempio n. 27
0
        public static ReceivedFault CreateFault11(XmlDictionaryReader reader, int maxBufferSize)
        {
            reader.ReadStartElement(XD.MessageDictionary.Fault, XD.Message11Dictionary.Namespace);
            string ns;
            string name;

            reader.ReadStartElement(XD.Message11Dictionary.FaultCode, XD.Message11Dictionary.FaultNamespace);
            XmlUtil.ReadContentAsQName(reader, out name, out ns);
            FaultCode code = new FaultCode(name, ns);

            reader.ReadEndElement();

            string xmlLang = reader.XmlLang;

            reader.MoveToContent();  // Don't do IsStartElement.  FaultString is required, so let the reader throw.
            string          text        = reader.ReadElementContentAsString(XD.Message11Dictionary.FaultString.Value, XD.Message11Dictionary.FaultNamespace.Value);
            FaultReasonText translation = new FaultReasonText(text, xmlLang);

            string actor = "";

            if (reader.IsStartElement(XD.Message11Dictionary.FaultActor, XD.Message11Dictionary.FaultNamespace))
            {
                actor = reader.ReadElementContentAsString();
            }

            XmlBuffer detail = null;

            if (reader.IsStartElement(XD.Message11Dictionary.FaultDetail, XD.Message11Dictionary.FaultNamespace))
            {
                detail = new XmlBuffer(maxBufferSize);
                XmlDictionaryWriter writer = detail.OpenSection(reader.Quotas);
                writer.WriteNode(reader, false);
                detail.CloseSection();
                detail.Close();
            }
            reader.ReadEndElement();
            FaultReason reason = new FaultReason(translation);

            return(new ReceivedFault(code, reason, actor, actor, detail, EnvelopeVersion.Soap11));
        }
Esempio n. 28
0
        internal virtual XmlDictionaryReader GetReaderAtHeader()
        {
            XmlBuffer           buffer = new XmlBuffer(0x7fffffff);
            XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            this.WriteStartEnvelope(writer);
            MessageHeaders headers = this.Headers;

            for (int i = 0; i < headers.Count; i++)
            {
                headers.WriteHeader(i, writer);
            }
            writer.WriteEndElement();
            writer.WriteEndElement();
            buffer.CloseSection();
            buffer.Close();
            XmlDictionaryReader reader = buffer.GetReader(0);

            reader.ReadStartElement();
            reader.MoveToStartElement();
            return(reader);
        }
Esempio n. 29
0
        public void WriteBodyToSignThenEncrypt(Stream canonicalStream, EncryptedData encryptedData, SymmetricAlgorithm algorithm)
        {
            XmlBuffer           buffer = new XmlBuffer(0x7fffffff);
            XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            this.WriteBodyToSignThenEncryptWithFragments(canonicalStream, false, null, encryptedData, algorithm, writer);
            ((IFragmentCapableXmlDictionaryWriter)writer).WriteFragment(this.startBodyFragment.GetBuffer(), 0, (int)this.startBodyFragment.Length);
            ((IFragmentCapableXmlDictionaryWriter)writer).WriteFragment(this.endBodyFragment.GetBuffer(), 0, (int)this.endBodyFragment.Length);
            buffer.CloseSection();
            buffer.Close();
            this.startBodyFragment = null;
            this.endBodyFragment   = null;
            XmlDictionaryReader reader = buffer.GetReader(0);

            reader.MoveToContent();
            this.bodyPrefix = reader.Prefix;
            if (reader.HasAttributes)
            {
                this.bodyAttributes = System.IdentityModel.XmlAttributeHolder.ReadAttributes(reader);
            }
            reader.Close();
        }
        private XmlBuffer GetOrCreateBufferOverExtensions()
        {
            if (this.buffer != null)
            {
                return(this.buffer);
            }
            XmlBuffer buffer = new XmlBuffer(0x7fffffff);

            using (XmlWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max))
            {
                writer.WriteStartElement("extensionWrapper");
                for (int i = 0; i < base.Count; i++)
                {
                    base[i].WriteTo(writer);
                }
                writer.WriteEndElement();
            }
            buffer.CloseSection();
            buffer.Close();
            this.buffer = buffer;
            return(buffer);
        }
        private XmlBuffer GetOrCreateBufferOverExtensions()
        {
            if (_buffer != null)
            {
                return(_buffer);
            }
            XmlBuffer newBuffer = new XmlBuffer(int.MaxValue);

            using (XmlWriter writer = newBuffer.OpenSection(XmlDictionaryReaderQuotas.Max))
            {
                writer.WriteStartElement(Rss20Constants.ExtensionWrapperTag);
                for (int i = 0; i < this.Count; ++i)
                {
                    this[i].WriteTo(writer);
                }
                writer.WriteEndElement();
            }
            newBuffer.CloseSection();
            newBuffer.Close();
            _buffer = newBuffer;
            return(newBuffer);
        }
Esempio n. 32
0
        public void WriteBodyToEncryptThenSign(Stream canonicalStream, EncryptedData encryptedData, SymmetricAlgorithm algorithm)
        {
            encryptedData.Id = _securityHeader.GenerateId();
            SetBodyId();

            XmlDictionaryWriter encryptingWriter = XmlDictionaryWriter.CreateTextWriter(Stream.Null);

            // The XmlSerializer body formatter would add a
            // document declaration to the body fragment when a fresh writer
            // is provided. Hence, insert a dummy element here and capture
            // the body contents as a fragment.
            encryptingWriter.WriteStartElement("a");
            MemoryStream ms = new MemoryStream();

            ((IFragmentCapableXmlDictionaryWriter)encryptingWriter).StartFragment(ms, true);

            InnerMessage.WriteBodyContents(encryptingWriter);
            ((IFragmentCapableXmlDictionaryWriter)encryptingWriter).EndFragment();
            encryptingWriter.WriteEndElement();
            ms.Flush();
            encryptedData.SetUpEncryption(algorithm, new ArraySegment <byte>(ms.GetBuffer(), 0, (int)ms.Length));

            _fullBodyBuffer = new XmlBuffer(int.MaxValue);
            XmlDictionaryWriter canonicalWriter = _fullBodyBuffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            canonicalWriter.StartCanonicalization(canonicalStream, false, null);
            WriteStartInnerMessageWithId(canonicalWriter);
            encryptedData.WriteTo(canonicalWriter, ServiceModelDictionaryManager.Instance);
            canonicalWriter.WriteEndElement();
            canonicalWriter.EndCanonicalization();
            canonicalWriter.Flush();

            _fullBodyBuffer.CloseSection();
            _fullBodyBuffer.Close();

            _state = BodyState.EncryptedThenSigned;
        }
        public void WriteBodyToSignThenEncrypt(Stream canonicalStream, EncryptedData encryptedData, SymmetricAlgorithm algorithm)
        {
            XmlBuffer buffer = new XmlBuffer(int.MaxValue);
            XmlDictionaryWriter fragmentingWriter = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);
            WriteBodyToSignThenEncryptWithFragments(canonicalStream, false, null, encryptedData, algorithm, fragmentingWriter);
            ((IFragmentCapableXmlDictionaryWriter)fragmentingWriter).WriteFragment(this.startBodyFragment.GetBuffer(), 0, (int)this.startBodyFragment.Length);
            ((IFragmentCapableXmlDictionaryWriter)fragmentingWriter).WriteFragment(this.endBodyFragment.GetBuffer(), 0, (int)this.endBodyFragment.Length);
            buffer.CloseSection();
            buffer.Close();

            this.startBodyFragment = null;
            this.endBodyFragment = null;

            XmlDictionaryReader reader = buffer.GetReader(0);
            reader.MoveToContent();
            this.bodyPrefix = reader.Prefix;
            if (reader.HasAttributes)
            {
                this.bodyAttributes = XmlAttributeHolder.ReadAttributes(reader);
            }
            reader.Close();
        }
Esempio n. 34
0
        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();
        }