Skip to content

Commit

Permalink
Add hexString methods; Clean up VC.
Browse files Browse the repository at this point in the history
  • Loading branch information
yspreen committed Apr 14, 2021
1 parent 1edab61 commit 4c94472
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
12 changes: 12 additions & 0 deletions PatientScannerDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
CEC2C4C42625ED030056E406 /* Base45.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2C4C12625ED030056E406 /* Base45.swift */; };
CEFAD86D2625F164009AFEF9 /* EC256.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFAD86C2625F164009AFEF9 /* EC256.swift */; };
CEFAD8722625F29E009AFEF9 /* String+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFAD8712625F29E009AFEF9 /* String+JSON.swift */; };
CEFAD87A26271414009AFEF9 /* COSE.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFAD87926271414009AFEF9 /* COSE.swift */; };
CEFAD87F262714C4009AFEF9 /* EHNTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFAD87E262714C4009AFEF9 /* EHNTests.swift */; };
CEFAD88726271B9A009AFEF9 /* Data+hexString.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFAD88626271B9A009AFEF9 /* Data+hexString.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -60,6 +63,9 @@
CEC2C4C12625ED030056E406 /* Base45.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Base45.swift; sourceTree = "<group>"; };
CEFAD86C2625F164009AFEF9 /* EC256.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EC256.swift; sourceTree = "<group>"; };
CEFAD8712625F29E009AFEF9 /* String+JSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+JSON.swift"; sourceTree = "<group>"; };
CEFAD87926271414009AFEF9 /* COSE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = COSE.swift; sourceTree = "<group>"; };
CEFAD87E262714C4009AFEF9 /* EHNTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EHNTests.swift; sourceTree = "<group>"; };
CEFAD88626271B9A009AFEF9 /* Data+hexString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+hexString.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -123,6 +129,8 @@
CEA6D6F6261F8D2900715333 /* LaunchScreen.storyboard */,
CEA6D6F9261F8D2900715333 /* Info.plist */,
CEFAD86C2625F164009AFEF9 /* EC256.swift */,
CEFAD87926271414009AFEF9 /* COSE.swift */,
CEFAD88626271B9A009AFEF9 /* Data+hexString.swift */,
);
path = PatientScannerDemo;
sourceTree = "<group>";
Expand All @@ -132,6 +140,7 @@
children = (
CEA6D702261F8D2900715333 /* PatientScannerDemoTests.swift */,
CEA6D704261F8D2900715333 /* Info.plist */,
CEFAD87E262714C4009AFEF9 /* EHNTests.swift */,
);
path = PatientScannerDemoTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -281,9 +290,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CEFAD88726271B9A009AFEF9 /* Data+hexString.swift in Sources */,
CEC2C4C32625ED030056E406 /* JWK.swift in Sources */,
CEC2C4C42625ED030056E406 /* Base45.swift in Sources */,
CEA6D6F0261F8D2700715333 /* ViewController.swift in Sources */,
CEFAD87A26271414009AFEF9 /* COSE.swift in Sources */,
CEFAD86D2625F164009AFEF9 /* EC256.swift in Sources */,
CEA6D6EC261F8D2700715333 /* AppDelegate.swift in Sources */,
CEFAD8722625F29E009AFEF9 /* String+JSON.swift in Sources */,
Expand All @@ -297,6 +308,7 @@
buildActionMask = 2147483647;
files = (
CEA6D703261F8D2900715333 /* PatientScannerDemoTests.swift in Sources */,
CEFAD87F262714C4009AFEF9 /* EHNTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
29 changes: 29 additions & 0 deletions PatientScannerDemo/Data+hexString.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Data+hexString.swift
// PatientScannerDemo
//
// Created by Yannick Spreen on 4/14/21.
//

import Foundation

extension Data {
init?(hexString: String) {
let len = hexString.count / 2
var data = Data(capacity: len)
var i = hexString.startIndex
for _ in 0..<len {
let j = hexString.index(i, offsetBy: 2)
let bytes = hexString[i..<j]
if var num = UInt8(bytes, radix: 16) {
data.append(&num, count: 1)
} else {
return nil
}
i = j
}
self = data
}

var uint: [UInt8] { [UInt8](self) }
}
10 changes: 6 additions & 4 deletions PatientScannerDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ViewController: UIViewController {
super.viewDidLoad()
checkPermissions()
setupCameraLiveView()
observationHandler(payloadS: nil)
// observationHandler(payloadS: nil)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
Expand Down Expand Up @@ -141,24 +141,26 @@ extension ViewController {
}

print(data)
let decoder = SwiftCBOR.CBORDecoder(input: [UInt8](data))
let decoder = SwiftCBOR.CBORDecoder(input: data.uint)
guard
let cose = try? decoder.decodeItem(),
case let CBOR.tagged(tag, cborElement) = cose,
tag.rawValue == 18,
tag.rawValue == 18, // SIGN1
case let CBOR.array(array) = cborElement,
case let CBOR.byteString(protectedBytes) = array[0],
case let CBOR.map(unprotected) = array[1],
case let CBOR.byteString(payloadBytes) = array[2],
case let CBOR.byteString(signature) = array[3],
let protected = try? CBOR.decode(protectedBytes),
let payload = try? CBOR.decode(payloadBytes)
let payload = try? CBOR.decode(payloadBytes),
case let CBOR.map(protectedMap) = protected
else {
return
}

print("START")
print(protected)
print(protectedMap)
print(unprotected)
print(payload)
print(signature)
Expand Down

0 comments on commit 4c94472

Please sign in to comment.