-
Notifications
You must be signed in to change notification settings - Fork 796
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable cipher key encryption for older server versions
- Loading branch information
Showing
5 changed files
with
62 additions
and
1 deletion.
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
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
46 changes: 46 additions & 0 deletions
46
app/src/main/java/com/x8bit/bitwarden/data/platform/util/ServerVersionUtils.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,46 @@ | ||
package com.x8bit.bitwarden.data.platform.util | ||
|
||
import com.x8bit.bitwarden.data.platform.repository.ServerConfigRepository | ||
import kotlin.text.split | ||
import kotlin.text.toIntOrNull | ||
|
||
private const val VERSION_SEPARATOR = "." | ||
private const val SUFFIX_SEPARATOR = "-" | ||
|
||
/** | ||
* Checks if the server version is greater than another provided version, returns true if it is. | ||
*/ | ||
fun isServerVersionAtLeast(serverConfig: ServerConfigRepository, version: String): Boolean { | ||
val serverVersion = serverConfig | ||
.getLocalServerConfig() | ||
?.serverData | ||
?.version | ||
|
||
val serverVersionParts = getVersionComponents(serverVersion) | ||
val otherVersionParts = getVersionComponents(version) | ||
|
||
if (serverVersionParts == null || otherVersionParts == null) { | ||
return false | ||
} | ||
|
||
for (i in serverVersionParts.indices) { | ||
val serverPart = serverVersionParts.getOrNull(i)?.toIntOrNull() ?: 0 | ||
val otherPart = otherVersionParts.getOrNull(i)?.toIntOrNull() ?: 0 | ||
|
||
if (serverPart > otherPart) { | ||
return true | ||
} else if (serverPart < otherPart) { | ||
return false | ||
} | ||
} | ||
|
||
return true // Versions are equal | ||
} | ||
|
||
/** | ||
* Extracts the version components from a version string, disregarding any suffixes. | ||
*/ | ||
private fun getVersionComponents(version: String?): List<String>? { | ||
val versionComponents = version?.split(SUFFIX_SEPARATOR)?.first() | ||
return versionComponents?.split(VERSION_SEPARATOR) | ||
} |
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