public static string Generate(XmlEement dataElement)
        {
            int initialCapacity = (dataElement.Name.Length + 3) * 2;
            var stringBuilder   = new StringBuilder(initialCapacity);

            stringBuilder.Append('<').Append(dataElement.Name).Append('>');
            if (dataElement.Value is string str)
            {
                stringBuilder.Append(str);
            }
            else if (dataElement.Value is XmlEement element)
            {
                stringBuilder.Append(Generate(element));
            }
            else if (dataElement.Value is List <XmlEement> elements)
            {
                foreach (var ele in elements)
                {
                    stringBuilder.Append(Generate(ele));
                }
            }
            else
            {
                throw new TestException($"dataElement.Value must be of type: '{typeof(string)}' or '{typeof(XmlEement)} or '{typeof(List<XmlEement>)}' was: {dataElement.Value.GetType()}.");
            }

            stringBuilder.Append("</").Append(dataElement.Name).Append('>');
            return(stringBuilder.ToString());
        }
예제 #2
0
        public static string Generate(XmlEement dataElement)
        {
            var stringBuilder = new StringBuilder($"<{dataElement.Name}>");

            if (dataElement.Value is string str)
            {
                stringBuilder.Append(str);
            }
            else if (dataElement.Value is XmlEement element)
            {
                stringBuilder.Append(Generate(element));
            }
            else if (dataElement.Value is List <XmlEement> elements)
            {
                foreach (var ele in elements)
                {
                    stringBuilder.Append(Generate(ele));
                }
            }
            else
            {
                throw new TestException($"dataElement.Value must be of type: '{typeof(string)}' or '{typeof(XmlEement)} or '{typeof(List<XmlEement>)}' was: {dataElement.Value.GetType()}.");
            }

            stringBuilder.Append($"</{dataElement.Name}>");
            return(stringBuilder.ToString());
        }
        public static string Generate(KeyInfo keyInfo)
        {
            var str = "";

            foreach (var data in keyInfo.X509Data)
            {
                // Make a new list of elements for each X509Data object
                var elements = new List <XmlEement>();
                foreach (var certificate in data.Certificates)
                {
                    elements.Add(new XmlEement(XmlSignatureConstants.Elements.X509Certificate, certificate));
                }
                if (data.IssuerSerial != null)
                {
                    if (!string.IsNullOrEmpty(data.IssuerSerial.IssuerName))
                    {
                        elements.Add(new XmlEement(XmlSignatureConstants.Elements.X509IssuerName, data.IssuerSerial.IssuerName));
                    }

                    if (!string.IsNullOrEmpty(data.IssuerSerial.SerialNumber))
                    {
                        elements.Add(new XmlEement(XmlSignatureConstants.Elements.X509SerialNumber, data.IssuerSerial.SerialNumber));
                    }
                }
                if (!string.IsNullOrEmpty(data.SKI))
                {
                    elements.Add(new XmlEement(XmlSignatureConstants.Elements.X509SKI, data.SKI));
                }

                if (!string.IsNullOrEmpty(data.SubjectName))
                {
                    elements.Add(new XmlEement(XmlSignatureConstants.Elements.X509SubjectName, data.SubjectName));
                }

                str += XmlEement.Generate(new XmlEement(XmlSignatureConstants.Elements.X509Data, elements));
            }

            return(string.Format(KeyInfoTemplate, XmlSignatureConstants.Namespace, str));
        }
 public static string KeyInfoXml(string @namespace, XmlEement x509Data)
 {
     return(string.Format(KeyInfoTemplate, @namespace, XmlEement.Generate(x509Data)));
 }