check zero byte key (solve issue #26)
This commit is contained in:
parent
9a942734f7
commit
e1f3a08666
1 changed files with 10 additions and 4 deletions
|
|
@ -127,11 +127,19 @@ class PasswordStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initPGP(pgpPublicKeyLocalPath: String, pgpPrivateKeyLocalPath: String) throws {
|
func initPGP(pgpPublicKeyLocalPath: String, pgpPrivateKeyLocalPath: String) throws {
|
||||||
pgp.importKeys(fromFile: pgpPublicKeyLocalPath, allowDuplicates: false)
|
let pgpPublicKeyData = NSData(contentsOfFile: pgpPublicKeyLocalPath)! as Data
|
||||||
|
if pgpPublicKeyData.count == 0 {
|
||||||
|
throw NSError(domain: "me.mssun.pass.error", code: 2, userInfo: [NSLocalizedDescriptionKey: "Cannot import public key."])
|
||||||
|
}
|
||||||
|
pgp.importKeys(from: pgpPublicKeyData, allowDuplicates: false)
|
||||||
if pgp.getKeysOf(.public).count == 0 {
|
if pgp.getKeysOf(.public).count == 0 {
|
||||||
throw NSError(domain: "me.mssun.pass.error", code: 2, userInfo: [NSLocalizedDescriptionKey: "Cannot import public key."])
|
throw NSError(domain: "me.mssun.pass.error", code: 2, userInfo: [NSLocalizedDescriptionKey: "Cannot import public key."])
|
||||||
}
|
}
|
||||||
pgp.importKeys(fromFile: pgpPrivateKeyLocalPath, allowDuplicates: false)
|
let pgpPrivateKeyData = NSData(contentsOfFile: pgpPrivateKeyLocalPath)! as Data
|
||||||
|
if pgpPrivateKeyData.count == 0 {
|
||||||
|
throw NSError(domain: "me.mssun.pass.error", code: 2, userInfo: [NSLocalizedDescriptionKey: "Cannot import public key."])
|
||||||
|
}
|
||||||
|
pgp.importKeys(from: pgpPrivateKeyData, allowDuplicates: false)
|
||||||
if pgp.getKeysOf(.secret).count == 0 {
|
if pgp.getKeysOf(.secret).count == 0 {
|
||||||
throw NSError(domain: "me.mssun.pass.error", code: 2, userInfo: [NSLocalizedDescriptionKey: "Cannot import seceret key."])
|
throw NSError(domain: "me.mssun.pass.error", code: 2, userInfo: [NSLocalizedDescriptionKey: "Cannot import seceret key."])
|
||||||
}
|
}
|
||||||
|
|
@ -145,10 +153,8 @@ class PasswordStore {
|
||||||
func initPGP(pgpPublicKeyURL: URL, pgpPublicKeyLocalPath: String, pgpPrivateKeyURL: URL, pgpPrivateKeyLocalPath: String) throws {
|
func initPGP(pgpPublicKeyURL: URL, pgpPublicKeyLocalPath: String, pgpPrivateKeyURL: URL, pgpPrivateKeyLocalPath: String) throws {
|
||||||
let pgpPublicData = try Data(contentsOf: pgpPublicKeyURL)
|
let pgpPublicData = try Data(contentsOf: pgpPublicKeyURL)
|
||||||
try pgpPublicData.write(to: URL(fileURLWithPath: pgpPublicKeyLocalPath), options: .atomic)
|
try pgpPublicData.write(to: URL(fileURLWithPath: pgpPublicKeyLocalPath), options: .atomic)
|
||||||
|
|
||||||
let pgpPrivateData = try Data(contentsOf: pgpPrivateKeyURL)
|
let pgpPrivateData = try Data(contentsOf: pgpPrivateKeyURL)
|
||||||
try pgpPrivateData.write(to: URL(fileURLWithPath: pgpPrivateKeyLocalPath), options: .atomic)
|
try pgpPrivateData.write(to: URL(fileURLWithPath: pgpPrivateKeyLocalPath), options: .atomic)
|
||||||
|
|
||||||
try initPGP(pgpPublicKeyLocalPath: pgpPublicKeyLocalPath, pgpPrivateKeyLocalPath: pgpPrivateKeyLocalPath)
|
try initPGP(pgpPublicKeyLocalPath: pgpPublicKeyLocalPath, pgpPrivateKeyLocalPath: pgpPrivateKeyLocalPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue