V0.6.2 Arroyo Toad

Fixed timeconversion to support unixepoch timestamp
This commit is contained in:
Christian Risi 2024-12-06 19:08:29 +00:00
parent ad4fd555f1
commit f3bc5f32e2
6 changed files with 21 additions and 3 deletions

Binary file not shown.

View File

@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQAAH1pxhFDBJWP1yFlEz71+uR19zeS
JCSj3VRcw0bWkx0SSpxBL1O2eYiwE/TaW1Xwmm70FyqOyw+bI6CdWaUlXKIA4AhQ
qKZlYp9mS7OZcjLWnraVQx/JvgCJUUJJLhppGrDPjletpM0qB5fwi+Hjc9cV8KrD
7aAYLz4kRcTSBP9Hc/c=
-----END PUBLIC KEY-----

View File

@ -20,7 +20,7 @@ public func serializeV1(msg: MessageP) -> Data {
serializedData[4...7] = msg.signType.rawValue.data
// First 8 bytes
serializedData[8...15] = msg.timestamp.data
serializedData[8...15] = msg.timestamp.timeIntervalSince1970.data
// 8 Bytes
serializedData[16...31] = msg.devID.data
@ -99,7 +99,7 @@ public func deserializeV1(serializedData: Data) throws -> SignedMessage {
let signBytes = try signatureBytes(signature: signType)
let timestamp = serializedData[8...15].timestamp
let timestamp = serializedData[8...15].double
// 8 Bytes
let devID = serializedData[16...31].uint128
@ -171,7 +171,7 @@ public func deserializeV1(serializedData: Data) throws -> SignedMessage {
devType: devType,
RESERVED: RESERVED,
signType: signType,
timestamp: timestamp,
timestamp: Date(timeIntervalSince1970: timestamp),
devID: devID,
location: Location(x: locationX, y: locationY, z: locationZ),
fields: fields,

View File

@ -29,4 +29,8 @@ public extension Data {
var timestamp: Date {
return self.withUnsafeBytes{ $0.bindMemory(to: Date.self) }[0]
}
var double: Double {
return self.withUnsafeBytes{ $0.bindMemory(to: Double.self) }[0]
}
}

View File

@ -41,3 +41,10 @@ extension Date: DataCompatibleP {
return Data(bytes: &obj, count: MemoryLayout<Self>.stride)
}
}
extension Double: DataCompatibleP {
public var data: Data {
var obj = self
return Data(bytes: &obj, count: MemoryLayout<Self>.stride)
}
}

View File

@ -116,5 +116,6 @@ import Testing
data.append(Data(signature))
try data.write(to: URL(filePath: "./Private/signedMessage/Message.bin"))
try key.publicKey.pemRepresentation.write(to: URL(filePath: "./Private/signedMessage/public-key.pem"), atomically: true, encoding: String.Encoding.utf8)
}