Rust Implementation
The Rust implementation provides a safe, zero-copy API for AIOSchema v0.5.5. 30 unit tests, 14/14 cross-verification vectors passing.
Requirements
- Rust 2021 edition
- Cargo
Install
git clone https://github.com/aioschema/aioschema.git
cd aioschema/implementations/rust
Add to Cargo.toml:
[dependencies]
aioschema = { path = "../implementations/rust" }
Quick Start
use aioschema::{verify_manifest, Manifest, VerifyOptions};
use std::fs;
fn main() {
// Read asset and manifest
let asset = fs::read("photo.jpg").unwrap();
let manifest: Manifest = serde_json::from_str(
&fs::read_to_string("photo.jpg.aios.json").unwrap()
).unwrap();
// Verify
let result = verify_manifest(
&asset,
&manifest,
&VerifyOptions::default()
).unwrap();
println!("{}", result.success); // true
println!("{:?}", result.match_type); // Some(Hard)
}
With signing
use aioschema::VerifyOptions;
use ed25519_dalek::SigningKey;
use rand::rngs::OsRng;
// Generate keypair
let signing_key = SigningKey::generate(&mut OsRng);
let verifying_key = signing_key.verifying_key();
// Verify with public key bytes
let result = verify_manifest(&asset, &manifest, &VerifyOptions {
public_key: Some(verifying_key.as_bytes()),
..Default::default()
}).unwrap();
Run Tests
# All tests (30 unit tests + 14 CV vectors)
cargo test
# Unit tests only
cargo test --test unit_tests
# Cross-verification vectors only
cargo test --test cross_verify
# With custom vectors path
AIOSCHEMA_VECTORS=/path/to/cross_verify_vectors.json cargo test
API Summary
| Function | Description |
|---|---|
verify_manifest(data, manifest, opts) |
Verify asset bytes against a manifest |
compute_hash(data, algorithm) |
Compute a prefixed hash string |
canonical_json(value) |
Deterministic sorted-key JSON as bytes |
canonical_core_fields(core) |
Canonical bytes of Core Block fields |
safe_equal(a, b) |
Timing-safe string comparison |
parse_hash_prefix(value) |
Parse alg-hexdigest into components |
Full contracts: API.md