mirror of
https://github.com/bitwarden/android.git
synced 2026-03-24 23:32:29 -05:00
Improve 2FAS import (#124)
This commit is contained in:
@@ -4,30 +4,30 @@ import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class TwoFasJsonExport(
|
||||
val schemaVersion: Int,
|
||||
val appVersionCode: Int,
|
||||
val appOrigin: String,
|
||||
val schemaVersion: Int?,
|
||||
val appVersionCode: Int?,
|
||||
val appOrigin: String?,
|
||||
val services: List<Service>,
|
||||
val servicesEncrypted: String?,
|
||||
val groups: List<Group>,
|
||||
val groups: List<Group>?,
|
||||
) {
|
||||
@Serializable
|
||||
data class Service(
|
||||
val otp: Otp,
|
||||
val order: Order,
|
||||
val updatedAt: Long,
|
||||
val name: String,
|
||||
val order: Order?,
|
||||
val updatedAt: Long?,
|
||||
val name: String?,
|
||||
val icon: Icon?,
|
||||
val secret: String,
|
||||
val badge: Badge,
|
||||
val badge: Badge?,
|
||||
val serviceTypeId: String?,
|
||||
) {
|
||||
@Serializable
|
||||
data class Otp(
|
||||
val counter: Int,
|
||||
val period: Int,
|
||||
val digits: Int,
|
||||
val account: String,
|
||||
val counter: Int?,
|
||||
val period: Int?,
|
||||
val digits: Int?,
|
||||
val account: String?,
|
||||
val source: String?,
|
||||
val tokenType: String?,
|
||||
val algorithm: String?,
|
||||
@@ -37,24 +37,24 @@ data class TwoFasJsonExport(
|
||||
|
||||
@Serializable
|
||||
data class Order(
|
||||
val position: Int,
|
||||
val position: Int?,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Icon(
|
||||
val iconCollection: IconCollection,
|
||||
val label: Label,
|
||||
val selected: String,
|
||||
val iconCollection: IconCollection?,
|
||||
val label: Label?,
|
||||
val selected: String?,
|
||||
) {
|
||||
@Serializable
|
||||
data class IconCollection(
|
||||
val id: String,
|
||||
val id: String?,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Label(
|
||||
val backgroundColor: String,
|
||||
val text: String,
|
||||
val backgroundColor: String?,
|
||||
val text: String?,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -68,6 +68,6 @@ data class TwoFasJsonExport(
|
||||
data class Group(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val isExpanded: Boolean,
|
||||
val isExpanded: Boolean?,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class TwoFasExportParser : ExportParser {
|
||||
ignoreUnknownKeys = true
|
||||
isLenient = true
|
||||
explicitNulls = false
|
||||
encodeDefaults = true
|
||||
}
|
||||
|
||||
return try {
|
||||
@@ -59,7 +60,7 @@ class TwoFasExportParser : ExportParser {
|
||||
private fun List<TwoFasJsonExport.Service>.toAuthenticatorItemEntities() =
|
||||
mapNotNull { it.toAuthenticatorItemEntityOrNull() }
|
||||
|
||||
private fun TwoFasJsonExport.Service.toAuthenticatorItemEntityOrNull(): AuthenticatorItemEntity? {
|
||||
private fun TwoFasJsonExport.Service.toAuthenticatorItemEntityOrNull(): AuthenticatorItemEntity {
|
||||
|
||||
val type = otp.tokenType
|
||||
?.let { tokenType ->
|
||||
@@ -87,9 +88,9 @@ class TwoFasExportParser : ExportParser {
|
||||
key = secret,
|
||||
type = type,
|
||||
algorithm = algorithm,
|
||||
period = otp.period,
|
||||
digits = otp.digits,
|
||||
issuer = otp.issuer ?: name,
|
||||
period = otp.period ?: 30,
|
||||
digits = otp.digits ?: 6,
|
||||
issuer = otp.issuer.takeUnless { it.isNullOrEmpty() } ?: name.orEmpty(),
|
||||
userId = null,
|
||||
accountName = otp.account,
|
||||
favorite = false,
|
||||
|
||||
Reference in New Issue
Block a user