Sesame-iOS/Sesame/API/MessageResult.swift

97 lines
2.8 KiB
Swift
Raw Normal View History

2022-04-09 17:43:33 +02:00
import Foundation
/**
A result from sending a key to the device.
*/
enum MessageResult: UInt8 {
/// Text content was received, although binary data was expected
case textReceived = 1
/// A socket event on the device was unexpected (not binary data)
case unexpectedSocketEvent = 2
2023-08-09 16:26:43 +02:00
/// The size of the payload (i.e. message) was invalid
case invalidMessageSize = 3
2022-04-09 17:43:33 +02:00
/// The transmitted message could not be authenticated using the key
case messageAuthenticationFailed = 4
/// The message time was not within the acceptable bounds
case messageTimeMismatch = 5
/// A later key has been used, invalidating this key (to prevent replay attacks after blocked communication)
case messageCounterInvalid = 6
/// The key was accepted by the device, and the door will be opened
case messageAccepted = 7
2023-08-07 15:47:40 +02:00
/// The device id is invalid
case messageDeviceInvalid = 8
2022-04-09 17:43:33 +02:00
/// The request did not contain body data with the key
case noBodyData = 10
/// The device is not connected
case deviceNotConnected = 12
/// The device did not respond within the timeout
case deviceTimedOut = 13
/// Another message is being processed by the device
case operationInProgress = 14
/// The device is connected
case deviceConnected = 15
2023-08-09 16:26:43 +02:00
case invalidUrlParameter = 20
case invalidResponseAuthentication = 21
2022-04-09 17:43:33 +02:00
}
extension MessageResult: CustomStringConvertible {
var description: String {
switch self {
case .textReceived:
return "The device received unexpected text"
case .unexpectedSocketEvent:
return "Unexpected socket event for the device"
2023-08-09 16:26:43 +02:00
case .invalidMessageSize:
2022-04-09 17:43:33 +02:00
return "Invalid message data"
case .messageAuthenticationFailed:
return "Message authentication failed"
case .messageTimeMismatch:
return "Message time invalid"
case .messageCounterInvalid:
return "Message counter invalid"
case .messageAccepted:
return "Message accepted"
2023-08-07 15:47:40 +02:00
case .messageDeviceInvalid:
return "Invalid device ID"
2022-04-09 17:43:33 +02:00
case .noBodyData:
return "No body data included in the request"
case .deviceNotConnected:
return "Device not connected"
case .deviceTimedOut:
return "The device did not respond"
case .operationInProgress:
return "Another operation is in progress"
case .deviceConnected:
return "The device is connected"
2023-08-09 16:26:43 +02:00
case .invalidUrlParameter:
return "The url parameter could not be found"
case .invalidResponseAuthentication:
return "The response could not be authenticated"
2022-04-09 17:43:33 +02:00
}
}
}
2023-08-09 16:26:43 +02:00
extension MessageResult {
var encoded: Data {
Data([rawValue])
}
}