예제 #1
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);
 }
 void EnsureContentBuffer()
 {
     if (this.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();
         this.contentBuffer = tmp;
     }
 }
 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;
     }
 }
예제 #4
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));
        }
예제 #5
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;
     }
 }
예제 #6
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));
        }
예제 #7
0
        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));
        }
예제 #8
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;
        }
 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;
 }
예제 #10
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;
        }
 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);
        }
 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;
 }
예제 #14
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;
 }
예제 #15
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));
        }
예제 #16
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);
        }
        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);
        }
예제 #18
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 (_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);
        }
예제 #20
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;
        }
예제 #21
0
 public SecurityVerifiedMessage(Message messageToProcess, ReceiveSecurityHeader securityHeader)
     : base(messageToProcess)
 {
     ReceivedSecurityHeader = securityHeader;
     if (securityHeader.RequireMessageProtection)
     {
         XmlDictionaryReader messageReader;
         if (InnerMessage is BufferedMessage bufferedMessage && 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;
     }
예제 #22
0
        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(_startBodyFragment.GetBuffer(), 0, (int)_startBodyFragment.Length);
            ((IFragmentCapableXmlDictionaryWriter)fragmentingWriter).WriteFragment(_endBodyFragment.GetBuffer(), 0, (int)_endBodyFragment.Length);
            buffer.CloseSection();
            buffer.Close();

            _startBodyFragment = null;
            _endBodyFragment   = null;

            XmlDictionaryReader reader = buffer.GetReader(0);

            reader.MoveToContent();
            _bodyPrefix = reader.Prefix;
            if (reader.HasAttributes)
            {
                _bodyAttributes = XmlAttributeHolder.ReadAttributes(reader);
            }
            reader.Close();
        }
        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();
        }