private void LoadXmlNodeListInput(XmlNodeList nodeList) { XmlResolver resolver = (ResolverSet ? _xmlResolver : new XmlSecureResolver(new XmlUrlResolver(), BaseURI)); CanonicalXml c14n = new CanonicalXml((XmlNodeList)nodeList, resolver, true); using (MemoryStream ms = new MemoryStream(c14n.GetBytes())) { LoadStreamInput(ms); } }
public override void LoadInput(object obj) { if (_inputStream != null) { _inputStream.Close(); } _inputStream = new MemoryStream(); if (obj is Stream) { _inputStream = (Stream)obj; } else if (obj is XmlNodeList) { CanonicalXml xmlDoc = new CanonicalXml((XmlNodeList)obj, null, _includeComments); byte[] buffer = xmlDoc.GetBytes(); if (buffer == null) { return; } _inputStream.Write(buffer, 0, buffer.Length); _inputStream.Flush(); _inputStream.Position = 0; } else if (obj is XmlDocument) { CanonicalXml xmlDoc = new CanonicalXml((XmlDocument)obj, null, _includeComments); byte[] buffer = xmlDoc.GetBytes(); if (buffer == null) { return; } _inputStream.Write(buffer, 0, buffer.Length); _inputStream.Flush(); _inputStream.Position = 0; } }
// The goal behind this method is to pump the input stream through the transforms and get back something that // can be hashed internal Stream TransformToOctetStream(object inputObject, Type inputType, XmlResolver resolver, string baseUri) { object currentInput = inputObject; foreach (Transform transform in _transforms) { if (currentInput == null || transform.AcceptsType(currentInput.GetType())) { //in this case, no translation necessary, pump it through transform.Resolver = resolver; transform.BaseURI = baseUri; transform.LoadInput(currentInput); currentInput = transform.GetOutput(); } else { // We need translation // For now, we just know about Stream->{XmlNodeList,XmlDocument} and {XmlNodeList,XmlDocument}->Stream if (currentInput is Stream) { if (transform.AcceptsType(typeof(XmlDocument))) { Stream currentInputStream = currentInput as Stream; XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; XmlReader valReader = Utils.PreProcessStreamInput(currentInputStream, resolver, baseUri); doc.Load(valReader); transform.LoadInput(doc); currentInputStream.Close(); currentInput = transform.GetOutput(); continue; } else { throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType); } } if (currentInput is XmlNodeList) { if (transform.AcceptsType(typeof(Stream))) { CanonicalXml c14n = new CanonicalXml((XmlNodeList)currentInput, resolver, false); MemoryStream ms = new MemoryStream(c14n.GetBytes()); transform.LoadInput(ms); currentInput = transform.GetOutput(); ms.Close(); continue; } else { throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType); } } if (currentInput is XmlDocument) { if (transform.AcceptsType(typeof(Stream))) { CanonicalXml c14n = new CanonicalXml((XmlDocument)currentInput, resolver); MemoryStream ms = new MemoryStream(c14n.GetBytes()); transform.LoadInput(ms); currentInput = transform.GetOutput(); ms.Close(); continue; } else { throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType); } } throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType); } } // Final processing, either we already have a stream or have to canonicalize if (currentInput is Stream) { return(currentInput as Stream); } if (currentInput is XmlNodeList) { CanonicalXml c14n = new CanonicalXml((XmlNodeList)currentInput, resolver, false); MemoryStream ms = new MemoryStream(c14n.GetBytes()); return(ms); } if (currentInput is XmlDocument) { CanonicalXml c14n = new CanonicalXml((XmlDocument)currentInput, resolver); MemoryStream ms = new MemoryStream(c14n.GetBytes()); return(ms); } throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType); }
internal Stream TransformToOctetStream(object inputObject, Type inputType, XmlResolver resolver, string baseUri) { object currentInput = inputObject; foreach (Transform transform in _transforms) { if (currentInput == null || transform.AcceptsType(currentInput.GetType())) { transform.Resolver = resolver; transform.BaseURI = baseUri; transform.LoadInput(currentInput); currentInput = transform.GetOutput(); } else { if (currentInput is Stream) { if (transform.AcceptsType(typeof(XmlDocument))) { Stream currentInputStream = currentInput as Stream; XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; XmlReader valReader = StreamUtils.PreProcessStreamInput(currentInputStream, resolver, baseUri); doc.Load(valReader); transform.LoadInput(doc); currentInputStream.Close(); currentInput = transform.GetOutput(); continue; } else { throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType); } } if (currentInput is XmlNodeList) { if (transform.AcceptsType(typeof(Stream))) { CanonicalXml c14n = new CanonicalXml((XmlNodeList)currentInput, resolver, false); MemoryStream ms = new MemoryStream(c14n.GetBytes()); transform.LoadInput(ms); currentInput = transform.GetOutput(); ms.Close(); continue; } else { throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType); } } if (currentInput is XmlDocument) { if (transform.AcceptsType(typeof(Stream))) { CanonicalXml c14n = new CanonicalXml((XmlDocument)currentInput, resolver); MemoryStream ms = new MemoryStream(c14n.GetBytes()); transform.LoadInput(ms); currentInput = transform.GetOutput(); ms.Close(); continue; } else { throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType); } } throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType); } } if (currentInput is Stream) { return(currentInput as Stream); } if (currentInput is XmlNodeList) { CanonicalXml c14n = new CanonicalXml((XmlNodeList)currentInput, resolver, false); MemoryStream ms = new MemoryStream(c14n.GetBytes()); return(ms); } if (currentInput is XmlDocument) { CanonicalXml c14n = new CanonicalXml((XmlDocument)currentInput, resolver); MemoryStream ms = new MemoryStream(c14n.GetBytes()); return(ms); } throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType); }
public override object GetOutput() { return(new MemoryStream(_cXml.GetBytes())); }