Sesame-iOS/Sesame/API Extensions/MessageType.swift

58 lines
1.2 KiB
Swift
Raw Permalink Normal View History

2023-12-12 17:33:42 +01:00
import Foundation
enum MessageType: UInt8 {
/// The initial message from remote to device to request a challenge.
case initial = 0
/// The second message in an unlock with the challenge from the device to the remote
case challenge = 1
/// The third message with the signed challenge from the remote to the device
case request = 2
/// The final message with the unlock result from the device to the remote
case response = 3
}
extension MessageType {
var encoded: Data {
Data([rawValue])
}
}
extension MessageType: Codable {
}
extension MessageType {
var responseType: MessageType {
switch self {
case .initial:
return .challenge
case .challenge:
return .request
case .request, .response:
return .response
}
}
}
extension MessageType: CustomStringConvertible {
var description: String {
switch self {
case .initial:
return "Initial"
case .challenge:
return "Challenge"
case .request:
return "Request"
case .response:
return "Response"
}
}
}