use std::fmt::{Display, Formatter};
#[derive(Debug, PartialEq, Eq, PartialOrd, Hash, Clone, Copy)]
pub enum Version {
Google,
RfcDraft13,
}
struct VersionData {
wire: &'static [u8],
display: &'static str,
dele_prefix: &'static [u8],
srep_prefix: &'static [u8],
}
impl Version {
const fn data(&self) -> VersionData {
match self {
Version::Google => VersionData {
wire: &[0x00, 0x00, 0x00, 0x00],
display: "Google",
dele_prefix: b"RoughTime v1 delegation signature--\x00",
srep_prefix: b"RoughTime v1 response signature\x00",
},
Version::RfcDraft13 => VersionData {
wire: &[0x0c, 0x00, 0x00, 0x80],
display: "RfcDraft13",
dele_prefix: b"RoughTime v1 delegation signature\x00",
srep_prefix: b"RoughTime v1 response signature\x00",
},
}
}
pub fn supported_versions_wire() -> Vec<u8> {
[
Version::Google.wire_bytes(),
Version::RfcDraft13.wire_bytes(),
]
.concat()
}
pub const fn wire_bytes(&self) -> &'static [u8] {
self.data().wire
}
pub const fn as_string(&self) -> &'static str {
self.data().display
}
pub const fn dele_prefix(&self) -> &'static [u8] {
self.data().dele_prefix
}
pub const fn sign_prefix(&self) -> &'static [u8] {
self.data().srep_prefix
}
}
impl Display for Version {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_string())
}
}