diff --git a/data/src/main/java/com/canopas/yourspace/data/service/location/JourneyKtx.kt b/data/src/main/java/com/canopas/yourspace/data/service/location/JourneyKtx.kt index 312de120..8870f4ae 100644 --- a/data/src/main/java/com/canopas/yourspace/data/service/location/JourneyKtx.kt +++ b/data/src/main/java/com/canopas/yourspace/data/service/location/JourneyKtx.kt @@ -9,7 +9,12 @@ import timber.log.Timber import java.util.Base64 import java.util.UUID -fun String.toBytes(): ByteArray = Base64.getDecoder().decode(this) +fun String.toBytes(): ByteArray? = try { + Base64.getDecoder().decode(this) +} catch (e: Exception) { + Timber.e(e, "Failed to decode base64 string") + null +} fun ByteArray.encodeToString(): String = Base64.getEncoder().encodeToString(this) @@ -94,9 +99,9 @@ fun LocationJourney.toEncryptedLocationJourney( ) } -fun GroupCipher.decryptPoint(data: ByteArray): Double? { +fun GroupCipher.decryptPoint(data: ByteArray?): Double? { return try { - decrypt(data).toString(Charsets.UTF_8).toDoubleOrNull() + data?.let { decrypt(it).toString(Charsets.UTF_8).toDoubleOrNull() } } catch (e: Exception) { Timber.e(e, "Failed to decrypt double") null