-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e45309
commit 7f3f737
Showing
20 changed files
with
1,436 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
BluetoothAccessory.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// swift-tools-version:5.7 | ||
import PackageDescription | ||
|
||
let bluetoothDependencies: [Target.Dependency] = [ | ||
"BluetoothAccessory", | ||
.product( | ||
name: "Bluetooth", | ||
package: "Bluetooth" | ||
), | ||
.product( | ||
name: "BluetoothGATT", | ||
package: "Bluetooth", | ||
condition: .when(platforms: [.macOS, .linux]) | ||
), | ||
.product( | ||
name: "BluetoothHCI", | ||
package: "Bluetooth", | ||
condition: .when(platforms: [.macOS, .linux]) | ||
), | ||
.product( | ||
name: "BluetoothGAP", | ||
package: "Bluetooth", | ||
condition: .when(platforms: [.macOS, .linux]) | ||
), | ||
.product( | ||
name: "GATT", | ||
package: "GATT" | ||
), | ||
.product( | ||
name: "DarwinGATT", | ||
package: "GATT", | ||
condition: .when(platforms: [.macOS]) | ||
), | ||
.product( | ||
name: "BluetoothLinux", | ||
package: "BluetoothLinux", | ||
condition: .when(platforms: [.linux]) | ||
), | ||
.product( | ||
name: "ArgumentParser", | ||
package: "swift-argument-parser" | ||
) | ||
] | ||
|
||
let package = Package( | ||
name: "BluetoothAccessory-Sample", | ||
platforms: [ | ||
.macOS(.v12) | ||
], | ||
products: [ | ||
.executable( | ||
name: "BulbAccessory", | ||
targets: ["BulbAccessory"] | ||
), | ||
.executable( | ||
name: "LockAccessory", | ||
targets: ["LockAccessory"] | ||
), | ||
.executable( | ||
name: "ThermostatAccessory", | ||
targets: ["ThermostatAccessory"] | ||
), | ||
.executable( | ||
name: "SolarAccessory", | ||
targets: ["SolarAccessory"] | ||
) | ||
], | ||
dependencies: [ | ||
.package( | ||
name: "BluetoothAccessory", | ||
path: "../" | ||
), | ||
.package( | ||
url: "https://github.com/PureSwift/Bluetooth.git", | ||
.upToNextMajor(from: "6.0.0") | ||
), | ||
.package( | ||
url: "https://github.com/PureSwift/GATT.git", | ||
branch: "master" | ||
), | ||
.package( | ||
url: "https://github.com/PureSwift/BluetoothLinux.git", | ||
branch: "master" | ||
), | ||
.package( | ||
url: "https://github.com/apple/swift-argument-parser", | ||
from: "1.2.0" | ||
), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "BulbAccessory", | ||
dependencies: bluetoothDependencies + ["BluetoothAccessoryExample"] | ||
), | ||
.executableTarget( | ||
name: "LockAccessory", | ||
dependencies: bluetoothDependencies + ["BluetoothAccessoryExample"] | ||
), | ||
.executableTarget( | ||
name: "ThermostatAccessory", | ||
dependencies: bluetoothDependencies + ["BluetoothAccessoryExample"] | ||
), | ||
.executableTarget( | ||
name: "SolarAccessory", | ||
dependencies: bluetoothDependencies + ["BluetoothAccessoryExample"] | ||
), | ||
.target( | ||
name: "BluetoothAccessoryExample", | ||
dependencies: bluetoothDependencies | ||
) | ||
] | ||
) |
32 changes: 32 additions & 0 deletions
32
Example/Sources/BluetoothAccessoryExample/AuthenticationDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// AuthenticationDelegate.swift | ||
// | ||
// | ||
// Created by Alsey Coleman Miller on 3/1/24. | ||
// | ||
|
||
import Foundation | ||
import Bluetooth | ||
import BluetoothAccessory | ||
|
||
/// Accessory Authentication Delegate | ||
public protocol AuthenticationDelegate: AnyObject { | ||
|
||
var isConfigured: Bool { get async } | ||
|
||
var allKeys: [KeysCharacteristic.Item] { get async } | ||
|
||
func key(for id: UUID) async -> Key? | ||
|
||
func newKey(for id: UUID) async -> NewKey? | ||
|
||
func secret(for id: UUID) async -> KeyData? | ||
|
||
func setup(_ request: SetupRequest, authenticationMessage: AuthenticationMessage) async -> Bool | ||
|
||
func create(_ request: CreateNewKeyRequest, authenticationMessage: AuthenticationMessage) async -> Bool | ||
|
||
func confirm(_ request: ConfirmNewKeyRequest, authenticationMessage: AuthenticationMessage) async -> Bool | ||
|
||
func remove(_ request: RemoveKeyRequest, authenticationMessage: AuthenticationMessage) async -> Bool | ||
} |
40 changes: 40 additions & 0 deletions
40
Example/Sources/BluetoothAccessoryExample/AuthenticationFile.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// AuthenticationFile.swift | ||
// | ||
// | ||
// Created by Alsey Coleman Miller on 3/1/24. | ||
// | ||
|
||
import Foundation | ||
import Bluetooth | ||
import BluetoothAccessory | ||
|
||
/// Bluetooth Accessory Authentication File. | ||
public struct AuthenticationFile: Equatable, Hashable, Codable, JSONFile { | ||
|
||
public var keys: [UUID: Key] | ||
|
||
public var newKeys: [UUID: NewKey] | ||
|
||
public var secretData: [UUID: KeyData] | ||
|
||
public init() { | ||
self.keys = [:] | ||
self.newKeys = [:] | ||
self.secretData = [:] | ||
} | ||
} | ||
|
||
public extension AuthenticationFile { | ||
|
||
var isConfigured: Bool { | ||
keys.contains(where: { $0.value.permission == .owner }) | ||
} | ||
|
||
init(owner: Key, secret: KeyData) { | ||
assert(owner.permission == .owner) | ||
self.keys = [owner.id : owner] | ||
self.newKeys = [:] | ||
self.secretData = [owner.id : secret] | ||
} | ||
} |
Oops, something went wrong.