Enable SwiftLint rule 'identifier_name' and handle all violations
This commit is contained in:
parent
7ada4dd96d
commit
e8389eb262
21 changed files with 157 additions and 156 deletions
|
|
@ -10,8 +10,8 @@ import Crypto
|
|||
|
||||
struct GopenPGPInterface: PGPInterface {
|
||||
private static let errorMapping: [String: Error] = [
|
||||
"gopenpgp: error in unlocking key: openpgp: invalid data: private key checksum failure": AppError.WrongPassphrase,
|
||||
"openpgp: incorrect key": AppError.KeyExpiredOrIncompatible,
|
||||
"gopenpgp: error in unlocking key: openpgp: invalid data: private key checksum failure": AppError.wrongPassphrase,
|
||||
"openpgp: incorrect key": AppError.keyExpiredOrIncompatible,
|
||||
]
|
||||
|
||||
private var publicKeys: [String: CryptoKey] = [:]
|
||||
|
|
@ -23,24 +23,24 @@ struct GopenPGPInterface: PGPInterface {
|
|||
|
||||
for key in pubKeys {
|
||||
var error: NSError?
|
||||
guard let k = CryptoNewKeyFromArmored(key, &error) else {
|
||||
guard let cryptoKey = CryptoNewKeyFromArmored(key, &error) else {
|
||||
guard error == nil else {
|
||||
throw error!
|
||||
}
|
||||
throw AppError.KeyImport
|
||||
throw AppError.keyImport
|
||||
}
|
||||
publicKeys[k.getFingerprint().lowercased()] = k
|
||||
publicKeys[cryptoKey.getFingerprint().lowercased()] = cryptoKey
|
||||
}
|
||||
|
||||
for key in prvKeys {
|
||||
var error: NSError?
|
||||
guard let k = CryptoNewKeyFromArmored(key, &error) else {
|
||||
guard let cryptoKey = CryptoNewKeyFromArmored(key, &error) else {
|
||||
guard error == nil else {
|
||||
throw error!
|
||||
}
|
||||
throw AppError.KeyImport
|
||||
throw AppError.keyImport
|
||||
}
|
||||
privateKeys[k.getFingerprint().lowercased()] = k
|
||||
privateKeys[cryptoKey.getFingerprint().lowercased()] = cryptoKey
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -71,9 +71,9 @@ struct GopenPGPInterface: PGPInterface {
|
|||
}
|
||||
|
||||
func decrypt(encryptedData: Data, keyID: String, passphrase: String) throws -> Data? {
|
||||
guard let e = privateKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) }),
|
||||
let privateKey = privateKeys[e.key] else {
|
||||
throw AppError.Decryption
|
||||
guard let key = privateKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) }),
|
||||
let privateKey = privateKeys[key.key] else {
|
||||
throw AppError.decryption
|
||||
}
|
||||
|
||||
do {
|
||||
|
|
@ -84,7 +84,7 @@ struct GopenPGPInterface: PGPInterface {
|
|||
guard error == nil else {
|
||||
throw error!
|
||||
}
|
||||
throw AppError.Decryption
|
||||
throw AppError.decryption
|
||||
}
|
||||
|
||||
let message = createPgpMessage(from: encryptedData)
|
||||
|
|
@ -95,9 +95,9 @@ struct GopenPGPInterface: PGPInterface {
|
|||
}
|
||||
|
||||
func encrypt(plainData: Data, keyID: String) throws -> Data {
|
||||
guard let e = publicKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) }),
|
||||
let publicKey = publicKeys[e.key] else {
|
||||
throw AppError.Encryption
|
||||
guard let key = publicKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) }),
|
||||
let publicKey = publicKeys[key.key] else {
|
||||
throw AppError.encryption
|
||||
}
|
||||
|
||||
var error: NSError?
|
||||
|
|
@ -106,7 +106,7 @@ struct GopenPGPInterface: PGPInterface {
|
|||
guard error == nil else {
|
||||
throw error!
|
||||
}
|
||||
throw AppError.Encryption
|
||||
throw AppError.encryption
|
||||
}
|
||||
|
||||
let encryptedData = try keyRing.encrypt(CryptoNewPlainMessage(plainData.mutable as Data), privateKey: nil)
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ struct ObjectivePGPInterface: PGPInterface {
|
|||
|
||||
init(publicArmoredKey: String, privateArmoredKey: String) throws {
|
||||
guard let publicKeyData = publicArmoredKey.data(using: .ascii), let privateKeyData = privateArmoredKey.data(using: .ascii) else {
|
||||
throw AppError.KeyImport
|
||||
throw AppError.keyImport
|
||||
}
|
||||
let publicKeys = try ObjectivePGP.readKeys(from: publicKeyData)
|
||||
let privateKeys = try ObjectivePGP.readKeys(from: privateKeyData)
|
||||
keyring.import(keys: publicKeys)
|
||||
keyring.import(keys: privateKeys)
|
||||
guard let publicKey = publicKeys.first, let privateKey = privateKeys.first else {
|
||||
throw AppError.KeyImport
|
||||
throw AppError.keyImport
|
||||
}
|
||||
self.publicKey = publicKey
|
||||
self.privateKey = privateKey
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class PGPAgent {
|
|||
guard let publicKey: String = keyStore.get(for: PgpKey.PUBLIC.getKeychainKey()),
|
||||
let privateKey: String = keyStore.get(for: PgpKey.PRIVATE.getKeychainKey()) else {
|
||||
pgpInterface = nil
|
||||
throw AppError.KeyImport
|
||||
throw AppError.keyImport
|
||||
}
|
||||
do {
|
||||
pgpInterface = try GopenPGPInterface(publicArmoredKey: publicKey, privateArmoredKey: privateKey)
|
||||
|
|
@ -48,7 +48,7 @@ public class PGPAgent {
|
|||
// Init keys.
|
||||
try checkAndInit()
|
||||
guard let pgpInterface = pgpInterface else {
|
||||
throw AppError.Decryption
|
||||
throw AppError.decryption
|
||||
}
|
||||
|
||||
var keyID = keyID
|
||||
|
|
@ -56,7 +56,7 @@ public class PGPAgent {
|
|||
if pgpInterface.keyID.count == 1 {
|
||||
keyID = pgpInterface.keyID.first!
|
||||
} else {
|
||||
throw AppError.PgpPrivateKeyNotFound(keyID: keyID)
|
||||
throw AppError.pgpPrivateKeyNotFound(keyID: keyID)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,14 +83,14 @@ public class PGPAgent {
|
|||
public func encrypt(plainData: Data, keyID: String) throws -> Data {
|
||||
try checkAndInit()
|
||||
guard let pgpInterface = pgpInterface else {
|
||||
throw AppError.Encryption
|
||||
throw AppError.encryption
|
||||
}
|
||||
var keyID = keyID
|
||||
if !pgpInterface.containsPublicKey(with: keyID) {
|
||||
if pgpInterface.keyID.count == 1 {
|
||||
keyID = pgpInterface.keyID.first!
|
||||
} else {
|
||||
throw AppError.PgpPublicKeyNotFound(keyID: keyID)
|
||||
throw AppError.pgpPublicKeyNotFound(keyID: keyID)
|
||||
}
|
||||
}
|
||||
return try pgpInterface.encrypt(plainData: plainData, keyID: keyID)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue