lint fixes

This commit is contained in:
decanus 2019-07-10 14:50:06 -04:00
parent 8427ddbb2e
commit 4703e6061f
No known key found for this signature in database
GPG Key ID: E95B8C69228FF5B4
13 changed files with 100 additions and 84 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@
## Build generated ## Build generated
build/ build/
DerivedData/ DerivedData/
Keycard.xcodeproj
## Various settings ## Various settings
*.pbxuser *.pbxuser

View File

@ -9,5 +9,5 @@ file_name:
- Package.swift - Package.swift
identifier_name: identifier_name:
excluded: excluded:
- id - p1
- to - p2

View File

@ -10,12 +10,12 @@ struct APDUCommand {
let needsLE: Bool let needsLE: Bool
init(cla: UInt8, ins: UInt8, p1: UInt8, p2: UInt8, data: [UInt8] = [], needsLE: Bool = false) { init(cla: UInt8, ins: UInt8, p1: UInt8, p2: UInt8, data: [UInt8] = [], needsLE: Bool = false) {
self.cla = cla; self.cla = cla
self.ins = ins; self.ins = ins
self.p1 = p1; self.p1 = p1
self.p2 = p2; self.p2 = p2
self.data = data; self.data = data
self.needsLE = needsLE; self.needsLE = needsLE
} }
func serialize() -> [UInt8] { func serialize() -> [UInt8] {

View File

@ -2,13 +2,13 @@
* ISO7816-4 R-APDU. * ISO7816-4 R-APDU.
*/ */
struct APDUResponse { struct APDUResponse {
let data : [UInt8] let data: [UInt8]
let sw1 : UInt8 let sw1: UInt8
let sw2 : UInt8 let sw2: UInt8
var sw : UInt16 { var sw: UInt16 {
get { get {
(UInt16(self.sw1) << 8) | UInt16(self.sw2) return (UInt16(self.sw1) << 8) | UInt16(self.sw2)
} }
} }
@ -32,7 +32,7 @@ struct APDUResponse {
} }
func checkSW(_ codes: StatusWord...) throws -> APDUResponse { func checkSW(_ codes: StatusWord...) throws -> APDUResponse {
try checkSW(codes: codes.map({$0.rawValue})) try checkSW(codes: codes.map({ $0.rawValue }))
} }
func checkSW(_ codes: UInt16...) throws -> APDUResponse { func checkSW(_ codes: UInt16...) throws -> APDUResponse {

View File

@ -16,13 +16,37 @@ enum AppCapability: UInt8 {
struct ApplicationInfo { struct ApplicationInfo {
let instanceUID: [UInt8] let instanceUID: [UInt8]
let freePairingSlots : Int let freePairingSlots: Int
let appVersion : UInt16 let appVersion: UInt16
let keyUID: [UInt8] let keyUID: [UInt8]
let secureChannelPubKey: [UInt8] let secureChannelPubKey: [UInt8]
let initializedCard: Bool let initializedCard: Bool
let capabilities: UInt8 let capabilities: UInt8
var appVersionString: String {
return "\(appVersion >> 8).\(appVersion & 0xff)"
}
var hasMasterKey: Bool {
return keyUID.count > 0
}
var hasSecureChannelCapability: Bool {
return (capabilities & AppCapability.secureChannel.rawValue) != 0
}
var hasKeyManagementCapability: Bool {
return (capabilities & AppCapability.keyManagement.rawValue) != 0
}
var hasCredentialsManagementCapability: Bool {
return (capabilities & AppCapability.credentialsManagement.rawValue) != 0
}
var hasNDEFCapability: Bool {
return (capabilities & AppCapability.ndef.rawValue) != 0
}
init(_ data: [UInt8]) throws { init(_ data: [UInt8]) throws {
let tlv = TinyBERTLV(data) let tlv = TinyBERTLV(data)
let topTag = try tlv.readTag() let topTag = try tlv.readTag()
@ -61,11 +85,4 @@ struct ApplicationInfo {
initializedCard = true initializedCard = true
} }
var appVersionString: String { get { "\(appVersion >> 8).\(appVersion & 0xff)" } }
var hasMasterKey: Bool { get { keyUID.count > 0 } }
var hasSecureChannelCapability: Bool { get { (capabilities & AppCapability.secureChannel.rawValue) != 0 } }
var hasKeyManagementCapability: Bool { get { (capabilities & AppCapability.keyManagement.rawValue) != 0 } }
var hasCredentialsManagementCapability: Bool { get { (capabilities & AppCapability.credentialsManagement.rawValue) != 0 } }
var hasNDEFCapability: Bool { get { (capabilities & AppCapability.ndef.rawValue) != 0 } }
} }

View File

@ -5,8 +5,6 @@ protocol CardChannel {
extension CardChannel { extension CardChannel {
var pairingPasswordPBKDF2IterationCount: Int { var pairingPasswordPBKDF2IterationCount: Int {
get {
return 50000; return 50000;
} }
}
} }

View File

@ -1,3 +1,3 @@
enum CardError : Error { enum CardError: Error {
case wrongPIN(retryCounter: Int) case wrongPIN(retryCounter: Int)
} }

View File

@ -92,14 +92,12 @@ enum Identifier: String {
case keycardCashAID = "A000000804000103" case keycardCashAID = "A000000804000103"
case keycardCashInstanceAID = "A00000080400010301" case keycardCashInstanceAID = "A00000080400010301"
var val: [UInt8] {
return rawValue.hexToBytes
}
static func getKeycardInstanceAID(instanceId: UInt8 = 1) -> [UInt8] { static func getKeycardInstanceAID(instanceId: UInt8 = 1) -> [UInt8] {
precondition(instanceId >= 1, "The instance index must be between 1 and 255") precondition(instanceId >= 1, "The instance index must be between 1 and 255")
return keycardAID.val + [instanceId] return keycardAID.val + [instanceId]
} }
var val: [UInt8] {
get {
self.rawValue.hexToBytes
}
}
} }

View File

@ -2,6 +2,12 @@ struct Pairing {
let pairingKey: [UInt8] let pairingKey: [UInt8]
let pairingIndex: UInt8 let pairingIndex: UInt8
var bytes: [UInt8] {
get {
return [pairingIndex] + pairingKey
}
}
init(pairingKey: [UInt8], pairingIndex: UInt8) { init(pairingKey: [UInt8], pairingIndex: UInt8) {
self.pairingKey = pairingKey self.pairingKey = pairingKey
self.pairingIndex = pairingIndex self.pairingIndex = pairingIndex
@ -11,10 +17,4 @@ struct Pairing {
self.pairingIndex = pairingData[0] self.pairingIndex = pairingData[0]
self.pairingKey = Array(pairingData[1...(pairingData.count - 1)]) self.pairingKey = Array(pairingData[1...(pairingData.count - 1)])
} }
var bytes: [UInt8] {
get {
[pairingIndex] + pairingKey
}
}
} }

View File

@ -8,7 +8,9 @@ extension Collection where Element == Character {
last = $0 last = $0
return nil return nil
} }
defer { last = nil } defer {
last = nil
}
return UInt8(lastHexDigitValue * 16 + hexDigitValue) return UInt8(lastHexDigitValue * 16 + hexDigitValue)
} }
} }