Skip to content

Commit

Permalink
Renamed package
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Mar 1, 2023
1 parent 4cd6e67 commit 7f5939a
Show file tree
Hide file tree
Showing 27 changed files with 26 additions and 27 deletions.
10 changes: 5 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ let package = Package(
],
products: [
.library(
name: "MillerBluetooth",
targets: ["MillerBluetooth"]
name: "BluetoothAccessory",
targets: ["BluetoothAccessory"]
),
],
dependencies: [
Expand All @@ -33,7 +33,7 @@ let package = Package(
],
targets: [
.target(
name: "MillerBluetooth",
name: "BluetoothAccessory",
dependencies: [
.product(
name: "Bluetooth",
Expand Down Expand Up @@ -63,8 +63,8 @@ let package = Package(
]
),
.testTarget(
name: "MillerBluetoothTests",
dependencies: ["MillerBluetooth"]
name: "BluetoothAccessoryTests",
dependencies: ["BluetoothAccessory"]
),
]
)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# MillerBluetooth
Bluetooth library with custom encryption
# BluetoothAccessory
Bluetooth Accessory library
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ typealias HMAC = Crypto.HMAC

/// Performs HMAC with the specified key and message.
internal func authenticationCode(for message: AuthenticationMessage, using key: KeyData) -> AuthenticationData {
let encoder = TLVEncoder.millerBluetooth
let encoder = TLVEncoder.bluetoothAccessory
let messageData = try! encoder.encode(message)
let authenticationCode = HMAC<SHA512>.authenticationCode(for: messageData, using: SymmetricKey(key))
return AuthenticationData(authenticationCode)
}

/// Encrypt data
internal func encrypt(_ data: Data, using key: KeyData, nonce: Nonce, authentication: AuthenticationMessage) throws -> Data {
let encoder = TLVEncoder.millerBluetooth
let encoder = TLVEncoder.bluetoothAccessory
let authenticatedData = try! encoder.encode(authentication)
do {
let sealed = try ChaChaPoly.seal(data, using: SymmetricKey(key), nonce: ChaChaPoly.Nonce(nonce), authenticating: authenticatedData)
Expand All @@ -41,7 +41,7 @@ internal func encrypt(_ data: Data, using key: KeyData, nonce: Nonce, authentica

/// Decrypt data
internal func decrypt(_ data: Data, using key: KeyData, authentication: AuthenticationMessage) throws -> Data {
let encoder = TLVEncoder.millerBluetooth
let encoder = TLVEncoder.bluetoothAccessory
let authenticatedData = try! encoder.encode(authentication)
do {
let sealed = try ChaChaPoly.SealedBox(combined: data)
Expand Down Expand Up @@ -101,7 +101,7 @@ internal extension SymmetricKey {
}

internal extension ChaChaPoly.Nonce {
init(_ nonce: MillerBluetooth.Nonce) {
init(_ nonce: BluetoothAccessory.Nonce) {
try! self.init(data: nonce.data)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public extension EncryptedData {
guard authentication.isAuthenticated(using: key)
else { throw AuthenticationError.invalidAuthentication }
// attempt to decrypt
return try MillerBluetooth.decrypt(encryptedData, using: key, authentication: authentication.message)
return try BluetoothAccessory.decrypt(encryptedData, using: key, authentication: authentication.message)
}
}

Expand All @@ -47,15 +47,15 @@ extension EncryptedData: TLVCodable {
return nil
}
let prefix = Data(tlvData.prefix(prefixLength))
guard let authentication = try? TLVDecoder.millerBluetooth.decode(Authentication.self, from: prefix) else {
guard let authentication = try? TLVDecoder.BluetoothAccessory.decode(Authentication.self, from: prefix) else {
return nil
}
self.authentication = authentication
self.encryptedData = tlvData.count > prefixLength ? Data(tlvData.suffix(from: prefixLength)) : Data()
}

public var tlvData: Data {
let authenticationData = try! TLVEncoder.millerBluetooth.encode(authentication)
let authenticationData = try! TLVEncoder.BluetoothAccessory.encode(authentication)
return authenticationData + encryptedData
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum ServiceType: UInt16, CaseIterable {
case firmwareUpdate
case wiFiTransport
case threadTransport
case loraTransport
case loRaTransport

// Energy
case battery = 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public protocol TLVCharacteristic: GATTProfileCharacteristic {

public extension TLVCharacteristic {

static var encoder: TLVEncoder { return .millerBluetooth }
static var encoder: TLVEncoder { return .bluetoothAccessory }

static var decoder: TLVDecoder { return .millerBluetooth }
static var decoder: TLVDecoder { return .bluetoothAccessory }
}

public extension TLVCharacteristic where Self: Codable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TLVCoding

public extension TLVEncoder {

static var millerBluetooth: TLVEncoder {
static var bluetoothAccessory: TLVEncoder {
var encoder = TLVEncoder()
encoder.numericFormatting = .littleEndian
encoder.uuidFormatting = .bytes
Expand All @@ -21,7 +21,7 @@ public extension TLVEncoder {

public extension TLVDecoder {

static var millerBluetooth: TLVDecoder {
static var bluetoothAccessory: TLVDecoder {
var decoder = TLVDecoder()
decoder.numericFormatting = .littleEndian
decoder.uuidFormatting = .bytes
Expand Down
1 change: 0 additions & 1 deletion Sources/MillerBluetooth/MillerBluetooth.swift

This file was deleted.

7 changes: 7 additions & 0 deletions Tests/BluetoothAccessoryTests/BluetoothAccessoryTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import XCTest
@testable import BluetoothAccessory

final class BluetoothAccessoryTests: XCTestCase {


}
7 changes: 0 additions & 7 deletions Tests/MillerBluetoothTests/MillerBluetoothTests.swift

This file was deleted.

0 comments on commit 7f5939a

Please sign in to comment.