Example #1
0
 internal ExcCanonicalXml(
     Stream inputStream,
     bool includeComments,
     string inclusiveNamespacesPrefixList,
     XmlResolver resolver,
     string strBaseUri)
 {
     if (inputStream == null)
     {
         throw new ArgumentNullException(nameof(inputStream));
     }
     this.m_c14nDoc             = new CanonicalXmlDocument(true, includeComments);
     this.m_c14nDoc.XmlResolver = resolver;
     this.m_c14nDoc.Load(Exml.PreProcessStreamInput(inputStream, resolver, strBaseUri));
     this.m_ancMgr = new ExcAncestralNamespaceContextManager(inclusiveNamespacesPrefixList);
 }
Example #2
0
        internal Stream TransformToOctetStream(
            object inputObject,
            Type inputType,
            XmlResolver resolver,
            string baseUri)
        {
            object obj = inputObject;

            foreach (Transform transform in this.m_transforms)
            {
                if (obj == null || transform.AcceptsType(obj.GetType()))
                {
                    transform.Resolver = resolver;
                    transform.BaseURI  = baseUri;
                    transform.LoadInput(obj);
                    obj = transform.GetOutput();
                }
                else if (obj is Stream)
                {
                    if (!transform.AcceptsType(typeof(XmlDocument)))
                    {
                        throw new CryptographicException("Cryptography_Xml_TransformIncorrectInputType");
                    }
                    Stream      inputStream = obj as Stream;
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.PreserveWhitespace = true;
                    XmlReader reader = Exml.PreProcessStreamInput(inputStream, resolver, baseUri);
                    xmlDocument.Load(reader);
                    transform.LoadInput((object)xmlDocument);
                    inputStream.Close();
                    obj = transform.GetOutput();
                }
                else if (obj is XmlNodeList)
                {
                    if (!transform.AcceptsType(typeof(Stream)))
                    {
                        throw new CryptographicException("Cryptography_Xml_TransformIncorrectInputType");
                    }
                    MemoryStream memoryStream = new MemoryStream(new CanonicalXml((XmlNodeList)obj, resolver, false).GetBytes());
                    transform.LoadInput((object)memoryStream);
                    obj = transform.GetOutput();
                    memoryStream.Close();
                }
                else
                {
                    if (!(obj is XmlDocument))
                    {
                        throw new CryptographicException("Cryptography_Xml_TransformIncorrectInputType");
                    }
                    if (!transform.AcceptsType(typeof(Stream)))
                    {
                        throw new CryptographicException("Cryptography_Xml_TransformIncorrectInputType");
                    }
                    MemoryStream memoryStream = new MemoryStream(new CanonicalXml((XmlDocument)obj, resolver).GetBytes());
                    transform.LoadInput((object)memoryStream);
                    obj = transform.GetOutput();
                    memoryStream.Close();
                }
            }
            if (obj is Stream)
            {
                return(obj as Stream);
            }
            if (obj is XmlNodeList)
            {
                return((Stream) new MemoryStream(new CanonicalXml((XmlNodeList)obj, resolver, false).GetBytes()));
            }
            if (obj is XmlDocument)
            {
                return((Stream) new MemoryStream(new CanonicalXml((XmlDocument)obj, resolver).GetBytes()));
            }
            throw new CryptographicException("Cryptography_Xml_TransformIncorrectInputType");
        }