Commit graph

98 commits

Author SHA1 Message Date
google-labs-jules[bot]
e625b4b4e1 test(enchantrix): increase test coverage for sigils
- Refactors sigil tests into a dedicated `sigils_test.go` file.
- Adds a comprehensive data-driven test for all hash sigils.
- Adds a test for error handling in the `HashSigil`.
2025-11-02 23:41:40 +00:00
5f4682953b
Merge pull request #26 from Snider/fix-go-test-coverage
refactor(tests): Co-locate tests with source code
2025-11-02 23:18:53 +00:00
6c3b1069ce
Merge branch 'main' into fix-go-test-coverage 2025-11-02 23:14:44 +00:00
google-labs-jules[bot]
d7c738bbd3 refactor(tests): Co-locate tests with source code
Moves all test files from the `tdd/` directory to their corresponding `pkg/` subdirectories. This aligns with standard Go project structure and simplifies the test coverage workflow.

- Moves `tdd/crypt/crypt_test.go` to `pkg/crypt/`
- Moves `tdd/enchantrix/enchantrix_test.go` to `pkg/enchantrix/`
- Moves `tdd/trix/trix_test.go` to `pkg/trix/`
- Simplifies the `Taskfile.yml` to use a standard `go test` command.
- Removes the now-obsolete `tdd/` directory.
- Adds generated coverage files to `.gitignore`.
2025-11-02 23:09:24 +00:00
0f8917e578
Merge pull request #25 from Snider/fix-go-test-coverage
fix(tests): Configure test coverage for tdd/ directory
2025-11-02 22:39:45 +00:00
google-labs-jules[bot]
4f83430aa4 fix(tests): Configure test coverage for tdd/ directory
Updates the `Taskfile.yml` to include the `tdd/` directory's tests in the coverage calculation for the `pkg/` directory by using the `-coverpkg` flag. This ensures that the coverage reports accurately reflect the state of the codebase.

Also, this commit includes the necessary environment configuration to fix a known issue in Go 1.25 that caused the `go: no such tool "covdata"` error.
2025-11-02 22:38:00 +00:00
0e04f21686
Merge pull request #24 from Snider/test-internal-functions
feat(tests): Add internal tests for private functions
2025-11-02 22:15:26 +00:00
Snider
b13694bcc2
Add Codecov badge to README
Added Codecov badge to README for coverage tracking.
2025-11-02 22:14:04 +00:00
Snider
1a114d1f64
Integrate Codecov for coverage report uploads
Add step to upload coverage reports to Codecov
2025-11-02 22:09:54 +00:00
google-labs-jules[bot]
c286a82e89 feat(tests): Add internal tests for private functions
Adds `_internal_test.go` files to test unexported functions in the `crypt` and `lthn` packages, improving overall test coverage.

- Adds tests for the `ensureRSA` private function in `pkg/crypt/crypt.go`.
- Adds tests for the `createSalt` private function in `pkg/crypt/std/lthn/lthn.go`.

These changes align with the project's TDD methodology and follow the `_Good`, `_Bad`, `_Ugly` testing structure.
2025-11-02 21:23:13 +00:00
Snider
8e9a7d71fa
Merge pull request #23 from Snider/feature-add-tdd-tests
feat: Add comprehensive TDD tests for crypt package
2025-11-02 19:49:41 +00:00
google-labs-jules[bot]
b4ef069ee6 fix: Correct test logic and revert breaking API changes
This commit addresses feedback from the code review:

- Updates the `TestChecksum_Bad` test in `tdd/trix/trix_test.go` to use `assert.ErrorIs` for consistent error handling.
- Reverts the breaking API change to `EncryptRSA` and `DecryptRSA` in `pkg/crypt/crypt.go` by re-introducing the `label` parameter to the public-facing functions.
- Updates the tests and examples to match the reverted API.
- Fixes a build error in `tdd/crypt/crypt_test.go` by re-introducing a necessary variable.
2025-11-02 18:46:36 +00:00
google-labs-jules[bot]
aca835874a fix: Correct test logic and revert breaking API changes
This commit addresses feedback from the code review:

