| Crates.io | sarif_rust |
| lib.rs | sarif_rust |
| version | 0.3.0 |
| created_at | 2025-09-17 15:56:36.311081+00 |
| updated_at | 2025-09-17 19:28:13.607396+00 |
| description | A comprehensive Rust library for parsing, generating, and manipulating SARIF (Static Analysis Results Interchange Format) v2.1.0 files |
| homepage | |
| repository | https://github.com/khalid/sarif_rust |
| max_upload_size | |
| id | 1843521 |
| size | 734,324 |
A comprehensive Rust library for parsing, generating, and manipulating SARIF (Static Analysis Results Interchange Format) v2.1.0 files.
SARIF is a standard JSON format for the output of static analysis tools. This library provides complete support for the SARIF v2.1.0 specification with type-safe parsing, generation, validation, and manipulation capabilities.
Add this to your Cargo.toml:
[dependencies]
sarif_rust = "0.2.0"
use sarif_rust::{SarifLog, SarifLogBuilder, Level};
// Parse existing SARIF file
let sarif: SarifLog = sarif_rust::from_file("results.sarif")?;
// Access results
for run in &sarif.runs {
println!("Tool: {}", run.tool.driver.name);
if let Some(results) = &run.results {
for result in results {
println!(" Issue: {}",
result.message.text.as_deref().unwrap_or("no message"));
}
}
}
// Create new SARIF programmatically
let new_sarif = SarifLogBuilder::new()
.with_schema("https://json.schemastore.org/sarif-2.1.0.json")
.build();
// Save to file
sarif_rust::to_file(&new_sarif, "output.sarif")?;
use sarif_rust::utils::{SarifIndex, QueryBuilder, Level};
let sarif = sarif_rust::from_file("results.sarif")?;
let index = SarifIndex::from_sarif_log(&sarif)?;
// Query by rule ID
let security_issues = index.get_results_for_rule("security/xss")?;
// Complex filtering with query builder
let query = QueryBuilder::new()
.with_rule_id_filter("security/*")
.with_minimum_level(Level::Warning)
.with_file_pattern("*.js")
.with_text_search("password")
.build();
let results = query.execute(&index)?;
println!("Found {} security issues", results.len());
use sarif_rust::utils::{SarifMerger, MergeConfig};
let baseline = sarif_rust::from_file("baseline.sarif")?;
let current = sarif_rust::from_file("current.sarif")?;
// Configure merge behavior
let config = MergeConfig::default()
.with_deduplication(true) // Remove duplicate results
.with_consolidation(true) // Merge runs from same tool
.with_include_added(true)
.with_include_removed(true);
let merger = SarifMerger::new(config);
let merged = merger.merge(vec![baseline, current])?;
sarif_rust::to_file(&merged, "merged.sarif")?;
use sarif_rust::utils::{SarifConverter, ConversionConfig, OutputFormat};
let sarif = sarif_rust::from_file("results.sarif")?;
let config = ConversionConfig::default()
.with_include_full_paths(true)
.with_max_message_length(Some(100));
let converter = SarifConverter::new(config);
// Convert to CSV
let csv_output = converter.to_csv(&sarif)?;
std::fs::write("results.csv", csv_output)?;
// Convert to HTML report
let html_output = converter.to_html(&sarif)?;
std::fs::write("report.html", html_output)?;
This library implements the complete SARIF v2.1.0 specification including:
| Operation | File Size | Performance Target |
|---|---|---|
| Parse | 1-10 MB | < 100ms |
| Validate | 1-10 MB | < 50ms |
| Serialize | 1-10 MB | < 50ms |
| Stream Parse | 100+ MB | < 500MB RAM |
Contributions are welcome! Please see our contribution guidelines for details on:
This project is licensed under either of:
at your option.
Status: 🚧 Under Development - See Implementation Plan for current progress