Byte-exact cereal binary layout, RFC 8439 ChaCha20-Poly1305, RFC 7914 scrypt defaults; tokio transport preserving the original's observable behavior (contract B1-B3, B5 quirks included). Parity evidence: golden C++ vectors in tests/vectors.rs and loopback behavior tests; both cross-directions verified against the unmodified C++ binaries. Source: https://git.0xfeedc0de.com/michael/OmniVox
38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
//! Port of the C++ `common.h`: shared payload type and demo constants.
|
|
|
|
use omnivox::{Cereal, CodecError, Reader, write_byte_vec};
|
|
|
|
/// Wire-identical to the C++ `DatagramPayload` (cereal field order:
|
|
/// `id`, `v1.qword`, `payload`; the `PackedValue64` union only ever
|
|
/// serialized its `qword`, so it ports as a plain `u64`).
|
|
#[derive(Debug, Default)]
|
|
pub struct DatagramPayload {
|
|
pub id: u16,
|
|
pub v1: u64,
|
|
pub payload: Vec<u8>,
|
|
}
|
|
|
|
impl Cereal for DatagramPayload {
|
|
fn encode(&self, out: &mut Vec<u8>) {
|
|
out.extend_from_slice(&self.id.to_le_bytes());
|
|
out.extend_from_slice(&self.v1.to_le_bytes());
|
|
write_byte_vec(out, &self.payload);
|
|
}
|
|
|
|
fn decode(bytes: &[u8]) -> Result<Self, CodecError> {
|
|
let mut r = Reader::new(bytes);
|
|
Ok(Self {
|
|
id: r.u16()?,
|
|
v1: r.u64()?,
|
|
payload: r.byte_vec()?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub const PASSWORD: &str = "SecurePassword123";
|
|
pub const SALT: &[u8] = &[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08];
|
|
pub const SERVER_PORT: u16 = 8080;
|
|
/// Only used by the client example.
|
|
#[allow(dead_code)]
|
|
pub const SERVER_ADDR: &str = "127.0.0.1";
|