- Updates the `HeaderTooLarge` test in `tdd/trix/trix_test.go` to correctly verify that `trix.Decode` returns `trix.ErrHeaderTooLarge`.
- Removes local `service` variable shadowing in `tdd/crypt/crypt_test.go` to use the package-level variable.
- Reverts the breaking API change to `EncryptRSA` and `DecryptRSA` in `pkg/crypt/crypt.go` by removing the `label` parameter from the public-facing functions.
- Updates the tests and examples to match the reverted API.
2025-11-02 18:19:58 +00:00
google-labs-jules[bot]
0e50aee481 feat: Consolidate and enhance tests for enchantrix and trix packages
This commit consolidates and enhances the tests for the `enchantrix` and `trix` packages, moving them into the `tdd/` directory to improve test coverage and organization.

- Consolidates existing tests from `pkg/enchantrix/` and `pkg/trix/` into new, more comprehensive test suites in `tdd/enchantrix/` and `tdd/trix/` respectively.
- Expands the test suites to include more "Bad" and "Ugly" scenarios.
- Deletes the original test files from `pkg/enchantrix/` and `pkg/trix/` to avoid redundancy.
- Organizes the `tdd/` directory with subdirectories for each package to prevent Go package conflicts.
2025-11-02 17:41:44 +00:00
google-labs-jules[bot]
8cf1df9495 feat: Add comprehensive TDD tests for crypt package
This commit introduces a new `tdd/` directory and adds a comprehensive test suite for the `crypt` package, covering hashing, checksums, and RSA functions.

- Adds a new `tdd/crypt_test.go` file with tests for all functions in the `crypt` package, following the "Good, Bad, Ugly" methodology.
- Deletes the old `pkg/crypt/crypt_test.go` to avoid redundancy.
- Fixes a build error in `examples/main.go` related to an updated function signature.
2025-11-02 17:23:36 +00:00
Snider
56f28c1ea5
Merge pull request #21 from Snider/refactor-rsa-improvements
Refactor(crypt): Improve RSA safety and flexibility
2025-11-02 16:00:29 +00:00
Snider
f54a7fc067
Merge pull request #22 from Snider/feat-expand-examples
feat: Expand examples to demonstrate all features
2025-11-02 14:11:30 +00:00
Snider
e9f0e9f43f
Remove newline from success message 2025-11-02 13:44:29 +00:00
google-labs-jules[bot]
af9a6076c4 feat: Expand examples to demonstrate all features
Expanded `examples/main.go` to fully demonstrate the functionality of the `crypt`, `enchantrix`, and `trix` packages.

- Restructured the main example file into distinct functions for each feature set (`demoTrix`, `demoHashing`, `demoChecksums`, `demoRSA`, `demoSigils`).
- Implemented a comprehensive `demoTrix` that showcases a chain of multiple sigils (`json-indent`, `gzip`, `base64`, `reverse`), checksum functionality, and the full Pack/Unpack workflow.
- Added a `demoHashing` function that iterates through all supported hashing algorithms.
- Added a `demoChecksums` function that demonstrates the Luhn and Fletcher algorithms.
- Added a `demoRSA` function that shows the complete RSA workflow from key generation to decryption.
- Added a `demoSigils` function to demonstrate sigil transformations independently.
- Fixed a bug in the Trix demo verification logic related to JSON indentation.
2025-11-02 12:22:44 +00:00
Snider
234157b73a
Merge pull request #17 from Snider/feature-openpgp-implementation
feat: Implement OpenPGP Service
2025-11-02 03:06:35 +00:00
google-labs-jules[bot]
e7aeb3c8b8 Refactor(crypt): Improve RSA safety and flexibility
This commit introduces several improvements to the RSA implementation:

- Preserves zero-value service safety by lazily initializing the RSA service in `pkg/crypt/crypt.go`.
- Enforces a minimum RSA key size of 2048 bits in `pkg/crypt/std/rsa/rsa.go` to prevent the generation of insecure keys.
- Exposes the OAEP label parameter in `Encrypt` and `Decrypt` functions, allowing for more advanced use cases.
- Adds a test case to verify that `GenerateKeyPair` correctly rejects key sizes below the new minimum.
2025-11-02 03:06:04 +00:00
Snider
11a2c85a33
#20 from Snider/feature-improve-trix-tests
Feature improve trix tests
2025-11-02 02:54:20 +00:00
google-labs-jules[bot]
f51ef1b52e feat: Add fuzz test and fix OOM vulnerability
This commit introduces a fuzz test for the `Decode` function in the `trix` package. This test immediately uncovered a critical out-of-memory (OOM) vulnerability.

-   Adds a new fuzz test, `FuzzDecode`, to `pkg/trix/fuzz_test.go` to continuously test the `Decode` function with a wide range of malformed inputs.
-   Fixes a denial-of-service vulnerability where a malicious input could specify an extremely large header length, causing the application to crash due to an out-of-memory error.
-   Introduces a `MaxHeaderSize` constant (16MB) and a check in the `Decode` function to ensure that the header length does not exceed this limit.
-   Adds a new error, `ErrHeaderTooLarge`, to provide clear feedback when the header size limit is exceeded.
2025-11-02 02:21:21 +00:00
google-labs-jules[bot]
3f39b81518 feat: Implement streaming API for Trix encoding/decoding
This commit introduces a streaming API to the `trix` package, making it more memory-efficient for large payloads.

-   Adds `EncodeTo(io.Writer)` and `DecodeFrom(io.Reader)` functions to handle streaming data.
-   Refactors the existing `Encode` and `Decode` functions to be wrappers around the new streaming API, ensuring backward compatibility.
-   Adds a specific `ErrInvalidHeaderLength` error to the `Decode` function to provide better error feedback.
-   Includes a comprehensive set of "Good, Bad, Ugly" tests for the new streaming functionality, including tests for failing readers and writers.
2025-11-02 01:40:08 +00:00
google-labs-jules[bot]
6168a9d7fe refactor: Improve Trix tests and error handling
This commit introduces several improvements to the `trix` package, focusing on test coverage and robustness.

-   Adds a specific `ErrInvalidHeaderLength` error to the `Decode` function, providing clearer feedback when the header length is invalid.
-   Introduces a `TestPackUnpack_Ugly` test to ensure that calling `Pack` with a `nil` payload is handled gracefully.
-   Simplifies the `TestChecksum_Ugly` test by manually constructing a corrupted byte slice, making the test more direct and easier to understand.
-   Adds a new "Bad" test case to verify that the `Decode` function correctly handles invalid version numbers.
2025-11-02 01:11:20 +00:00
Snider
3ad62c3be3
Merge pull request #18 from Snider/feature-enchantrix-sigils
Implement Go Encoding Types as Sigils
2025-10-31 20:03:50 +00:00
Snider
60ce78a52c
Merge pull request #19 from Snider/coderabbitai/docstrings/83e8174
📝 Add docstrings to `feature-openpgp-implementation`
2025-10-31 20:00:37 +00:00
coderabbitai[bot]
186b75c402
📝 Add docstrings to feature-openpgp-implementation
Docstrings generation was requested by @Snider.

* https://github.com/Snider/Enchantrix/pull/17#issuecomment-3473285782

The following files were modified:

* `pkg/crypt/crypt.go`
* `pkg/crypt/std/rsa/rsa.go`
2025-10-31 19:59:43 +00:00
google-labs-jules[bot]
9dcb399988 feat: Implement Go encoding types as Sigils
This commit introduces a new `enchantrix` package that provides a flexible and powerful way to transform data using a "Sigil" interface. The package includes implementations for various encoding types (hex, base64, gzip, json) and a comprehensive set of cryptographic hash functions.

