-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
CustomerSessionClientSecret
validation & remodel `ElementsSessi…
…onManager` response. (#9373) * Add `CustomerSessionClientSecret` validation & remodel `ElementsSessionManager` response. * Address PR comments
- Loading branch information
1 parent
292d709
commit c89b6d5
Showing
9 changed files
with
256 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...rc/main/java/com/stripe/android/common/validation/CustomerSessionClientSecretValidator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.stripe.android.common.validation | ||
|
||
internal object CustomerSessionClientSecretValidator { | ||
private const val EPHEMERAL_KEY_SECRET_PREFIX = "ek_" | ||
private const val CUSTOMER_SESSION_CLIENT_SECRET_KEY_PREFIX = "cuss_" | ||
|
||
sealed interface Result { | ||
data object Valid : Result | ||
|
||
sealed interface Error : Result { | ||
data object Empty : Result | ||
|
||
data object LegacyEphemeralKey : Result | ||
|
||
data object UnknownKey : Result | ||
} | ||
} | ||
|
||
fun validate(customerSessionClientSecret: String): Result { | ||
return when { | ||
customerSessionClientSecret.isBlank() -> | ||
Result.Error.Empty | ||
customerSessionClientSecret.startsWith(EPHEMERAL_KEY_SECRET_PREFIX) -> | ||
Result.Error.LegacyEphemeralKey | ||
!customerSessionClientSecret.startsWith(CUSTOMER_SESSION_CLIENT_SECRET_KEY_PREFIX) -> | ||
Result.Error.UnknownKey | ||
else -> Result.Valid | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.