separate password and additional information of a password
This commit is contained in:
parent
d44aec6527
commit
35a9c84b63
1 changed files with 13 additions and 1 deletions
|
|
@ -29,7 +29,19 @@ extension PasswordEntity {
|
|||
let encryptedData = try Data(contentsOf: encryptedDataPath)
|
||||
let decryptedData = try PasswordStore.shared.pgp.decryptData(encryptedData, passphrase: Defaults[.pgpKeyPassphrase])
|
||||
let plain = String(data: decryptedData, encoding: .ascii) ?? ""
|
||||
password = Password(name: name!, password: plain, additions: nil)
|
||||
var decrypted_password = ""
|
||||
var decrypted_addtions = [String: String]()
|
||||
plain.enumerateLines(invoking: { line, _ in
|
||||
let item = line.characters.split(separator: ":").map(String.init)
|
||||
if item.count == 1 {
|
||||
decrypted_password = item[0]
|
||||
} else {
|
||||
let key = item[0]
|
||||
let value = item[1].trimmingCharacters(in: .whitespaces)
|
||||
decrypted_addtions[key] = value
|
||||
}
|
||||
})
|
||||
password = Password(name: name!, password: decrypted_password, additions: decrypted_addtions)
|
||||
} catch let error as NSError {
|
||||
print(error.debugDescription)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue