internal CanonicalXml(XmlDocument document, XmlResolver resolver, bool includeComments) {
            if (document == null)
                throw new ArgumentNullException("document");

            m_c14nDoc = new CanonicalXmlDocument(true, includeComments);
            m_c14nDoc.XmlResolver = resolver;
            m_c14nDoc.Load(new XmlNodeReader(document));
            m_ancMgr = new C14NAncestralNamespaceContextManager();
        }
        // private static String defaultXPathWithoutComments = "(//. | //@* | //namespace::*)[not(self::comment())]";
        // private static String defaultXPathWithoutComments = "(//. | //@* | //namespace::*)";
        // private static String defaultXPathWithComments = "(//. | //@* | //namespace::*)";
        // private static String defaultXPathWithComments = "(//. | //@* | //namespace::*)";

        internal CanonicalXml(Stream inputStream, bool includeComments, XmlResolver resolver, string strBaseUri) {
            if (inputStream == null)
                throw new ArgumentNullException("inputStream");

            m_c14nDoc = new CanonicalXmlDocument(true, includeComments);
            m_c14nDoc.XmlResolver = resolver;
            m_c14nDoc.Load(Utils.PreProcessStreamInput(inputStream, resolver, strBaseUri));
            m_ancMgr = new C14NAncestralNamespaceContextManager();
        }
Beispiel #3
0
        // private static string defaultXPathWithoutComments = "(//. | //@* | //namespace::*)[not(self::comment())]";
        // private static string defaultXPathWithoutComments = "(//. | //@* | //namespace::*)";
        // private static string defaultXPathWithComments = "(//. | //@* | //namespace::*)";
        // private static string defaultXPathWithComments = "(//. | //@* | //namespace::*)";

        internal CanonicalXml(Stream inputStream, bool includeComments, XmlResolver resolver, string strBaseUri)
        {
            if (inputStream == null)
            {
                throw new ArgumentNullException(nameof(inputStream));
            }

            _c14nDoc             = new CanonicalXmlDocument(true, includeComments);
            _c14nDoc.XmlResolver = resolver;
            _c14nDoc.Load(Utils.PreProcessStreamInput(inputStream, resolver, strBaseUri));
            _ancMgr = new C14NAncestralNamespaceContextManager();
        }
        internal CanonicalXml(XmlNodeList nodeList, XmlResolver resolver, bool includeComments) {
            if (nodeList == null)
                throw new ArgumentNullException("nodeList");

            XmlDocument doc = Utils.GetOwnerDocument(nodeList);
            if (doc == null)
                throw new ArgumentException("nodeList");

            m_c14nDoc = new CanonicalXmlDocument(false, includeComments);
            m_c14nDoc.XmlResolver = resolver;
            m_c14nDoc.Load(new XmlNodeReader(doc));
            m_ancMgr = new C14NAncestralNamespaceContextManager();

            MarkInclusionStateForNodes(nodeList, doc, m_c14nDoc);
        }
 internal CanonicalXml(XmlNodeList nodeList, XmlResolver resolver, bool includeComments)
 {
     if (nodeList == null)
     {
         throw new ArgumentNullException("nodeList");
     }
     XmlDocument ownerDocument = System.Security.Cryptography.Xml.Utils.GetOwnerDocument(nodeList);
     if (ownerDocument == null)
     {
         throw new ArgumentException("nodeList");
     }
     this.m_c14nDoc = new CanonicalXmlDocument(false, includeComments);
     this.m_c14nDoc.XmlResolver = resolver;
     this.m_c14nDoc.Load(new XmlNodeReader(ownerDocument));
     this.m_ancMgr = new C14NAncestralNamespaceContextManager();
     MarkInclusionStateForNodes(nodeList, ownerDocument, this.m_c14nDoc);
 }
Beispiel #6
0
        internal CanonicalXml(XmlNodeList nodeList, XmlResolver resolver, bool includeComments)
        {
            if (nodeList == null)
            {
                throw new ArgumentNullException("nodeList");
            }
            XmlDocument ownerDocument = System.Security.Cryptography.Xml.Utils.GetOwnerDocument(nodeList);

            if (ownerDocument == null)
            {
                throw new ArgumentException("nodeList");
            }
            this.m_c14nDoc             = new CanonicalXmlDocument(false, includeComments);
            this.m_c14nDoc.XmlResolver = resolver;
            this.m_c14nDoc.Load(new XmlNodeReader(ownerDocument));
            this.m_ancMgr = new C14NAncestralNamespaceContextManager();
            MarkInclusionStateForNodes(nodeList, ownerDocument, this.m_c14nDoc);
        }
        internal CanonicalXml(XmlNodeList nodeList, bool includeComments)
        {
            if (nodeList == null)
            {
                throw new ArgumentNullException(nameof(nodeList));
            }

            XmlDocument doc = Utils.GetOwnerDocument(nodeList);

            if (doc == null)
            {
                throw new ArgumentException("nodeList");
            }

            _c14nDoc = new CanonicalXmlDocument(false, includeComments);
            _c14nDoc.LoadXml(doc.OuterXml);
            _ancMgr = new C14NAncestralNamespaceContextManager();

            MarkInclusionStateForNodes(nodeList, doc, _c14nDoc);
        }
Beispiel #8
0
        internal CanonicalXml(XmlNodeList nodeList, XmlResolver resolver, bool includeComments)
        {
            if (nodeList == null)
            {
                throw new ArgumentNullException("nodeList");
            }

            XmlDocument doc = Utils.GetOwnerDocument(nodeList);

            if (doc == null)
            {
                throw new ArgumentException("nodeList");
            }

            m_c14nDoc             = new CanonicalXmlDocument(false, includeComments);
            m_c14nDoc.XmlResolver = resolver;
            m_c14nDoc.Load(new XmlNodeReader(doc));
            m_ancMgr = new C14NAncestralNamespaceContextManager();

            MarkInclusionStateForNodes(nodeList, doc, m_c14nDoc);
        }
        public void Write(StringBuilder strBuilder, C14NAncestralNamespaceContextManager anc)
        {
            Hashtable  nsLocallyDeclared = new Hashtable();
            SortedList nsListToRender    = new SortedList(new NamespaceSortOrder());
            SortedList attrListToRender  = new SortedList(new AttributeSortOrder());

            XmlAttributeCollection attrList = Attributes;

            if (attrList != null)
            {
                foreach (XmlAttribute attr in attrList)
                {
                    if (((CanonicalXmlAttribute)attr).IsInNodeSet || Utils.IsNamespaceNode(attr) || Utils.IsXmlNamespaceNode(attr))
                    {
                        if (Utils.IsNamespaceNode(attr))
                        {
                            anc.TrackNamespaceNode(attr, nsListToRender, nsLocallyDeclared);
                        }
                        else if (Utils.IsXmlNamespaceNode(attr))
                        {
                            anc.TrackXmlNamespaceNode(attr, nsListToRender, attrListToRender, nsLocallyDeclared);
                        }
                        else if (IsInNodeSet)
                        {
                            attrListToRender.Add(attr, null);
                        }
                    }
                }
            }

            if (!Utils.IsCommittedNamespace(this, Prefix, NamespaceURI))
            {
                string       name     = ((Prefix.Length > 0) ? "xmlns" + ":" + Prefix : "xmlns");
                XmlAttribute nsattrib = (XmlAttribute)OwnerDocument.CreateAttribute(name);
                nsattrib.Value = NamespaceURI;
                anc.TrackNamespaceNode(nsattrib, nsListToRender, nsLocallyDeclared);
            }

            if (IsInNodeSet)
            {
                anc.GetNamespacesToRender(this, attrListToRender, nsListToRender, nsLocallyDeclared);

                strBuilder.Append("<" + Name);
                foreach (object attr in nsListToRender.GetKeyList())
                {
                    (attr as CanonicalXmlAttribute).Write(strBuilder, anc);
                }
                foreach (object attr in attrListToRender.GetKeyList())
                {
                    (attr as CanonicalXmlAttribute).Write(strBuilder, anc);
                }
                strBuilder.Append(">");
            }

            anc.EnterElementContext();
            anc.LoadUnrenderedNamespaces(nsLocallyDeclared);
            anc.LoadRenderedNamespaces(nsListToRender);

            XmlNodeList childNodes = ChildNodes;

            foreach (XmlNode childNode in childNodes)
            {
                CanonicalizationDispatcher.Write(childNode, strBuilder, anc);
            }

            anc.ExitElementContext();

            if (IsInNodeSet)
            {
                strBuilder.Append("</" + Name + ">");
            }
        }
        public void WriteHash(HashAlgorithm hash, C14NAncestralNamespaceContextManager anc, List <byte> conjuntoDados)
        {
            Hashtable    nsLocallyDeclared = new Hashtable();
            SortedList   nsListToRender    = new SortedList(new NamespaceSortOrder());
            SortedList   attrListToRender  = new SortedList(new AttributeSortOrder());
            UTF8Encoding utf8 = new UTF8Encoding(false);

            byte[] rgbData;

            XmlAttributeCollection attrList = Attributes;

            if (attrList != null)
            {
                foreach (XmlAttribute attr in attrList)
                {
                    if (((CanonicalXmlAttribute)attr).IsInNodeSet || Utils.IsNamespaceNode(attr) || Utils.IsXmlNamespaceNode(attr))
                    {
                        if (Utils.IsNamespaceNode(attr))
                        {
                            anc.TrackNamespaceNode(attr, nsListToRender, nsLocallyDeclared);
                        }
                        else if (Utils.IsXmlNamespaceNode(attr))
                        {
                            anc.TrackXmlNamespaceNode(attr, nsListToRender, attrListToRender, nsLocallyDeclared);
                        }
                        else if (IsInNodeSet)
                        {
                            attrListToRender.Add(attr, null);
                        }
                    }
                }
            }

            if (!Utils.IsCommittedNamespace(this, Prefix, NamespaceURI))
            {
                string       name     = ((Prefix.Length > 0) ? "xmlns" + ":" + Prefix : "xmlns");
                XmlAttribute nsattrib = (XmlAttribute)OwnerDocument.CreateAttribute(name);
                nsattrib.Value = NamespaceURI;
                anc.TrackNamespaceNode(nsattrib, nsListToRender, nsLocallyDeclared);
            }

            if (IsInNodeSet)
            {
                anc.GetNamespacesToRender(this, attrListToRender, nsListToRender, nsLocallyDeclared);
                rgbData = utf8.GetBytes("<" + Name);
                conjuntoDados.AddRange(rgbData);
                foreach (object attr in nsListToRender.GetKeyList())
                {
                    (attr as CanonicalXmlAttribute).WriteHash(hash, anc, conjuntoDados);
                }
                foreach (object attr in attrListToRender.GetKeyList())
                {
                    (attr as CanonicalXmlAttribute).WriteHash(hash, anc, conjuntoDados);
                }
                rgbData = utf8.GetBytes(">");
                conjuntoDados.AddRange(rgbData);
            }

            anc.EnterElementContext();
            anc.LoadUnrenderedNamespaces(nsLocallyDeclared);
            anc.LoadRenderedNamespaces(nsListToRender);

            XmlNodeList childNodes = ChildNodes;

            foreach (XmlNode childNode in childNodes)
            {
                CanonicalizationDispatcher.WriteHash(childNode, hash, anc, conjuntoDados);
            }

            anc.ExitElementContext();

            if (IsInNodeSet)
            {
                rgbData = utf8.GetBytes("</" + Name + ">");
                conjuntoDados.AddRange(rgbData);
            }
        }
Beispiel #11
0
 public void Write(StringBuilder strBuilder, C14NAncestralNamespaceContextManager anc)
 {
     strBuilder.Append(" " + Name + "=\"");
     strBuilder.Append(Utils.EscapeAttributeValue(Value));
     strBuilder.Append("\"");
 }