Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Threema/Keychain/Tests/Helper/   (Social Medium ©)  Datei vom 26.9.2026 mit Größe 5 kB image not shown  

Quelle  KeychainManagerMock.swift   Sprache: JAVA

 

import Foundation
import Keychain
import ThreemaEssentials

// MARK: - Helper to make mock sendable

private final class SendableRemoteSecretInfo: @unchecked Sendable {
    var value: (authenticationToken: Data, identityHash: Data)? {
        get { accessQueue.sync { internalValue } }
        set { accessQueue.sync { internalValue = newValue } }
    }
    
    private let accessQueue = DispatchQueue(label: "ch.threema.SendableRemoteSecretInfo")
    private var internalValue: (authenticationToken: Data, identityHash: Data)?
}

// MARK: - The actual mock

public final class KeychainManagerMock: KeychainManagerProtocol, @unchecked Sendable {
    
    @Atomic
    public private(set) var loadMultiDeviceGroupKeyCalls = 0
    
    @Atomic
    public private(set) var storeMultiDeviceGroupKeyCalls = [Data]()
    
    @Atomic
    public private(set) var storeMultiDeviceIDCalls = [Data]()
    
    @Atomic
    public private(set) var storeLicenseCalls = [String]()

    @Atomic
    public private(set) var storeDataBackupRecoveryKeyCalls = [Data]()

    @Atomic
    public private(set) var deleteDataBackupRecoveryKeyCalls = 0
    
    @Atomic
    public private(set) var migrateToDowngradeCalls = 0
    
    @Atomic
    public private(set) var migrateToVersion0Calls = 0
    
    @Atomic
    public private(set) var migrateToVersion1Calls = 0

    private static let remoteSecretInfo = SendableRemoteSecretInfo()

    @Atomic
    public var dataBackupRecoveryKey: Data?

    public init() {
        // no-op
    }
    
    public static func loadRemoteSecret() throws -> (
        authenticationToken: Data,
        identityHash: Data
    )? {
        remoteSecretInfo.value
    }
    
    public static func storeRemoteSecret(authenticationToken: Data, identityHash: Data) throws {
        remoteSecretInfo.value = (authenticationToken, identityHash)
    }
    
    public static func deleteRemoteSecret() throws {
        remoteSecretInfo.value = nil
    }
    
    public static func loadThreemaIdentity() throws -> ThreemaIdentity? {
        ThreemaIdentity("ABCDEFGH")
    }

    public func loadIdentity() throws -> MyIdentity? {
        nil
    }

    public func storeIdentity(_ myIdentity: MyIdentity, thisDeviceOnly: Bool) throws {
        // no-op
    }

    public func deleteIdentity() throws {
        // no-op
    }
    
    public func isIdentityThisDeviceOnly() throws -> Bool {
        true
    }

    public func changeIdentityAccessibility(thisDeviceOnly: Bool) throws {
        // no-op
    }
    
    public static func loadIdentityBackup() throws -> String {
        ""
    }

    public static func storeIdentityBackup(_ data: String) throws {
        // no-op
    }

    public static func deleteIdentityBackup() throws {
        // no-op
    }

    public func loadDeviceCookie() throws -> Data? {
        nil
    }

    public func storeDeviceCookie(_ cookie: Data) throws {
        // no-op
    }

    public static func deleteDeviceCookie() throws {
        // no-op
    }

    public func loadMultiDeviceGroupKey() throws -> Data? {
        loadMultiDeviceGroupKeyCalls += 1
        return storeMultiDeviceGroupKeyCalls.first
    }

    public func storeMultiDeviceGroupKey(key: Data) throws {
        $storeMultiDeviceGroupKeyCalls.append(key)
    }

    public static func deleteMultiDeviceGroupKey() throws {
        // no-op
    }

    public func loadMultiDeviceID() -> Data? {
        nil
    }

    public func storeMultiDeviceID(id: Data) throws {
        $storeMultiDeviceIDCalls.append(id)
    }

    public func deleteMultiDeviceID() throws {
        // no-op
    }

    public func loadForwardSecurityWrappingKey() throws -> Data? {
        nil
    }

    public func storeForwardSecurityWrappingKey(_ key: Data) throws {
        // no-op
    }

    public static func deleteForwardSecurityKey() throws {
        // no-op
    }

    public static func loadOnPremServer() throws -> String? {
        nil
    }

    public static func loadUnencryptedLicense() throws -> ThreemaLicense? {
        nil
    }

    public func loadLicense() throws -> ThreemaLicense? {
        nil
    }

    public func storeLicense(_ license: ThreemaLicense) throws {
        $storeLicenseCalls.append(license.password)
    }

    public func deleteLicense() throws {
        // no-op
    }

    public func loadThreemaSafeKey() throws -> Data? {
        nil
    }

    public func storeThreemaSafeKey(key: Data) throws {
        // no-op
    }

    public func deleteThreemaSafeKey() throws {
        // no-op
    }

    public func loadThreemaSafeServer() throws -> ThreemaSafeServerInfo? {
        nil
    }

    public func storeThreemaSafeServer(_ safeServer: ThreemaSafeServerInfo) throws {
        // no-op
    }

    public func deleteThreemaSafeServer() throws {
        // no-op
    }

    public func loadDataBackupRecoveryKey() throws -> Data? {
        dataBackupRecoveryKey
    }

    public func storeDataBackupRecoveryKey(_ key: Data) throws {
        dataBackupRecoveryKey = key
        $storeDataBackupRecoveryKeyCalls.append(key)
    }

    public func deleteDataBackupRecoveryKey() throws {
        dataBackupRecoveryKey = nil
        deleteDataBackupRecoveryKeyCalls += 1
    }

    public func migrateToDowngrade() throws {
        $migrateToDowngradeCalls += 1
    }

    public func migrateToVersion0() throws {
        $migrateToVersion0Calls += 1
    }

    public func migrateToVersion1(myIdentity: ThreemaEssentials.ThreemaIdentity) throws {
        $migrateToVersion1Calls += 1
    }
    
    public static func deleteAllItems() throws {
        // no-op
    }
    
    public static func deleteAllThisDeviceOnlyItems() throws {
        // no-op
    }
    
    public static func deleteAllEncryptedItems() throws {
        // no-op
    }
}

Messung
CHZG
839610093

¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet am  2026-11-04) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover


Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.