20 lines · 920 B · KotlinRaw
package com.cottondb.android.platformimport androidx.fragment.app.FragmentActivityimport com.cottondb.android.passwords.VaultAuthenticationCancelledimport com.cottondb.android.passwords.VaultAuthenticationUnavailableimport 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.") }}