| Crates.io | stix2 |
| lib.rs | stix2 |
| version | 0.1.1 |
| created_at | 2026-01-01 05:25:36.273197+00 |
| updated_at | 2026-01-01 06:12:36.83485+00 |
| description | A Rust implementation of STIX 2.1 (Structured Threat Information Expression) |
| homepage | https://cysecurity.org/ |
| repository | https://github.com/CSPF-Founder/darwis-taxii |
| max_upload_size | |
| id | 2015786 |
| size | 876,902 |
A Rust implementation of STIX 2.1 (Structured Threat Information Expression) for representing and exchanging cyber threat intelligence.
Add to your Cargo.toml:
[dependencies]
stix2 = "0.1"
default - Core functionality (no async)async - Enables async datastore operations with tokio and reqwesttaxii - Enables TAXII client support (includes async)# With async support
stix2 = { version = "0.1", features = ["async"] }
use stix2::prelude::*;
fn main() -> stix2::Result<()> {
// Create an indicator
let indicator = Indicator::builder()
.name("Malicious File Hash")
.pattern("[file:hashes.'SHA-256' = 'abc123']")
.pattern_type(PatternType::Stix)
.valid_from_now()
.build()?;
// Serialize to JSON
let json = stix2::serialize_pretty(&indicator)?;
println!("{}", json);
// Parse from JSON
let parsed: StixObject = stix2::parse(&json)?;
Ok(())
}
use stix2::prelude::*;
fn main() -> stix2::Result<()> {
// Create a bundle with multiple objects
let mut bundle = Bundle::new();
let threat_actor = ThreatActor::builder()
.name("APT28")
.threat_actor_types(vec![ThreatActorType::NationState])
.build()?;
let malware = Malware::builder()
.name("X-Agent")
.is_family(true)
.malware_types(vec![MalwareType::Backdoor])
.build()?;
bundle.add_object(threat_actor);
bundle.add_object(malware);
// Serialize the bundle
let json = stix2::serialize_pretty(&bundle)?;
Ok(())
}
use stix2::prelude::*;
fn main() -> stix2::Result<()> {
// Create an in-memory store
let mut store = MemoryStore::new();
let indicator = Indicator::builder()
.name("Test Indicator")
.pattern("[domain-name:value = 'malicious.com']")
.pattern_type(PatternType::Stix)
.valid_from_now()
.build()?;
// Add to store
store.add(indicator.into())?;
// Query with filters
let results = store.query(vec![
Filter::new("type", "=", "indicator"),
])?;
Ok(())
}
use stix2::patterns::Pattern;
fn main() -> stix2::Result<()> {
let pattern_str = "[file:hashes.'SHA-256' = 'abc123'] AND [domain-name:value = 'evil.com']";
let pattern = Pattern::parse(pattern_str)?;
// Analyze the parsed pattern
println!("Pattern: {:?}", pattern);
Ok(())
}
BSD-3-Clause