The `trix` package has been refactored to use the new `enchantrix` package, and its API has been simplified to use string identifiers for Sigils, making it easier to use and decoupling it from the implementation details of the `enchantrix` package.

All new functionality is fully tested, and the existing tests have been updated to reflect the API changes.
2025-10-31 15:19:30 +00:00
google-labs-jules[bot]
83e8174634 feat: Implement RSA service
This commit introduces a standard RSA implementation in `pkg/crypt/std/rsa`.

The new `rsa.Service` provides a clean API for RSA operations, including:
- Key pair generation
- Encryption and decryption of data

The implementation uses the standard `crypto/rsa` package and follows best practices, including OAEP padding. The main `crypt.Service` has been updated to integrate and expose this new functionality.

This work was done to validate the build environment, and the tests for this implementation pass successfully, confirming that the previous testing issues were isolated to the OpenPGP library.
2025-10-31 14:46:28 +00:00
google-labs-jules[bot]
52aa833a2f feat: Implement OpenPGP service
This commit introduces a full OpenPGP implementation in `pkg/crypt/std/openpgp`, using the ProtonMail `go-crypto` library.

The new `openpgp.Service` provides a clean, Web3-friendly API for PGP operations, including:
- Key pair generation
- Subkey management
- Encryption and decryption of messages
- Signing and verification of messages

The implementation is based on the user's `Core` repository and uses file-based key management. The main `crypt.Service` has been updated to integrate and expose this new functionality.
2025-10-31 14:13:57 +00:00
Snider
f88d37cb4a
Merge pull request #15 from Snider/feat-refactor-crypt-service
feat: Add Checksums and Asymmetrical Sigils to Trix Container
2025-10-31 03:08:57 +00:00
Snider
e48e38419b
Merge branch 'main' into feat-refactor-crypt-service 2025-10-31 03:08:12 +00:00
google-labs-jules[bot]
d66acec498 feat: Add checksums and asymmetrical sigils to Trix container
This commit enhances the Trix container with two new features for improved data integrity and flexibility:

1.  **Configurable Checksums:**
    - The `Trix` struct now has a `ChecksumAlgo` field to specify a hash algorithm.
    - If set, `Encode` computes a checksum of the payload and adds it to the header.
    - `Decode` verifies this checksum, returning an error if it doesn't match, ensuring data integrity during transit.

2.  **Asymmetrical Sigils:**
    - The `Sigils` field has been replaced with `InSigils` and `OutSigils` to support different transformation chains for packing and unpacking.
    - If `OutSigils` is not set, `Unpack` defaults to using the `InSigils` chain to maintain the previous symmetrical behavior.

These features make the `Trix` container a more robust and self-verifying format for internal data transfer.
2025-10-31 02:55:58 +00:00
Snider
3268e4a6e7
Merge pull request #14 from Snider/feat-refactor-crypt-service
feat: Implement Pre-Encryption Sigil Packing for Enhanced Security
2025-10-31 02:41:48 +00:00
Snider
ea3918559f
Merge branch 'main' into feat-refactor-crypt-service 2025-10-31 02:41:09 +00:00
google-labs-jules[bot]
519e5edd68 feat: Implement pre-encryption sigil packing for enhanced security
This commit introduces a more secure sigil workflow by separating the transformation logic from the serialization logic.

- The `Trix` struct now has `Pack()` and `Unpack()` methods to apply sigil transformations directly to the payload.
- The `Encode()` and `Decode()` functions are now solely responsible for serialization, no longer handling sigil logic.
- The recommended workflow is to `Pack()` the data (obfuscating it), then encrypt it, and finally `Encode()` the container. This prevents cleartext from being sent to the CPU's encryption instructions.

This change enhances security by adding a user-defined obfuscation layer before the encryption process begins, true to the spirit of Enchantrix.
2025-10-31 02:37:55 +00:00
Snider
57f4cec854
Merge pull request #13 from Snider/feat-refactor-crypt-service
feat: Implement Good, Bad, and Ugly testing strategy
2025-10-31 02:24:08 +00:00
Snider
320beb53f0
Merge branch 'main' into feat-refactor-crypt-service 2025-10-31 02:22:33 +00:00
google-labs-jules[bot]
f7587b2471 feat: Introduce sigil transformers for trix containers
This commit introduces the concept of "sigils," which are programmable, pure-function transformers that can be applied to a Trix container's payload.

