Throw error in case PGP key files cannot be read

This commit is contained in:
Danny Moesch 2019-06-29 10:28:16 +02:00 committed by Mingshen Sun
parent f0003227d5
commit b806175842
4 changed files with 13 additions and 10 deletions

View file

@ -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)
}
}