Skip to content

Commit 0c6febb

Browse files
Surjit Kumar SahooSurjit Kumar Sahoo
authored andcommitted
refactor: convert decrypt function to an expression body and expand its try-catch scope.
1 parent 0b5fb70 commit 0c6febb

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

app/src/main/kotlin/org/grakovne/lissen/persistence/preferences/LissenSharedPreferences.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -636,22 +636,21 @@ class LissenSharedPreferences
636636
awaitClose { sharedPreferences.unregisterOnSharedPreferenceChangeListener(listener) }
637637
}.distinctUntilChanged()
638638

639-
private fun decrypt(data: String): String? {
640-
val decodedData = Base64.decode(data, Base64.DEFAULT)
641-
val iv = decodedData.sliceArray(0 until 12)
642-
val cipherText = decodedData.sliceArray(12 until decodedData.size)
639+
private fun decrypt(data: String): String? =
640+
try {
641+
val decodedData = Base64.decode(data, Base64.DEFAULT)
642+
val iv = decodedData.sliceArray(0 until 12)
643+
val cipherText = decodedData.sliceArray(12 until decodedData.size)
643644

644-
val cipher = Cipher.getInstance(TRANSFORMATION)
645-
val spec = GCMParameterSpec(128, iv)
646-
cipher.init(Cipher.DECRYPT_MODE, getSecretKey(), spec)
645+
val cipher = Cipher.getInstance(TRANSFORMATION)
646+
val spec = GCMParameterSpec(128, iv)
647+
cipher.init(Cipher.DECRYPT_MODE, getSecretKey(), spec)
647648

648-
return try {
649649
String(cipher.doFinal(cipherText))
650650
} catch (ex: Exception) {
651651
crashReporter.recordException(ex)
652652
null
653653
}
654-
}
655654

656655
companion object {
657656
private const val KEY_ALIAS = "secure_key_alias"

0 commit comments

Comments
 (0)