improve decrypted data parser
This commit is contained in:
parent
16df7ac847
commit
373c6500f0
1 changed files with 16 additions and 7 deletions
|
|
@ -45,19 +45,28 @@ extension PasswordEntity {
|
|||
var decrypted_password = ""
|
||||
var username = ""
|
||||
var decrypted_addtions = [AdditionField]()
|
||||
var i = 0
|
||||
plain.enumerateLines(invoking: { line, _ in
|
||||
let items = line.characters.split(separator: ":").map(String.init)
|
||||
if items.count == 1 {
|
||||
decrypted_password = items[0]
|
||||
if i == 0 {
|
||||
decrypted_password = line
|
||||
} else {
|
||||
let key = items[0]
|
||||
let value = items[1].trimmingCharacters(in: .whitespaces)
|
||||
if key.lowercased() == "username" {
|
||||
username = value
|
||||
let items = line.characters.split(separator: ":", maxSplits: 1, omittingEmptySubsequences: true).map(String.init)
|
||||
if items.count == 2 && items[0].lowercased() == "username" {
|
||||
username = items[1].trimmingCharacters(in: .whitespaces)
|
||||
} else {
|
||||
var key = ""
|
||||
var value = ""
|
||||
if items.count == 1 {
|
||||
key = "unknown"
|
||||
value = items[0]
|
||||
} else {
|
||||
key = items[0]
|
||||
value = items[1].trimmingCharacters(in: .whitespaces)
|
||||
}
|
||||
decrypted_addtions.append(AdditionField(title: key, content: value))
|
||||
}
|
||||
}
|
||||
i += 1
|
||||
})
|
||||
password = Password(name: name!, username: username, password: decrypted_password, additions: decrypted_addtions)
|
||||
return password
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue