Files
motia-iii/services/blake3_utils.py
bsiggel 1ffc37b0b7 feat: Add Advoware History and Watcher services for document synchronization
- Implement AdvowareHistoryService for fetching and creating history entries.
- Implement AdvowareWatcherService for file operations including listing, downloading, and uploading with Blake3 hash verification.
- Introduce Blake3 utility functions for hash computation and verification.
- Create document sync cron step to poll Redis for pending Aktennummern and emit sync events.
- Develop document sync event handler to manage 3-way merge synchronization for Akten, including metadata updates and error handling.
2026-03-25 21:24:31 +00:00

48 lines
1012 B
Python

"""
Blake3 Hash Utilities
Provides Blake3 hash computation for file integrity verification.
"""
from typing import Union
def compute_blake3(content: bytes) -> str:
"""
Compute Blake3 hash of content.
Args:
content: File bytes
Returns:
Hex string (lowercase)
Raises:
ImportError: If blake3 module not installed
"""
try:
import blake3
except ImportError:
raise ImportError(
"blake3 module not installed. Install with: pip install blake3"
)
hasher = blake3.blake3()
hasher.update(content)
return hasher.hexdigest()
def verify_blake3(content: bytes, expected_hash: str) -> bool:
"""
Verify Blake3 hash of content.
Args:
content: File bytes
expected_hash: Expected hex hash (lowercase)
Returns:
True if hash matches, False otherwise
"""
computed = compute_blake3(content)
return computed.lower() == expected_hash.lower()