/// <summary>
        /// Applies a canonicalization transform over a set of XML nodes.
        /// </summary>
        /// <param name="tokenStream">the set of XML nodes to transform.</param>
        /// <param name="includeComments">include comments in canonical bytes.</param>
        /// <param name="inclusiveNamespacesPrefixList">list of namespace prefixes to include</param>
        /// <returns>the bytes of the transformed octets.</returns>
        internal static string GetString(XmlTokenStream tokenStream, bool includeComments, string[] inclusiveNamespacesPrefixList)
        {
            var streamWriter = new XmlTokenStreamWriter(tokenStream);

            using (var stream = new MemoryStream())
                using (var writer = XmlDictionaryWriter.CreateTextWriter(Stream.Null))
                {
                    writer.StartCanonicalization(stream, includeComments, inclusiveNamespacesPrefixList);
                    streamWriter.WriteTo(writer);
                    writer.EndCanonicalization();
                    writer.Flush();
                    return(Encoding.UTF8.GetString(stream.GetBuffer(), 0, (int)stream.Length));
                }
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of <see cref="XmlTokenStreamReader"/> for creating a <see cref="XmlTokenStream"/>.
        /// </summary>
        /// <param name="reader">an <see cref="XmlDictionaryReader"/> to capture the <see cref="XmlTokenStream"/>.</param>
        /// <exception cref="ArgumentNullException">if <paramref name="reader"/> if null.</exception>
        /// <exception cref="ArgumentException">if <paramref name="reader"/>.IsStartElement() is false.</exception>
        public XmlTokenStreamReader(XmlDictionaryReader reader)
        {
            if (reader == null)
            {
                throw LogArgumentNullException(nameof(reader));
            }

            if (!reader.IsStartElement())
            {
                throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX30026, reader.NodeType)));
            }

            TokenStream = new XmlTokenStream();
            InnerReader = reader;
            Record();
        }
        /// <summary>
        /// Initializes a new instance of <see cref="XmlTokenStreamReader"/> for creating a <see cref="XmlTokenStream"/>.
        /// </summary>
        /// <param name="reader">an <see cref="XmlDictionaryReader"/> to capture the <see cref="XmlTokenStream"/>.</param>
        /// <exception cref="ArgumentNullException">if <paramref name="reader"/> if null.</exception>
        /// <exception cref="ArgumentException">if <paramref name="reader"/>.IsStartElement() is false.</exception>
        public XmlTokenStreamReader(XmlDictionaryReader reader)
        {
            if (reader == null)
            {
                throw LogArgumentNullException(nameof(reader));
            }

            if (!reader.IsStartElement())
            {
                throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX30026, reader.NodeType)));
            }

            // When multiple signed elements are being processed, the EnvelopedSignatureReader always creates a new XmlTokenStreamReader.
            // This creates a chain of readers.
            // The outer reader need to record the position of its 'Signature' element.
            // When calculating the digest all inner 'Signatures' are considered as inner text.
            // This allows for embedded signed elements.
            _innerTokenStreamReader = reader as XmlTokenStreamReader;
            TokenStream             = new XmlTokenStream();
            InnerReader             = reader;
            Record();
        }
コード例 #4
0
 public XmlTokenStreamWriter(XmlTokenStream tokenStream)
 {
     Position    = 0;
     TokenStream = tokenStream;
 }
 /// <summary>
 /// Processes a set of XML nodes and returns the hash of the octets.
 /// </summary>
 /// <param name="tokenStream">the <see cref="XmlTokenStream"/> that has the XML nodes to process.</param>
 /// <param name="hashAlg">the <see cref="HashAlgorithm"/>to use</param>
 /// <returns>the hash of the processed XML nodes.</returns>
 public abstract byte[] ProcessAndDigest(XmlTokenStream tokenStream, HashAlgorithm hashAlg);