Skip to content

Conversation

StefanPrintezis
Copy link

Summary

This PR improves thread safety and concurrency support by making SignedDataVerifier and ChainVerifier conform to the Sendable protocol. The main change involves replacing a mutable var for certificate caching with a dedicated CacheManager actor to ensure thread-safe certificate caching operations.

Changes

Core Changes

  • SignedDataVerifier: Added Sendable conformance to enable safe concurrent usage
  • ChainVerifier:
    • Added Sendable conformance
    • Replaced mutable verifiedPublicKeyCache with a dedicated CacheManager actor
    • Moved caching logic to the new CacheManager actor for thread safety

🆕 New Components

  • CacheManager actor: A thread-safe actor that manages certificate verification result caching
    • Implements automatic cache expiration (15 minutes)
    • Handles cache size management (max 32 entries)
    • Provides thread-safe getCachedResult and cacheResult methods

🔄 Updated Types

  • CacheKey: Added Sendable conformance
  • CacheValue: Added Sendable conformance

🧪 Testing

  • New test file: CacheManagerTests.swift with comprehensive tests for:
    • Cache storage and retrieval
    • Cache expiration behavior
    • Cache eviction when full
  • Updated tests: Refactored SignedDataVerifierTests.swift to use the new caching architecture
    • Removed custom DateOverrideChainVerifier class
    • Simplified caching tests to focus on actual behavior verification

Benefits

  1. Thread Safety: The CacheManager actor ensures all cache operations are thread-safe
  2. Concurrency Support: Both verifiers can now be safely used in concurrent contexts
  3. Better Architecture: Separation of concerns with dedicated caching logic
  4. Maintainability: Cleaner, more focused test code

Breaking Changes

None - this is a backward-compatible improvement that enhances thread safety without changing the public API.

Instead of using a var for certificate caching use a seperate CacheManager actor for thread safety
@StefanPrintezis StefanPrintezis marked this pull request as ready for review June 23, 2025 15:04
@StefanPrintezis
Copy link
Author

PR Builder failed on missing gpg data? Doesn't seem related to the PR, can we try running it again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant