V0.6.2 Arroyo Toad
Fixed timeconversion to support unixepoch timestamp
This commit is contained in:
parent
ad4fd555f1
commit
f3bc5f32e2
Binary file not shown.
6
Private/signedMessage/public-key.pem
Normal file
6
Private/signedMessage/public-key.pem
Normal file
@ -0,0 +1,6 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQAAH1pxhFDBJWP1yFlEz71+uR19zeS
|
||||
JCSj3VRcw0bWkx0SSpxBL1O2eYiwE/TaW1Xwmm70FyqOyw+bI6CdWaUlXKIA4AhQ
|
||||
qKZlYp9mS7OZcjLWnraVQx/JvgCJUUJJLhppGrDPjletpM0qB5fwi+Hjc9cV8KrD
|
||||
7aAYLz4kRcTSBP9Hc/c=
|
||||
-----END PUBLIC KEY-----
|
||||
@ -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,
|
||||
|
||||
@ -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]
|
||||
}
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user