hexz-common
Common utilities, configuration, and shared types for the Hexz ecosystem.
Overview
hexz-common centralizes configuration loading, error types, logging setup, and format constants that are shared across all Hexz crates (core, CLI, FUSE, server, loader). This ensures a single source of truth for defaults, wire formats, and runtime parameters.
This is an internal crate used by other Hexz components—it's not typically used directly by end users.
Architecture
hexz-common/
├── src/
│ ├── lib.rs # Public exports
│ ├── config.rs # Configuration loading and management
│ ├── constants.rs # Format constants (magic bytes, sizes, versions)
│ ├── error.rs # Shared error types (Error, Result)
│ ├── logging.rs # Logging initialization (tracing)
│ ├── crypto.rs # Cryptographic utilities
│ └── sign.rs # Ed25519 signing (optional feature)
Key Components
Configuration (config.rs)
Runtime parameter management for Hexz tools:
use Config;
// Load configuration (from env, files, defaults)
let config = load?;
// Access settings
println!;
println!;
Constants (constants.rs)
Format constants and wire format definitions:
use *;
// Magic bytes for format identification
assert_eq!;
// Header and block sizes
println!;
println!;
// Format version
println!;
These constants are used across all crates to ensure consistent on-disk layout.
Error Types (error.rs)
Shared error types using thiserror:
use ;
Common error variants:
Io(io::Error)- I/O errorsFormat(String)- Invalid format or corruptionCompression(String)- Compression/decompression failuresEncryption(String)- Encryption/decryption failuresInvalidParameter(String)- Invalid configuration
Logging (logging.rs)
Unified logging setup using tracing:
use logging;
Cryptographic Utilities (crypto.rs)
Password-based key derivation parameters:
use crypto;
// Key derivation for encryption
let salt = generate_salt;
let key = derive_key?;
Signing (sign.rs) - Optional Feature
Ed25519 signing for snapshot integrity (requires signing feature):
use ;
// Generate keypair
let keypair = generate;
// Sign data
let signature = sign;
// Verify signature
verify?;
Usage in Other Crates
Core Library
use ;
use *;
CLI Tool
use ;
Features
default: No features enabled by defaultsigning: Enable Ed25519 signing support
Build with signing:
Development
From the repository root:
# Build the common crate
# Run tests
# Build with all features
Constants Reference
Key constants defined in constants.rs:
| Constant | Value | Description |
|---|---|---|
MAGIC |
b"HEXZ" |
File format magic bytes |
FORMAT_VERSION |
1 |
Current format version |
HEADER_SIZE |
512 |
Header size in bytes |
DEFAULT_BLOCK_SIZE |
65536 |
Default compression block size (64KB) |
MAX_BLOCK_SIZE |
16777216 |
Maximum block size (16MB) |
DEFAULT_CACHE_SIZE |
1024 |
Default LRU cache size (blocks) |
These values affect on-disk format and must be coordinated across all crates.
See Also
- hexz-core - Core engine (uses common types)
- hexz-cli - CLI tool (uses config and logging)
- Project README - Main project overview