Skip to main content

commit_version

Function commit_version 

Source
pub fn commit_version(
    path: &Path,
    new_rules: &[u8],
    options: &CommitOptions<'_>,
    registry: &KeyRegistry,
) -> Result<CommitResult>
Expand description

Commit a new version with updated rules to an existing AION file

This operation:

  1. Loads and parses the existing file
  2. Verifies the existing signature chain
  3. Encrypts the new rules
  4. Creates a new version entry linked to the previous version
  5. Signs the new version with the author’s key
  6. Writes the updated file atomically

§Arguments

  • path - Path to the existing AION file
  • new_rules - The new rules content to commit
  • options - Commit options including author and signing key

§Returns

  • Ok(CommitResult) - On success, contains the new version number and hashes
  • Err(AionError) - On failure

§Errors

  • AionError::FileReadError - Cannot read the file
  • AionError::InvalidFormat - File format is invalid
  • AionError::SignatureVerificationFailed - Existing signature chain is invalid
  • AionError::VersionOverflow - Version number would overflow u64
  • AionError::FileWriteError - Cannot write the updated file

§Example

use aion_context::operations::{commit_version, CommitOptions};
use aion_context::crypto::SigningKey;
use aion_context::types::AuthorId;
use std::path::Path;

let signing_key = SigningKey::generate();
let options = CommitOptions {
    author_id: AuthorId::new(50001),
    signing_key: &signing_key,
    message: "Updated rules",
    timestamp: None,
};

// let result = commit_version(
//     Path::new("rules.aion"),
//     b"new rules content",
//     &options,
// )?;
// println!("Created version {}", result.version.as_u64());