Throw error in case PGP key files cannot be read
This commit is contained in:
parent
f0003227d5
commit
b806175842
4 changed files with 13 additions and 10 deletions
|
|
@ -60,6 +60,7 @@
|
|||
"FailureToSaveContext" = "Fehler beim Speichern des Kontexts: %@";
|
||||
"RepositoryRemoteMasterNotFoundError." = "Remote-Branch origin/master wurde nicht gefunden.";
|
||||
"KeyImportError." = "Schlüssel kann nicht importiert werden.";
|
||||
"FileNotFoundError." = "Die Datei '%@' kann nicht gelesen werden.";
|
||||
"PasswordDuplicatedError." = "Passwort kann nicht hinzugefügt werden; es existiert bereits.";
|
||||
"GitResetError." = "Der zuletzt synchronisierte Commit kann nicht identifiziert werden.";
|
||||
"PGPPublicKeyNotExistError." = "Der öffentliche PGP-Schlüssen existiert nicht";
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@
|
|||
"RepositoryRemoteBranchNotFoundError." = "Cannot find remote branch %@.";
|
||||
"RepositoryBranchNotFoundError." = "Branch %@ not found in repository.";
|
||||
"KeyImportError." = "Cannot import the key.";
|
||||
"FileNotFoundError." = "File '%@' cannot be read.";
|
||||
"PasswordDuplicatedError." = "Cannot add the password; password is duplicated.";
|
||||
"GitResetError." = "Cannot identify the latest synced commit.";
|
||||
"PgpPublicKeyNotExistError." = "PGP public key doesn't exist.";
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public enum AppError: Error {
|
|||
case RepositoryRemoteBranchNotFound(_: String)
|
||||
case RepositoryBranchNotFound(_: String)
|
||||
case KeyImport
|
||||
case ReadingFile(_: String)
|
||||
case PasswordDuplicated
|
||||
case GitReset
|
||||
case GitCommit
|
||||
|
|
@ -26,7 +27,7 @@ extension AppError: LocalizedError {
|
|||
public var errorDescription: String? {
|
||||
let localizationKey = "\(String(describing: self).prefix(while: { $0 != "(" }))Error."
|
||||
switch self {
|
||||
case let .RepositoryRemoteBranchNotFound(name), let .RepositoryBranchNotFound(name):
|
||||
case let .RepositoryRemoteBranchNotFound(name), let .RepositoryBranchNotFound(name), let .ReadingFile(name):
|
||||
return localizationKey.localize(name)
|
||||
default:
|
||||
return localizationKey.localize()
|
||||
|
|
|
|||
|
|
@ -883,16 +883,16 @@ public class PasswordStore {
|
|||
}
|
||||
|
||||
public func pgpKeyImportFromFileSharing() throws {
|
||||
let publicKeyFileUrl = URL(fileURLWithPath: Globals.iTunesFileSharingPGPPublic)
|
||||
let privateKeyFileUrl = URL(fileURLWithPath: Globals.iTunesFileSharingPGPPrivate)
|
||||
|
||||
let publicKeyFileContent = try Data(contentsOf: publicKeyFileUrl)
|
||||
let privateKeyFileContent = try Data(contentsOf: privateKeyFileUrl)
|
||||
|
||||
guard let publicKeyFileContent = fm.contents(atPath: Globals.iTunesFileSharingPGPPublic) else {
|
||||
throw AppError.ReadingFile(Globals.iTunesFileSharingPGPPublic)
|
||||
}
|
||||
AppKeychain.add(data: publicKeyFileContent, for: PGPKeyType.PUBLIC.rawValue)
|
||||
AppKeychain.add(data: privateKeyFileContent, for: PGPKeyType.PRIVATE.rawValue)
|
||||
try fm.removeItem(atPath: Globals.iTunesFileSharingPGPPublic)
|
||||
|
||||
try fm.removeItem(at: publicKeyFileUrl)
|
||||
try fm.removeItem(at: privateKeyFileUrl)
|
||||
guard let privateKeyFileContent = fm.contents(atPath: Globals.iTunesFileSharingPGPPrivate) else {
|
||||
throw AppError.ReadingFile(Globals.iTunesFileSharingPGPPrivate)
|
||||
}
|
||||
AppKeychain.add(data: privateKeyFileContent, for: PGPKeyType.PRIVATE.rawValue)
|
||||
try fm.removeItem(atPath: Globals.iTunesFileSharingPGPPrivate)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue