public static Parse ( |
||
xmlReader | The |
|
strings | Strings used in processing a Fortify report. | |
Результат |
/// <summary> /// Interface implementation for converting a stream of Fortify report in XML format to a /// SARIF json format stream. /// </summary> /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception> /// <param name="input">Stream of the Fortify report.</param> /// <param name="output">Stream of SARIF json.</param> /// <param name="dataToInsert">Logging options that configure output.</param> public override void Convert(Stream input, IResultLogWriter output, OptionallyEmittedData dataToInsert) { if (input == null) { throw new ArgumentNullException(nameof(input)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreWhitespace = true, NameTable = _nameTable, XmlResolver = null }; var results = new List <Result>(); using (XmlReader reader = XmlReader.Create(input, settings)) { while (reader.Read()) { while (StringReference.AreEqual(reader.LocalName, _strings.Issue)) { FortifyIssue fortify = FortifyIssue.Parse(reader, _strings); results.Add(ConvertFortifyIssueToSarifIssue(fortify)); } } } var tool = new Tool { Name = "Fortify" }; var fileInfoFactory = new FileInfoFactory(MimeType.DetermineFromFileExtension, dataToInsert); Dictionary <string, FileData> fileDictionary = fileInfoFactory.Create(results); var run = new Run() { Tool = tool }; output.Initialize(run); if (fileDictionary != null && fileDictionary.Count > 0) { output.WriteFiles(fileDictionary); } output.OpenResults(); output.WriteResults(results); output.CloseResults(); }
/// <summary> /// Interface implementation for converting a stream of Fortify report in XML format to a /// SARIF json format stream. /// </summary> /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception> /// <param name="input">Stream of the Fortify report.</param> /// <param name="output">Stream of SARIF json.</param> public void Convert(Stream input, IResultLogWriter output) { if (input == null) { throw new ArgumentNullException("input"); } if (output == null) { throw new ArgumentNullException("output"); } var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreWhitespace = true, NameTable = _nameTable }; var results = new List <Result>(); using (XmlReader reader = XmlReader.Create(input, settings)) { while (reader.Read()) { while (Ref.Equal(reader.LocalName, _strings.Issue)) { FortifyIssue fortify = FortifyIssue.Parse(reader, _strings); results.Add(ConvertFortifyIssueToSarifIssue(fortify)); } } } var tool = new Tool { Name = "Fortify" }; var fileInfoFactory = new FileInfoFactory(MimeType.DetermineFromFileExtension); Dictionary <string, IList <FileData> > fileDictionary = fileInfoFactory.Create(results); output.WriteTool(tool); if (fileDictionary != null && fileDictionary.Count > 0) { output.WriteFiles(fileDictionary); } output.OpenResults(); output.WriteResults(results); output.CloseResults(); }
/// <summary> /// Interface implementation for converting a stream of Fortify report in XML format to a /// SARIF json format stream. /// </summary> /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception> /// <param name="input">Stream of the Fortify report.</param> /// <param name="output">Stream of SARIF json.</param> public void Convert(Stream input, IResultLogWriter output) { if (input == null) { throw new ArgumentNullException("input"); } if (output == null) { throw new ArgumentNullException("output"); } output.WriteToolAndRunInfo(new ToolInfo { Name = "Fortify" }, null); var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreWhitespace = true, NameTable = _nameTable }; using (XmlReader reader = XmlReader.Create(input, settings)) { while (reader.Read()) { while (Ref.Equal(reader.LocalName, _strings.Issue)) { FortifyIssue fortify = FortifyIssue.Parse(reader, _strings); output.WriteResult(ConvertFortifyIssueToSarifIssue(fortify)); } } } }
private static FortifyIssue Parse(XmlReader reader) { return(FortifyIssue.Parse(reader, new FortifyStrings(reader.NameTable))); }
/// <summary> /// Interface implementation for converting a stream of Fortify report in XML format to a /// SARIF json format stream. /// </summary> /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception> /// <param name="input">Stream of the Fortify report.</param> /// <param name="output">Stream of SARIF json.</param> /// <param name="dataToInsert">Optionally emitted properties that should be written to log.</param> public override void Convert(Stream input, IResultLogWriter output, OptionallyEmittedData dataToInsert) { if (input == null) { throw new ArgumentNullException(nameof(input)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreWhitespace = true, NameTable = _nameTable, XmlResolver = null }; string runDescription = null; var results = new List <Result>(); using (XmlReader reader = XmlReader.Create(input, settings)) { while (reader.Read()) { if (runDescription == null) { // Find the executive summary <ReportSection> element if (StringReference.AreEqual(reader.LocalName, _strings.ReportSection) && reader.IsStartElement()) { reader.Read(); // Move to Title element if (reader.ReadElementContentAsString(_strings.Title, String.Empty) == "Executive Summary") { reader.Read(); // Move to SubSection element reader.IgnoreElement(_strings.Title, IgnoreOptions.Required); reader.IgnoreElement(_strings.Description, IgnoreOptions.Required); runDescription = reader.ReadElementContentAsString(_strings.Text, String.Empty); } } } else { while (StringReference.AreEqual(reader.LocalName, _strings.Issue)) { FortifyIssue fortify = FortifyIssue.Parse(reader, _strings); results.Add(ConvertFortifyIssueToSarifIssue(fortify)); } } } } var tool = new Tool { Name = "Fortify" }; var fileInfoFactory = new FileInfoFactory(MimeType.DetermineFromFileExtension, dataToInsert); Dictionary <string, FileData> fileDictionary = fileInfoFactory.Create(results); var run = new Run() { Description = new Message { Text = runDescription }, Tool = tool }; output.Initialize(run); if (fileDictionary != null && fileDictionary.Count > 0) { output.WriteFiles(fileDictionary); } output.OpenResults(); output.WriteResults(results); output.CloseResults(); }
/// <summary> /// Interface implementation for converting a stream of Fortify report in XML format to a /// SARIF json format stream. /// </summary> /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception> /// <param name="input">Stream of the Fortify report.</param> /// <param name="output">Stream of SARIF json.</param> /// <param name="dataToInsert">Optionally emitted properties that should be written to log.</param> public override void Convert(Stream input, IResultLogWriter output, OptionallyEmittedData dataToInsert) { if (input == null) { throw new ArgumentNullException(nameof(input)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreWhitespace = true, NameTable = _nameTable, XmlResolver = null }; string runDescription = null; var results = new List <Result>(); using (XmlReader reader = XmlReader.Create(input, settings)) { while (reader.Read()) { if (runDescription == null) { // Find the executive summary <ReportSection> element if (StringReference.AreEqual(reader.LocalName, _strings.ReportSection) && reader.IsStartElement()) { reader.Read(); // Move to Title element if (reader.ReadElementContentAsString(_strings.Title, String.Empty) == "Executive Summary") { reader.Read(); // Move to SubSection element reader.IgnoreElement(_strings.Title, IgnoreOptions.Required); reader.IgnoreElement(_strings.Description, IgnoreOptions.Required); runDescription = reader.ReadElementContentAsString(_strings.Text, String.Empty); } } } else { while (StringReference.AreEqual(reader.LocalName, _strings.Issue)) { FortifyIssue fortify = FortifyIssue.Parse(reader, _strings); results.Add(ConvertFortifyIssueToSarifIssue(fortify)); } } } } var run = new Run() { AutomationDetails = new RunAutomationDetails { Description = new Message { Text = runDescription } }, Tool = new Tool { Driver = new ToolComponent { Name = ToolName } } }; PersistResults(output, results, run); }