Rewrite AutoFill extension
This commit is contained in:
parent
7e034d9c99
commit
40ac070232
13 changed files with 609 additions and 216 deletions
38
passAutoFillExtension/Services/PasswordDecryptor.swift
Normal file
38
passAutoFillExtension/Services/PasswordDecryptor.swift
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// PasswordDecryptor.swift
|
||||
// passAutoFillExtension
|
||||
//
|
||||
// Created by Sun, Mingshen on 12/31/20.
|
||||
// Copyright © 2020 Bob Sun. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import passKit
|
||||
|
||||
func decryptPassword(in controller: UIViewController, with passwordEntity: PasswordEntity, using keyID: String? = nil, completion: @escaping ((Password) -> Void)) {
|
||||
DispatchQueue.global(qos: .userInteractive).async {
|
||||
do {
|
||||
let requestPGPKeyPassphrase = Utils.createRequestPGPKeyPassphraseHandler(controller: controller)
|
||||
let decryptedPassword = try PasswordStore.shared.decrypt(passwordEntity: passwordEntity, keyID: keyID, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
completion(decryptedPassword)
|
||||
}
|
||||
} catch let AppError.pgpPrivateKeyNotFound(keyID: key) {
|
||||
DispatchQueue.main.async {
|
||||
let alert = UIAlertController(title: "CannotShowPassword".localize(), message: AppError.pgpPrivateKeyNotFound(keyID: key).localizedDescription, preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction.cancelAndPopView(controller: controller))
|
||||
let selectKey = UIAlertAction.selectKey(controller: controller) { action in
|
||||
decryptPassword(in: controller, with: passwordEntity, using: action.title, completion: completion)
|
||||
}
|
||||
alert.addAction(selectKey)
|
||||
|
||||
controller.present(alert, animated: true)
|
||||
}
|
||||
} catch {
|
||||
DispatchQueue.main.async {
|
||||
Utils.alert(title: "CannotCopyPassword".localize(), message: error.localizedDescription, controller: controller)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue