|
1 | 1 | # Contributing |
2 | 2 |
|
3 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, |
4 | | -email, or any other method with the owners of this repository before making a change. |
| 4 | +email, or any other method with the owners of this repository before making a change. |
5 | 5 |
|
6 | 6 | Please note we have a code of conduct, please follow it in all your interactions with the project. |
7 | 7 |
|
| 8 | +## Architecture Overview |
| 9 | + |
| 10 | +### Feature-Gated Design |
| 11 | + |
| 12 | +This crate uses **mutually exclusive features by design**. The PASETO specification recommends choosing a single version per application. This architectural choice: |
| 13 | + |
| 14 | +- Minimizes binary size by only compiling required cryptographic dependencies |
| 15 | +- Enforces compile-time safety through intentionally conflicting trait implementations |
| 16 | +- Prevents version mixing that could introduce security vulnerabilities |
| 17 | + |
| 18 | +**Important:** `cargo build --all-features` **will fail**. This is intentional, not a bug. |
| 19 | + |
| 20 | +### Feature Combinations |
| 21 | + |
| 22 | +**Valid combinations:** |
| 23 | +```bash |
| 24 | +# Single version + purpose |
| 25 | +--features v4_local |
| 26 | +--features v4_public |
| 27 | +--features v1_local |
| 28 | + |
| 29 | +# Same version, both purposes |
| 30 | +--features "v4_local,v4_public" |
| 31 | + |
| 32 | +# Default (recommended) |
| 33 | +# Enables: batteries_included + v4_local + v4_public |
| 34 | +``` |
| 35 | + |
| 36 | +**Invalid combinations (will fail at compile time):** |
| 37 | +```bash |
| 38 | +# Multiple public features |
| 39 | +--features "v1_public,v2_public" # ❌ Trait conflict |
| 40 | +--features "v3_public,v4_public" # ❌ Trait conflict |
| 41 | + |
| 42 | +# All features |
| 43 | +--all-features # ❌ Enables conflicting features |
| 44 | +``` |
| 45 | + |
| 46 | +See [Issue #48](https://github.com/rrrodzilla/rusty_paseto/issues/48) for details. |
| 47 | + |
| 48 | +## Development Setup |
| 49 | + |
| 50 | +### Required Tools |
| 51 | + |
| 52 | +```bash |
| 53 | +# Install cargo-nextest (used by CI and local development) |
| 54 | +cargo install cargo-nextest |
| 55 | +``` |
| 56 | + |
| 57 | +### Testing |
| 58 | + |
| 59 | +**Match CI behavior** by testing each feature combination individually: |
| 60 | + |
| 61 | +```bash |
| 62 | +# Test individual features (matches CI matrix) |
| 63 | +cargo nextest run --no-default-features --features v1_local |
| 64 | +cargo nextest run --no-default-features --features v2_local |
| 65 | +cargo nextest run --no-default-features --features v3_local |
| 66 | +cargo nextest run --no-default-features --features v4_local |
| 67 | +cargo nextest run --no-default-features --features v1_public |
| 68 | +cargo nextest run --no-default-features --features v2_public |
| 69 | +cargo nextest run --no-default-features --features v3_public |
| 70 | +cargo nextest run --no-default-features --features v4_public |
| 71 | + |
| 72 | +# Test default features |
| 73 | +cargo nextest run |
| 74 | +``` |
| 75 | + |
| 76 | +**Do NOT use:** |
| 77 | +```bash |
| 78 | +cargo test --all-features # ❌ Will fail |
| 79 | +cargo nextest run --all-features # ❌ Will fail |
| 80 | +``` |
| 81 | + |
| 82 | +### Building |
| 83 | + |
| 84 | +```bash |
| 85 | +# Build with specific features |
| 86 | +cargo build --no-default-features --features v4_local |
| 87 | + |
| 88 | +# Build with default features |
| 89 | +cargo build |
| 90 | +``` |
| 91 | + |
| 92 | +### Linting |
| 93 | + |
| 94 | +```bash |
| 95 | +# Run clippy (zero tolerance for warnings) |
| 96 | +cargo clippy --all-targets --features v4_local -- -D warnings |
| 97 | +cargo clippy --all-targets --features v4_public -- -D warnings |
| 98 | + |
| 99 | +# Format code |
| 100 | +cargo fmt |
| 101 | +``` |
| 102 | + |
| 103 | +## Feature Architecture Layers |
| 104 | + |
| 105 | +The crate has three architectural layers: |
| 106 | + |
| 107 | +1. **`core`** - Bare PASETO cryptographic primitives (no serde, minimal deps) |
| 108 | +2. **`generic`** - Customizable builder/parser foundation (adds serde, claims) |
| 109 | +3. **`batteries_included`** - Ready-to-use builders with sensible defaults |
| 110 | + |
| 111 | +Version/purpose combinations: |
| 112 | +- `v1_local`, `v2_local`, `v3_local`, `v4_local` - Symmetric encryption |
| 113 | +- `v1_public`, `v2_public`, `v3_public`, `v4_public` - Asymmetric signing |
| 114 | + |
| 115 | +## Contribution Guidelines |
| 116 | + |
| 117 | +### Before Submitting |
| 118 | + |
| 119 | +1. **Discuss first** - Open an issue before starting work |
| 120 | +2. **Test all affected features** - Run the feature-specific tests shown above |
| 121 | +3. **Check clippy** - Zero warnings policy |
| 122 | +4. **Format code** - Run `cargo fmt` |
| 123 | +5. **Update docs** - If adding features or changing public APIs |
| 124 | + |
| 125 | +### Pull Request Process |
| 126 | + |
| 127 | +1. Ensure tests pass for all affected feature combinations |
| 128 | +2. Update CHANGELOG.md if applicable |
| 129 | +3. Follow conventional commit format: `type(scope): description` |
| 130 | +4. Reference related issues with `Closes #123` or `Addresses #123` |
| 131 | + |
| 132 | +### Understanding Test Failures |
| 133 | + |
| 134 | +If your PR fails CI with trait conflicts: |
| 135 | +- Check if you're enabling multiple public features |
| 136 | +- Verify your changes don't break feature isolation |
| 137 | +- Test locally with the exact feature combination that failed |
| 138 | + |
| 139 | +### Common Mistakes |
| 140 | + |
| 141 | +❌ **Don't:** Try to make `--all-features` work |
| 142 | +✅ **Do:** Understand this is intentional architectural design |
| 143 | + |
| 144 | +❌ **Don't:** Test only with default features |
| 145 | +✅ **Do:** Test all affected feature combinations individually |
| 146 | + |
| 147 | +❌ **Don't:** Add dependencies without feature gates |
| 148 | +✅ **Do:** Make new dependencies optional and feature-gated |
| 149 | + |
| 150 | +❌ **Don't:** Implement traits that conflict across versions |
| 151 | +✅ **Do:** Keep version-specific code isolated |
| 152 | + |
| 153 | +## Questions? |
| 154 | + |
| 155 | +Open an issue or reach out to the maintainers before starting work. |
0 commit comments