Introduce CryptographicKey protocol

This commit is contained in:
Danny Moesch 2019-07-02 20:20:56 +02:00 committed by Mingshen Sun
parent d43a3be6f6
commit 6b95e60ea1
6 changed files with 30 additions and 24 deletions

View file

@ -1,12 +1,17 @@
//
// PgpKeyType.swift
// CryptographicKeys.swift
// passKit
//
// Created by Danny Moesch on 29.06.19.
// Copyright © 2019 Bob Sun. All rights reserved.
//
public enum PgpKeyType {
public protocol CryptographicKey {
func getKeychainKey() -> String
func getFileSharingPath() -> String
}
public enum PgpKey: CryptographicKey {
case PUBLIC
case PRIVATE
@ -19,7 +24,7 @@ public enum PgpKeyType {
}
}
func getFileSharingPath() -> String {
public func getFileSharingPath() -> String {
switch self {
case .PUBLIC:
return Globals.iTunesFileSharingPGPPublic
@ -28,3 +33,4 @@ public enum PgpKeyType {
}
}
}

View file

@ -9,18 +9,18 @@
public class KeyFileManager {
public typealias KeyHandler = (Data, String) -> ()
public static let PublicPgp = KeyFileManager(keyType: PgpKeyType.PUBLIC)
public static let PrivatePgp = KeyFileManager(keyType: PgpKeyType.PRIVATE)
public static let PublicPgp = KeyFileManager(keyType: PgpKey.PUBLIC)
public static let PrivatePgp = KeyFileManager(keyType: PgpKey.PRIVATE)
private let keyType: PgpKeyType
private let keyType: CryptographicKey
private let keyPath: String
private let keyHandler: KeyHandler
private convenience init(keyType: PgpKeyType) {
private convenience init(keyType: CryptographicKey) {
self.init(keyType: keyType, keyPath: keyType.getFileSharingPath())
}
public init(keyType: PgpKeyType, keyPath: String, keyHandler: @escaping KeyHandler = AppKeychain.add) {
public init(keyType: CryptographicKey, keyPath: String, keyHandler: @escaping KeyHandler = AppKeychain.add) {
self.keyType = keyType
self.keyPath = keyPath
self.keyHandler = keyHandler