Adapt code to changed API of GopenPGP
This commit is contained in:
parent
44cb864642
commit
01ac9d38df
2 changed files with 14 additions and 6 deletions
|
|
@ -19,11 +19,16 @@ struct GopenPgp: PgpInterface {
|
||||||
private let privateKey: CryptoKeyRing
|
private let privateKey: CryptoKeyRing
|
||||||
|
|
||||||
init(publicArmoredKey: String, privateArmoredKey: String) throws {
|
init(publicArmoredKey: String, privateArmoredKey: String) throws {
|
||||||
guard let pgp = CryptoGetGopenPGP() else {
|
var error: NSError?
|
||||||
|
guard let publicKey = CryptoBuildKeyRingArmored(publicArmoredKey, &error),
|
||||||
|
let privateKey = CryptoBuildKeyRingArmored(privateArmoredKey, &error) else {
|
||||||
throw AppError.KeyImport
|
throw AppError.KeyImport
|
||||||
}
|
}
|
||||||
publicKey = try pgp.buildKeyRingArmored(publicArmoredKey)
|
guard error == nil else {
|
||||||
privateKey = try pgp.buildKeyRingArmored(privateArmoredKey)
|
throw error!
|
||||||
|
}
|
||||||
|
self.publicKey = publicKey
|
||||||
|
self.privateKey = privateKey
|
||||||
}
|
}
|
||||||
|
|
||||||
func decrypt(encryptedData: Data, passphrase: String) throws -> Data? {
|
func decrypt(encryptedData: Data, passphrase: String) throws -> Data? {
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,13 @@ class CryptoFrameworkTest: XCTestCase {
|
||||||
ED25519,
|
ED25519,
|
||||||
ED25519_SUB,
|
ED25519_SUB,
|
||||||
].forEach { keyTriple in
|
].forEach { keyTriple in
|
||||||
let pgp = CryptoGetGopenPGP()!
|
|
||||||
let publicKey = try pgp.buildKeyRingArmored(keyTriple.publicKey)
|
|
||||||
let privateKey = try pgp.buildKeyRingArmored(keyTriple.privateKey)
|
|
||||||
var error: NSError?
|
var error: NSError?
|
||||||
|
guard let publicKey = CryptoBuildKeyRingArmored(keyTriple.publicKey, &error),
|
||||||
|
let privateKey = CryptoBuildKeyRingArmored(keyTriple.privateKey, &error) else {
|
||||||
|
XCTFail("Keys cannot be initialized.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
XCTAssertNil(error)
|
||||||
|
|
||||||
XCTAssert(publicKey.getFingerprint(&error).hasSuffix(keyTriple.fingerprint))
|
XCTAssert(publicKey.getFingerprint(&error).hasSuffix(keyTriple.fingerprint))
|
||||||
XCTAssertNil(error)
|
XCTAssertNil(error)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue