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
}
public func signMessage(msgData: Data, signType: SignType, key: P256.Signing.PrivateKey) throws
-> [UInt8]
{

View File

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

View File

@ -4,4 +4,13 @@ public struct Location {
public let y: 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
public struct Message : MessageP{
public struct Message: MessageP {
public let version: UInt8
public let messageType: MessageType
@ -8,13 +8,37 @@ public struct Message : MessageP{
public let RESERVED: UInt8
public let signType: SignType
public let timestamp : Date
public let devID : UInt128
public let timestamp: Date
public let devID: UInt128
public let location: Location
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 = ""
description += "MESSAGE -------\n"
description += "V: \t\(self.version)\n"
@ -24,17 +48,18 @@ public struct Message : MessageP{
description += "Signature Type: \t\(self.signType.rawValue)\n"
description += "Timestamp: \t\(self.timestamp)\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"
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
}
}
public struct SignedMessage : MessageP {
public struct SignedMessage: MessageP {
public let version: UInt8
public let messageType: MessageType
@ -42,14 +67,13 @@ public struct SignedMessage : MessageP {
public let RESERVED: UInt8
public let signType: SignType
public let timestamp : Date
public let devID : UInt128
public let timestamp: Date
public let devID: UInt128
public let location: Location
public let fields: [Field]
public let signature: [UInt8]
public func toString() -> String{
public func toString() -> String {
var description = ""
description += "MESSAGE -------\n"
description += "V: \t\(self.version)\n"
@ -59,10 +83,12 @@ public struct SignedMessage : MessageP {
description += "Signature Type: \t\(self.signType.rawValue)\n"
description += "Timestamp: \t\(self.timestamp)\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"
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"