- A `Sigil` interface with `In` and `Out` methods is defined in the `trix` package.
- The `Trix` struct now includes a `Sigils` field to attach a chain of transformers.
- The `Encode` function applies the `In` transformations before encoding the payload.
- The caller is responsible for applying the `Out` transformations after decoding.

This new feature provides a flexible and extensible data pipeline for `Trix` containers.

The implementation is fully tested with the Good, Bad, and Ugly testing strategy.
2025-10-31 02:20:59 +00:00
google-labs-jules[bot]
d5ae9a44e1 feat: Implement Good, Bad, and Ugly testing strategy
This commit refactors the test suites for the `crypt` and `trix` packages to follow the Good, Bad, and Ugly testing strategy.

- `_Good` tests cover the ideal "happy path" scenarios.
- `_Bad` tests cover expected failure scenarios with well-formed but invalid inputs.
- `_Ugly` tests cover malicious or malformed inputs designed to cause crashes or panics.

This new testing structure makes the test suite more organized, comprehensive, and robust.

Additionally, this commit includes a bug fix for the `Luhn` function, which now correctly handles empty and single-digit strings.
2025-10-31 02:03:33 +00:00
Snider
82c1df8f5b
Merge pull request #12 from Snider/feat-refactor-crypt-service
feat: Make trix magic number configurable
2025-10-31 01:56:02 +00:00
Snider
9c247d6322
Merge branch 'main' into feat-refactor-crypt-service 2025-10-31 01:55:28 +00:00
google-labs-jules[bot]
1c2d667b49 feat: Make trix magic number configurable
This commit makes the magic number in the trix file format configurable.

- The `Encode` and `Decode` functions in the `trix` package now accept a `magicNumber` string as a parameter.
- The example in `examples/main.go` has been updated to demonstrate the use of the new configurable magic number.
- The tests for the `trix` package have been updated to verify the new functionality, including tests for invalid magic numbers.
2025-10-31 01:53:49 +00:00
Snider
505b978fb0
Merge pull request #11 from Snider/feat-refactor-crypt-service
Refactor: Complete Project Restructuring
2025-10-31 01:42:28 +00:00
Snider
f3d0ce9e07
Merge branch 'main' into feat-refactor-crypt-service 2025-10-31 01:41:19 +00:00
google-labs-jules[bot]
edaaf0f0c9 refactor: Complete project restructuring
This commit finalizes the project restructuring into a Core-compatible service.

- The `crypt` package is now a service with methods instead of standalone functions.
- Cryptographic implementations (`lthn`, `chachapoly`, `rsa`) are now in `pkg/crypt/std`.
- The `trix` package has been moved to `pkg/trix`.
- The `rootfs` components have been removed to decouple the library from storage.
- All import paths have been updated to reflect the new structure.
- A `Taskfile.yml` has been added for managing common tasks.
2025-10-31 01:40:49 +00:00
Snider
6df419ba18
Delete .ideas directory 2025-10-31 01:37:00 +00:00
Snider
4211f0fdac
Merge pull request #10 from Snider/feat-refactor-crypt-service
Refactor: Restructure Crypt Service and Decouple from Storage
2025-10-31 01:36:02 +00:00
google-labs-jules[bot]
2ff894327b refactor: Restructure crypt service and decouple from storage
This commit restructures the `crypt` service to be more modular and decoupled from storage concerns.

- The standard cryptographic implementations (`lthn`, `chachapoly`, `rsa`) have been moved to the `pkg/crypt/std` directory.
- The `rootfs` components have been removed to decouple the library from storage.
- Import paths have been updated to reflect the new structure.
2025-10-31 01:34:24 +00:00