#![forbid(unsafe_code)]
pub mod client;
pub mod frame;
pub use client::{Client, MAX_PACKET};
pub use frame::{Frame, FrameType};
pub const MAGIC: [u8; 8] = [b'D', b'E', b'R', b'P', 0xf0, 0x9f, 0x94, 0x91];
pub const VERSION: u32 = 2;
pub const PATH: &str = "/derp";
pub const UPGRADE_TOKEN: &str = "DERP";
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Error {
Incomplete,
Malformed,
Decryption,
TooLarge,
BufferTooSmall,
Unsupported,
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(match self {
Self::Incomplete => "incomplete",
Self::Malformed => "malformed DERP frame",
Self::Decryption => "the DERP handshake did not open",
Self::TooLarge => "frame larger than the client will hold",
Self::BufferTooSmall => "output buffer too small",
Self::Unsupported => "unsupported DERP version",
})
}
}
impl core::error::Error for Error {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_magic_is_what_a_real_server_sends() {
assert_eq!(MAGIC.len(), 8);
assert_eq!(&MAGIC, "DERP\u{1f511}".as_bytes());
assert_eq!(&MAGIC[..4], b"DERP");
}
}