Improves the test coverage of the project and adds examples for coverage reports.
- Increases the test coverage of the `cmd/trix` package from 67.7% to 78.1%.
- Increases the test coverage of the `pkg/crypt` package from 96.2% to 98.7%.
- Adds tests for the `examples` to ensure they run without errors.
- Adds a new example that demonstrates how to generate and interpret a coverage report.
Adds a comprehensive set of examples to demonstrate the library's features.
- Breaks out the existing `examples/main.go` into separate, well-named files.
- Adds new examples for hashing, checksums, RSA, and PGP.
- The PGP examples cover key generation, encryption/decryption, signing/verification, and symmetric encryption.
- Removes the old `examples/main.go` file and formats the new example files.
- Refactors the `lthn` keymap test to be thread-safe by using a mutex and `t.Cleanup` to ensure state is properly restored.
- Corrects the `mockReader` implementation in the `trix` tests to adhere to the `io.Reader` interface contract.
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.
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.
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.
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.
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.
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.
This commit introduces a new, generic `.trix` file format, which is decoupled from any specific encryption algorithm.
The format is defined in `docs/trix_format.md` and consists of a magic number, version, a flexible JSON header, and a raw data payload.
A new `trix` Go package is implemented to handle the encoding and decoding of this format. Unit tests are included to verify the implementation.
An example file, `examples/main.go`, is also added to demonstrate how to use the `.trix` container to store data encrypted with the `chachapoly` package, showcasing the intended decoupled design.