How tak-pesar/tgcrypto works
Main Components
• PHP Extension Layer: Represents the part that integrates with PHP. This includes the PHP code (like run-tests.php and any PHP-specific tests in the tests/ directory), which interacts with the extension.
• Rust Cryptography Library: The core cryptographic functions are implemented in Rust (files like src/lib.rs and managed via Cargo.toml). This serves as the underlying logic behind the PHP extension.
• Build & Integration Utilities: The install.sh script (and possibly the build.yml GitHub Actions file) shows the automated installation and continuous integration aspects.
• Testing Framework: The PHP scripts (run-tests.php and tests/test-00*.php) are used to run performance checks and validate functionality.
Relationships and Interactions
• PHP acts as the client that makes calls to the PHP extension.
• The PHP extension functions as a wrapper that forwards cryptographic function calls to the Rust library through an FFI layer (commonly using cbindgen or similar tooling to create the bridging code).
• The Rust library processes the cryptographic functions and returns the results back through the extension to PHP.
• The installation script (install.sh) integrates the building of the Rust library (using Cargo) with the PHP environment setup.
• Testing scripts validate that PHP correctly interacts with the underlying Rust logic and that performance meets expectations.
Important Architectural Patterns
• Language Interoperability / FFI: The design centers on bridging PHP and Rust, likely using a Foreign Function Interface (FFI) pattern.
• Layered Architecture: There is clear separation between the presentation/client layer (PHP), the extension layer (acting as a mediator) and the core logic layer (Rust library).
Relevant Technologies/Frameworks
• PHP for end-user code and tests.
• Rust for the actual cryptographic computations.
• Cargo for building and managing the Rust project.
• GitHub Actions (via .github/workflows/build.yml) for CI/CD integration.
• Unix shell scripting (install.sh) for installation and deployment.