A Rust library for creating, validating, and working with JMIX (JSON Medical Interchange) packages. JMIX enables secure exchange of medical imaging data and metadata with built-in encryption, digital signatures, and integrity verification.
- ποΈ High-level builder API for creating JMIX envelopes
- π₯ DICOM file processing and metadata extraction
- π End-to-end encryption using AES-256-GCM with Curve25519 ECDH
- βοΈ Digital signatures with Ed25519 (JWS standard)
- π JSON Schema validation with configurable schema directory
- β Integrity verification using deterministic SHA-256 payload hashing
- π‘οΈ Cryptographic assertions for sender/receiver identity verification
- π¦ Package validation API with comprehensive error reporting
Add to your Cargo.toml:
[dependencies]
jmix-rs = "0.3.2"Create a simple JMIX envelope from DICOM files:
use jmix_rs::{builder::JmixBuilder, config::Config};
let builder = JmixBuilder::new();
let config = Config::from_file("config.json")?;
let (envelope, files) = builder.build_from_dicom("path/to/dicom", &config)?;Create an envelope with encryption and digital signatures:
use jmix_rs::builder::JmixBuilder;
// Builder with complete security features
let builder = JmixBuilder::with_complete_security()?;
let (envelope, files) = builder.build_from_dicom("path/to/dicom", &config)?;
// Save to files
let saved_files = builder.save_to_files(&envelope, &files, "./tmp/output")?;Extract metadata from DICOM files:
use jmix_rs::dicom::DicomProcessor;
let processor = DicomProcessor::new();
let metadata = processor.process_dicom_folder("path/to/dicom", None)?;
println!("Extracted {} instances", metadata.instance_count);Create a configuration file for your JMIX envelope:
{
"version": "1.0",
"sender": {
"name": "Healthcare Provider",
"id": "org:provider.123",
"contact": "admin@provider.com"
},
"patient": {
"name": "John Doe",
"id": "PAT12345",
"dob": "1985-03-15"
}
}use jmix_rs::{
builder::JmixBuilder,
config::Config,
types::{Envelope, Manifest, Metadata, Audit, Files},
dicom::DicomProcessor,
validation::ValidationConfig,
package_validation::{validate_package, ValidationOptions}
};The JmixBuilder provides a high-level API for creating JMIX envelopes:
// Basic builder
let builder = JmixBuilder::new();
// With encryption only
let builder = JmixBuilder::with_encryption(recipient_public_key)?;
// With signatures only
let builder = JmixBuilder::with_jws_signing()?;
// With complete security (encryption + signatures + assertions)
let builder = JmixBuilder::with_complete_security()?;Validate existing JMIX packages:
use jmix_rs::package_validation::{validate_package, ValidationOptions};
let options = ValidationOptions {
validate_schema: true,
schema_dir: Some("../jmix/schemas".to_string()),
verify_assertions: true,
recipient_secret_key_path: Some("./tmp/key.pem".to_string()),
};
let report = validate_package("./tmp/package.jmix", &options)?;
println!("Validation result: {:?}", report);use jmix_rs::error::JmixError;
match result {
Ok(envelope) => println!("Success!"),
Err(JmixError::Validation(e)) => eprintln!("Schema validation error: {}", e),
Err(JmixError::Dicom(e)) => eprintln!("DICOM processing error: {}", e),
Err(JmixError::Encryption(e)) => eprintln!("Encryption error: {}", e),
Err(JmixError::Jws(e)) => eprintln!("Signing error: {}", e),
Err(JmixError::Assertion(e)) => eprintln!("Assertion error: {}", e),
Err(e) => eprintln!("Other error: {}", e),
}For large DICOM datasets, you can use performance flags to optimize processing:
// Skip SHA-256 hashing for faster processing
let (envelope, files) = builder.build_from_dicom_with_options(
&dicom_path,
&config,
true, // skip_hashing
false // skip_listing
)?;
// Skip both hashing and file listing for maximum speed
let (envelope, files) = builder.build_from_dicom_with_options(
&dicom_path,
&config,
true, // skip_hashing
true // skip_listing
)?;
// Save with same performance flags
builder.save_to_files_with_options(
&envelope,
&files,
&output_dir,
true, // skip_hashing
true // skip_listing
)?;See Performance Optimization Guide for detailed information.
Configure JSON Schema validation for JMIX packages:
use jmix_rs::validation::ValidationConfig;
// Configure schema directory
let validation_config = ValidationConfig::new(
Some("../jmix/schemas".to_string())
)?;
// Validate envelope components
validation_config.validate_manifest(&envelope.manifest)?;
validation_config.validate_metadata(&envelope.metadata)?;
validation_config.validate_audit(&envelope.audit)?;Schema resolution order:
ValidationConfig::new(Some(path))- Explicit pathJMIX_SCHEMA_DIRenvironment variable../jmix/schemas(default)
- AES-256-GCM: Authenticated encryption with 256-bit keys
- Curve25519: Elliptic curve Diffie-Hellman key exchange
- Ed25519: Elliptic curve digital signatures (JWS standard)
- SHA-256: Deterministic payload hashing for integrity verification
- Ephemeral keys: Base64-encoded ephemeral public key, IV, and auth tag
JMIX-RS uses deterministic SHA-256 payload hashing:
- Unencrypted: Hash computed over
payload/directory contents - Encrypted: Hash computed over plaintext TAR before encryption
- Format:
sha256:<hex>stored inmanifest.security.payload_hash
The library includes a command-line tool for validating and working with JMIX packages:
# Install from crates.io
cargo install jmix-rs
# Or build from source
cargo build --release
# Binary at: target/release/jmix# Validate a JMIX package
jmix validate ./tmp/package.jmix
# Validate with schema checking
jmix validate ./tmp/package.jmix --validate-schema
# Decrypt an encrypted package
jmix decrypt ./tmp/encrypted.jmix --key ./tmp/key.pem --out ./tmp/output
# JSON output for automation
jmix validate ./tmp/package.jmix --jsonFor detailed CLI documentation, run jmix --help.
- π Developer Guide - Contributing and development setup
- β‘ Performance Optimization - Large dataset handling
- π§ͺ Testing Guide - Test suite documentation
- π Changelog - Release history and changes
- π API Documentation - Rust library docs
This project is licensed under the Apache 2.0 License.