diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/entity/request/PasswordHistoryRequest.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/entity/request/PasswordHistoryRequest.kt index 74216e20..547a8917 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/entity/request/PasswordHistoryRequest.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/entity/request/PasswordHistoryRequest.kt @@ -10,14 +10,19 @@ data class PasswordHistoryRequest( @SerialName("password") val password: String, @SerialName("lastUsedDate") - val lastUsedDate: Instant?, + val lastUsedDate: Instant, ) fun PasswordHistoryRequest.Companion.of( model: BitwardenCipher.Login.PasswordHistory, ) = kotlin.run { + val lastUsedDate = model.lastUsedDate + // Bitwarden forces us to have a last used date for + // the password history item. It still allows for existing + // items to have it as null tho. + ?: Instant.fromEpochMilliseconds(0) PasswordHistoryRequest( password = model.password, - lastUsedDate = model.lastUsedDate, + lastUsedDate = lastUsedDate, ) } diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/mapper/CipherMapping.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/mapper/CipherMapping.kt index 5f27bd32..883a78c5 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/mapper/CipherMapping.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/mapper/CipherMapping.kt @@ -182,7 +182,11 @@ suspend fun BitwardenCipher.Login.toDomain( fun BitwardenCipher.Login.PasswordHistory.toDomain() = DSecret.Login.PasswordHistory( password = password, - lastUsedDate = lastUsedDate, + // Bitwarden forces us to have a last used date for + // the password history item. The ones that had it as + // null will end up converted to the zero Unix timestamp. + lastUsedDate = lastUsedDate + ?.takeUnless { it.epochSeconds == 0L }, ) fun BitwardenCipher.Login.PasswordStrength.toDomain() = PasswordStrength(