Skip to content

Commit

Permalink
Extract account name from Aegis imports (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintPatrck authored Jun 14, 2024
1 parent 17c9008 commit cbb469e
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,26 @@ class AegisExportParser : ExportParser {

private fun AegisJsonExport.Database.Entry.toAuthenticatorItemEntity(): AuthenticatorItemEntity {

// Lastpass only supports TOTP codes.
// Aegis only supports TOTP codes.
val type = AuthenticatorItemType.fromStringOrNull(type)
?: throw IllegalArgumentException("Unsupported OTP type")

val algorithmEnum = AuthenticatorItemAlgorithm
.fromStringOrNull(info.algo)
?: throw IllegalArgumentException("Unsupported algorithm.")

val issuer = issuer
.takeUnless { it.isEmpty() }
// If issuer is not provided we fallback to the account name.
?: name
.split(":")
.first()
val accountName = name
.split(":")
.last()
// If the account name matches the derived issuer we ignore it to prevent redundancy.
.takeUnless { it == issuer }

return AuthenticatorItemEntity(
id = UUID.randomUUID().toString(),
key = info.secret,
Expand All @@ -62,7 +74,7 @@ class AegisExportParser : ExportParser {
digits = info.digits,
issuer = issuer,
userId = null,
accountName = name,
accountName = accountName,
favorite = favorite,
)
}
Expand Down

0 comments on commit cbb469e

Please sign in to comment.