From b5382b129e057d3e69b5deb635172df822fc9f19 Mon Sep 17 00:00:00 2001 From: islam <2553451+qalandarov@users.noreply.github.com> Date: Thu, 11 Sep 2025 09:37:23 +0100 Subject: [PATCH] =?UTF-8?q?Rename=20`logError(=E2=80=A6)`=20to=20`error(?= =?UTF-8?q?=E2=80=A6)`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Identity/SecureIdentityStateManager.swift | 4 +-- bitchat/Services/KeychainManager.swift | 6 ++-- bitchat/Services/NoiseEncryptionService.swift | 6 ++-- bitchat/Utils/SecureLogger.swift | 28 +++++++++---------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/bitchat/Identity/SecureIdentityStateManager.swift b/bitchat/Identity/SecureIdentityStateManager.swift index e87e46fd..3bd8b31c 100644 --- a/bitchat/Identity/SecureIdentityStateManager.swift +++ b/bitchat/Identity/SecureIdentityStateManager.swift @@ -160,7 +160,7 @@ final class SecureIdentityStateManager { cache = try JSONDecoder().decode(IdentityCache.self, from: decryptedData) } catch { // Log error but continue with empty cache - SecureLogger.logError(error, context: "Failed to load identity cache", category: .security) + SecureLogger.error(error, context: "Failed to load identity cache", category: .security) } } @@ -194,7 +194,7 @@ final class SecureIdentityStateManager { SecureLogger.debug("Identity cache saved to keychain", category: .security) } } catch { - SecureLogger.logError(error, context: "Failed to save identity cache", category: .security) + SecureLogger.error(error, context: "Failed to save identity cache", category: .security) } } diff --git a/bitchat/Services/KeychainManager.swift b/bitchat/Services/KeychainManager.swift index 0c864814..5eb8fe98 100644 --- a/bitchat/Services/KeychainManager.swift +++ b/bitchat/Services/KeychainManager.swift @@ -113,9 +113,9 @@ final class KeychainManager { if status == errSecSuccess { return true } if status == -34018 && !triedWithoutGroup { - SecureLogger.logError(NSError(domain: "Keychain", code: -34018), context: "Missing keychain entitlement", category: .keychain) + SecureLogger.error(NSError(domain: "Keychain", code: -34018), context: "Missing keychain entitlement", category: .keychain) } else if status != errSecDuplicateItem { - SecureLogger.logError(NSError(domain: "Keychain", code: Int(status)), context: "Error saving to keychain", category: .keychain) + SecureLogger.error(NSError(domain: "Keychain", code: Int(status)), context: "Error saving to keychain", category: .keychain) } return false } @@ -151,7 +151,7 @@ final class KeychainManager { if status == errSecSuccess { return result as? Data } if status == -34018 { - SecureLogger.logError(NSError(domain: "Keychain", code: -34018), context: "Missing keychain entitlement", category: .keychain) + SecureLogger.error(NSError(domain: "Keychain", code: -34018), context: "Missing keychain entitlement", category: .keychain) } return nil } diff --git a/bitchat/Services/NoiseEncryptionService.swift b/bitchat/Services/NoiseEncryptionService.swift index 4a05efd8..12aa1b1a 100644 --- a/bitchat/Services/NoiseEncryptionService.swift +++ b/bitchat/Services/NoiseEncryptionService.swift @@ -281,7 +281,7 @@ final class NoiseEncryptionService { let signature = try signingKey.signature(for: data) return signature } catch { - SecureLogger.logError(error, context: "Failed to sign data", category: .noise) + SecureLogger.error(error, context: "Failed to sign data", category: .noise) return nil } } @@ -292,7 +292,7 @@ final class NoiseEncryptionService { let signingPublicKey = try Curve25519.Signing.PublicKey(rawRepresentation: publicKey) return signingPublicKey.isValidSignature(signature, for: data) } catch { - SecureLogger.logError(error, context: "Failed to verify signature", category: .noise) + SecureLogger.error(error, context: "Failed to verify signature", category: .noise) return false } } @@ -578,7 +578,7 @@ final class NoiseEncryptionService { // Signal that handshake is needed onHandshakeRequired?(peerID) } catch { - SecureLogger.logError(error, context: "Failed to initiate rekey for peer: \(peerID)", category: .session) + SecureLogger.error(error, context: "Failed to initiate rekey for peer: \(peerID)", category: .session) } } } diff --git a/bitchat/Utils/SecureLogger.swift b/bitchat/Utils/SecureLogger.swift index eb91adbd..41867a8a 100644 --- a/bitchat/Utils/SecureLogger.swift +++ b/bitchat/Utils/SecureLogger.swift @@ -133,6 +133,20 @@ final class SecureLogger { log(message(), category: category, level: .error, file: file, line: line, function: function) } + /// Log errors with context + static func error(_ error: Error, context: @autoclosure () -> String, category: OSLog = .noise, + file: String = #file, line: Int = #line, function: String = #function) { + let location = formatLocation(file: file, line: line, function: function) + let sanitized = sanitize(context()) + let errorDesc = sanitize(error.localizedDescription) + + #if DEBUG + os_log("%{public}@ Error in %{public}@: %{public}@", log: category, type: .error, location, sanitized, errorDesc) + #else + os_log("%{private}@ Error in %{private}@: %{private}@", log: category, type: .error, location, sanitized, errorDesc) + #endif + } + /// Log a security event static func logSecurityEvent(_ event: SecurityEvent, level: LogLevel = .info, file: String = #file, line: Int = #line, function: String = #function) { @@ -148,20 +162,6 @@ final class SecureLogger { #endif } - /// Log errors with context - static func logError(_ error: Error, context: @autoclosure () -> String, category: OSLog = .noise, - file: String = #file, line: Int = #line, function: String = #function) { - let location = formatLocation(file: file, line: line, function: function) - let sanitized = sanitize(context()) - let errorDesc = sanitize(error.localizedDescription) - - #if DEBUG - os_log("%{public}@ Error in %{public}@: %{public}@", log: category, type: .error, location, sanitized, errorDesc) - #else - os_log("%{private}@ Error in %{private}@: %{private}@", log: category, type: .error, location, sanitized, errorDesc) - #endif - } - // MARK: - Private Helpers /// Log general messages with automatic sensitive data filtering