Add Deterministic AEAD Encryption and EncryptedBinaryField#5
Merged
Conversation
…ary fields Major improvements from PR #2: 1. **Deterministic AEAD Encryption**: - Added DeterministicEncryptedField base class - Added deterministic variants of all field types (Text, Char, Email, Integer, Date, DateTime) - Supports searchable encryption with exact lookups - Graceful fallback when deterministic AEAD is not available 2. **EncryptedBinaryField**: - New field type for storing binary data - Preserves raw bytes without string conversion - Useful for storing keysets, images, or other binary data 3. **Memory Leak Fix**: - Replaced lru_cache with Django's cached_property - Fixes memory leaks when using lru_cache on instance methods - All primitives now properly cached without memory issues 4. **Refactored Key Management**: - New KeysetManager class centralizes keyset handling - Better separation of concerns - Improved error handling and validation - Lazy loading of keyset handles 5. **Enhanced Lookup Handling**: - Deterministic fields support exact lookups via 'in' operator - Better error messages for unsupported operations - Maintains backward compatibility with existing fields 6. **Improved Error Handling**: - Better error messages for configuration issues - Graceful handling of missing deterministic AEAD support - Clear guidance for users on keyset requirements All original functionality preserved and tested. New features are ready for use when proper keysets are configured.
- Add deterministic AEAD support using tinkey-generated keyset - Implement EncryptedBinaryField for binary data encryption - Add DeterministicEncryptedField and variants (TextField, CharField, etc.) - Create proper test models for new field types - Add deterministic keyset configuration - All existing tests still pass - Deterministic encryption produces identical ciphertext for same plaintext - Binary field correctly handles binary data and None values
- Update all test methods to use existing test models instead of dynamic creation - Fix EncryptedBinaryField to allow null values - Fix deterministic lookup to return single encrypted value instead of list - Add missing test models for deterministic fields - Fix KeysetManager test to use appropriate keysets - All 43 tests now pass with 89% coverage - Black formatting applied
- Run isort to fix import sorting in all files - Remove unused imports from test_new_features.py - Add back required DeterministicEncryptedTextField import - All linting checks now pass: isort, black, flake8 - All 43 tests still passing with 89% coverage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements the features from the original PR #2, adding deterministic AEAD encryption and binary field support to django-tink-fields.
Features Added
🔐 Deterministic AEAD Encryption
�� EncryptedBinaryField
🛠️ Technical Improvements
Implementation Details
Keyset Generation
org.kohsuke.args4j.CmdLineException: Argument "command" is required
[add-key | convert-keyset | : Command to run
create-keyset | create-public-keyset
| delete-key | destroy-key |
disable-key | enable-key |
list-keyset | list-key-templates |
rotate-keyset | promote-key] to generate proper deterministic AEAD keyset
Field Architecture
Database Integration
Testing
Usage Examples
Security Notes
Breaking Changes
None - this is a purely additive feature that maintains full backward compatibility.
Related
Implements features from PR #2 with modern codebase improvements.