package com.cottondb.android.platform import androidx.fragment.app.FragmentActivity import com.cottondb.android.passwords.VaultAuthenticationCancelled import com.cottondb.android.passwords.VaultAuthenticationUnavailable import com.cottondb.android.passwords.VaultAuthenticator /** One Activity-bound request, supplied to VaultAccess; never retained by the app session. */ class AndroidVaultAuthenticator( private val activity: FragmentActivity, private val unlock: VaultUnlock = VaultUnlock(VaultKeyring(activity.applicationContext)), ) : VaultAuthenticator { override suspend fun authenticate(): String = try { unlock.unlock(activity) } catch (_: VaultUnlockCancelledException) { throw VaultAuthenticationCancelled() } catch (failure: VaultUnlockUnavailableException) { throw VaultAuthenticationUnavailable(failure.message ?: "This phone cannot unlock passwords.") } }