Refactor and optimize various components

- Updated RosettaFirebaseMessagingService to use IO dispatcher for blocking calls.
- Enhanced AvatarRepository with LRU caching and improved coroutine handling for avatar loading.
- Implemented timeout for websocket connection in UnlockScreen.
- Added selection mode functionality in ChatsListScreen with haptic feedback and improved UI for chat actions.
- Improved animated dots in AttachmentComponents for a smoother visual effect.
- Refactored image downloading and caching logic in ChatDetailComponents to streamline the process.
- Optimized SwipeBackContainer to simplify gesture handling.
- Adjusted swipe back behavior in OtherProfileScreen based on image viewer state.
This commit is contained in:
2026-02-12 15:38:30 +05:00
parent 263d00b783
commit ea537ccce1
16 changed files with 775 additions and 1370 deletions

View File

@@ -24,6 +24,10 @@ object MessageCrypto {
private const val CHACHA_KEY_SIZE = 32
private const val XCHACHA_NONCE_SIZE = 24
private const val POLY1305_TAG_SIZE = 16
// Кэш PBKDF2-SHA256 ключей: password → derived key bytes
// PBKDF2 с 1000 итерациями ~50-100ms, кэш убирает повторные вычисления
private val pbkdf2Cache = java.util.concurrent.ConcurrentHashMap<String, ByteArray>()
init {
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
@@ -608,6 +612,13 @@ object MessageCrypto {
* но PBEKeySpec в Java использует UTF-16! Поэтому используем ручную реализацию.
*/
private fun generatePBKDF2Key(password: String, salt: String = "rosetta", iterations: Int = 1000): ByteArray {
// Кэшируем только для дефолтных salt/iterations (99% вызовов)
if (salt == "rosetta" && iterations == 1000) {
return pbkdf2Cache.getOrPut(password) {
val passwordBytes = password.toByteArray(Charsets.UTF_8)
generatePBKDF2KeyFromBytes(passwordBytes, salt.toByteArray(Charsets.UTF_8), iterations)
}
}
// Crypto-js: WordArray.create(password) использует UTF-8
val passwordBytes = password.toByteArray(Charsets.UTF_8)
return generatePBKDF2KeyFromBytes(passwordBytes, salt.toByteArray(Charsets.UTF_8), iterations)