pub fn init_file(
path: &Path,
initial_rules: &[u8],
options: &InitOptions<'_>,
) -> Result<InitResult>Expand description
Initialize a new AION file with genesis version
Creates a new AION file with:
- Unique file ID
- Genesis version (version 1)
- Encrypted rules
- Cryptographic signature
- Audit trail entry
§Arguments
path- Path where the file will be createdinitial_rules- Initial rules content (plaintext)options- Initialization options (author, key, message)
§Returns
Returns InitResult containing file ID and version information.
§Errors
Returns error if:
- File already exists at the path
- Rules encryption fails
- File write fails
- I/O error occurs
§Example
use aion_context::operations::{init_file, InitOptions};
use aion_context::crypto::SigningKey;
use aion_context::types::AuthorId;
use std::path::Path;
let signing_key = SigningKey::generate();
let options = InitOptions {
author_id: AuthorId::new(50001),
signing_key: &signing_key,
message: "Initial policy version",
timestamp: None, // Use current time
};
let initial_rules = b"fraud_threshold: 1000\nrisk_level: medium";
// let result = init_file(
// Path::new("policy.aion"),
// initial_rules,
// &options,
// )?;
// println!("Created file {} with version {}", result.file_id.as_u64(), result.version.as_u64());