Skip to content

Commit

Permalink
Minor rearrangements
Browse files Browse the repository at this point in the history
  • Loading branch information
sunkup committed Feb 25, 2025
1 parent 11f6cf7 commit ce1d76e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import javax.net.ssl.X509TrustManager
@SuppressLint("CustomX509TrustManager")
class CustomCertManager @JvmOverloads constructor(
context: Context,
private val scope: CoroutineScope,
val trustSystemCerts: Boolean = true,
private val scope: CoroutineScope,
private val getUserDecision: suspend (X509Certificate) -> Boolean
): X509TrustManager {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ class UserDecisionRegistry private constructor(
}
}

if (requestDecision) {
if (requestDecision)
scope.launch {
val userDecision = getUserDecision(cert) // Suspends until user decision is made
onUserDecision(cert, userDecision)
}
}
}

fun onUserDecision(cert: X509Certificate, trusted: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ class MainActivity : ComponentActivity() {
// set cert4android TrustManager and HostnameVerifier
val certMgr = CustomCertManager(
getApplication(),
viewModelScope,
trustSystemCerts = trustSystemCerts,
viewModelScope,
getUserDecision = { cert ->
// Reset user decision
userDecision = CompletableDeferred()
Expand Down

0 comments on commit ce1d76e

Please sign in to comment.