Skip to main content

Crate xarf

Crate xarf 

Source
Expand description

§xarf — XARF v4 parser, validator, and generator

The eXtended Abuse Reporting Format (XARF) is a JSON schema for describing abuse incidents — spam, DDoS, phishing, compromised infrastructure, copyright violations, and so on. This crate is a Rust implementation of the v4 spec.

§Quick start

use xarf::{parse, Contact, ReportBuilder, create_evidence};
use serde_json::json;

// Parse incoming JSON.
let result = parse(r#"{"xarf_version": "4.2.0", ... }"#).unwrap();
if result.errors.is_empty() {
    println!("category = {}", result.report.unwrap().category.as_str());
}

// Build a new report programmatically.
let evidence = create_evidence("text/plain", b"log line");
let result = ReportBuilder::new("messaging", "spam", "192.0.2.1")
    .reporter(Contact::new("Acme", "abuse@acme.example", "acme.example"))
    .sender(Contact::new("Acme", "abuse@acme.example", "acme.example"))
    .extra("protocol", json!("smtp"))
    .extra("smtp_from", json!("spam@bad.example"))
    .add_evidence(evidence)
    .build()
    .unwrap();

§Modules

Re-exports§

pub use error::Result;
pub use error::ValidationError;
pub use error::ValidationInfo;
pub use error::ValidationWarning;
pub use error::XarfError;
pub use generator::CreateReportOptions;
pub use generator::EvidenceOptions;
pub use generator::HashAlgorithm;
pub use generator::ReportBuilder;
pub use generator::SPEC_VERSION;
pub use generator::create_evidence;
pub use generator::create_evidence_with_options;
pub use generator::create_report;
pub use model::Category;
pub use model::Contact;
pub use model::Evidence;
pub use model::Report;
pub use parser::ParseOptions;
pub use parser::ParseResult;
pub use parser::parse;
pub use parser::parse_value;
pub use parser::parse_with_options;
pub use v3_compat::convert_v3_to_v4;
pub use v3_compat::deprecation_warning;
pub use v3_compat::is_v3_report;
pub use validator::ValidateOptions;
pub use validator::ValidationResult;
pub use validator::quick_errors;
pub use validator::validate;

Modules§

error
Error and result types for the XARF crate.
generator
Report generator — create_report and create_evidence.
model
Core data model for XARF v4 reports.
parser
High-level parse() entry point.
schemas
Embedded XARF v4 JSON schemas and a lazily-compiled validator registry.
v3_compat
XARF v3 compatibility: detect v3 reports and convert them to v4 JSON.
validator
Schema-based validator for raw XARF v4 report JSON.