V0.6.9.a Arroyo Toad

Fixed package visibility
This commit is contained in:
Christian Risi 2024-12-08 15:51:42 +00:00
parent 711ad7b5c8
commit 8ae58929b0
4 changed files with 61 additions and 17 deletions

View File

@ -64,6 +64,7 @@ public func serializeV1(msg: MessageP) -> Data {
return serializedData return serializedData
} }
public func signMessage(msgData: Data, signType: SignType, key: P256.Signing.PrivateKey) throws public func signMessage(msgData: Data, signType: SignType, key: P256.Signing.PrivateKey) throws
-> [UInt8] -> [UInt8]
{ {

View File

@ -5,4 +5,12 @@ public struct Field {
public let key: [UInt8] public let key: [UInt8]
public let value: [UInt8] public let value: [UInt8]
public init(
key: [UInt8],
value: [UInt8]
) {
self.key = key
self.value = value
}
} }

View File

@ -3,5 +3,14 @@ public struct Location {
public let x: UInt64 public let x: UInt64
public let y: UInt64 public let y: UInt64
public let z: UInt64 public let z: UInt64
} public init(
x: UInt64,
y: UInt64,
z: UInt64
) {
self.x = x
self.y = y
self.z = z
}
}

View File

@ -1,6 +1,6 @@
import Foundation import Foundation
public struct Message : MessageP{ public struct Message: MessageP {
public let version: UInt8 public let version: UInt8
public let messageType: MessageType public let messageType: MessageType
@ -8,13 +8,37 @@ public struct Message : MessageP{
public let RESERVED: UInt8 public let RESERVED: UInt8
public let signType: SignType public let signType: SignType
public let timestamp : Date public let timestamp: Date
public let devID : UInt128 public let devID: UInt128
public let location: Location public let location: Location
public let fields: [Field] public let fields: [Field]
public init(
public func toString() -> String{ version: UInt8,
messageType: MessageType,
devType: DeviceType,
RESERVED: UInt8,
signType: SignType,
timestamp: Date,
devID: UInt128,
location: Location,
fields: [Field]
) {
self.version = version
self.messageType = messageType
self.devType = devType
self.RESERVED = RESERVED
self.signType = signType
self.timestamp = timestamp
self.devID = devID
self.location = location
self.fields = fields
}
public func toString() -> String {
var description = "" var description = ""
description += "MESSAGE -------\n" description += "MESSAGE -------\n"
description += "V: \t\(self.version)\n" description += "V: \t\(self.version)\n"
@ -24,17 +48,18 @@ public struct Message : MessageP{
description += "Signature Type: \t\(self.signType.rawValue)\n" description += "Signature Type: \t\(self.signType.rawValue)\n"
description += "Timestamp: \t\(self.timestamp)\n" description += "Timestamp: \t\(self.timestamp)\n"
description += "Device ID: \t\(self.devID)\n" description += "Device ID: \t\(self.devID)\n"
description += "Location: \tX: \(self.location.x)\tY: \(self.location.y)\tZ: \(self.location.z)\n" description +=
"Location: \tX: \(self.location.x)\tY: \(self.location.y)\tZ: \(self.location.z)\n"
description += "Fields: \n" description += "Fields: \n"
for field in self.fields { for field in self.fields {
description += "\t\(String(data: Data(field.key), encoding: .ascii) ?? "UNABLE TO DECODE"): \(String(data: Data(field.value), encoding: .ascii) ?? "UNABLE TO DECODE")\n" description +=
"\t\(String(data: Data(field.key), encoding: .ascii) ?? "UNABLE TO DECODE"): \(String(data: Data(field.value), encoding: .ascii) ?? "UNABLE TO DECODE")\n"
} }
return description return description
} }
} }
public struct SignedMessage: MessageP {
public struct SignedMessage : MessageP {
public let version: UInt8 public let version: UInt8
public let messageType: MessageType public let messageType: MessageType
@ -42,14 +67,13 @@ public struct SignedMessage : MessageP {
public let RESERVED: UInt8 public let RESERVED: UInt8
public let signType: SignType public let signType: SignType
public let timestamp : Date public let timestamp: Date
public let devID : UInt128 public let devID: UInt128
public let location: Location public let location: Location
public let fields: [Field] public let fields: [Field]
public let signature: [UInt8] public let signature: [UInt8]
public func toString() -> String {
public func toString() -> String{
var description = "" var description = ""
description += "MESSAGE -------\n" description += "MESSAGE -------\n"
description += "V: \t\(self.version)\n" description += "V: \t\(self.version)\n"
@ -59,13 +83,15 @@ public struct SignedMessage : MessageP {
description += "Signature Type: \t\(self.signType.rawValue)\n" description += "Signature Type: \t\(self.signType.rawValue)\n"
description += "Timestamp: \t\(self.timestamp)\n" description += "Timestamp: \t\(self.timestamp)\n"
description += "Device ID: \t\(self.devID)\n" description += "Device ID: \t\(self.devID)\n"
description += "Location: \tX: \(self.location.x)\tY: \(self.location.y)\tZ: \(self.location.z)\n" description +=
"Location: \tX: \(self.location.x)\tY: \(self.location.y)\tZ: \(self.location.z)\n"
description += "Fields: \n" description += "Fields: \n"
for field in self.fields { for field in self.fields {
description += "\t\(String(data: Data(field.key), encoding: .ascii) ?? "UNABLE TO DECODE"): \(String(data: Data(field.value), encoding: .ascii) ?? "UNABLE TO DECODE")\n" description +=
"\t\(String(data: Data(field.key), encoding: .ascii) ?? "UNABLE TO DECODE"): \(String(data: Data(field.value), encoding: .ascii) ?? "UNABLE TO DECODE")\n"
} }
description += "Signature: \t\(self.signature)\n" description += "Signature: \t\(self.signature)\n"
return description return description
} }
} }