47 lines
1.6 KiB
Rust
47 lines
1.6 KiB
Rust
//! Protobuf-generated types for the v2 relay transport
|
|
//! (data/iOS-app/v2/relay-protocol.md §2). Used by both the relay
|
|
//! and (in a separate task) the mobile-connector plugin. Generated by
|
|
//! `build.rs` from `proto/skald/relay/v2/relay_frame.proto` via prost.
|
|
|
|
#![allow(clippy::all, clippy::pedantic)]
|
|
|
|
/// The `OUT_DIR` is the build-script output directory (set by Cargo).
|
|
/// `prost_build` writes `skald.relay.v2.rs` into it.
|
|
pub mod v2 {
|
|
include!(concat!(env!("OUT_DIR"), "/skald.relay.v2.rs"));
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::v2::*;
|
|
use super::v2::relay_frame::Frame;
|
|
|
|
#[test]
|
|
fn proto_types_construct() {
|
|
// Round-trip a Challenge and a Message with all fields set.
|
|
//
|
|
// Note: prost 0.13 generates `bytes` fields as `::prost::bytes::Bytes`
|
|
// (re-export of `bytes::Bytes`), not `Vec<u8>` as the spec originally
|
|
// suggested. `Bytes: From<Vec<u8>>` so a `.into()` on the literal
|
|
// produces a value the generated struct accepts. The wire encoding
|
|
// is identical — both types are zero-copy compatible on the wire.
|
|
let ch = RelayFrame {
|
|
frame: Some(Frame::Challenge(Challenge {
|
|
nonce: vec![0u8; 32].into(),
|
|
})),
|
|
};
|
|
assert!(matches!(ch.frame, Some(Frame::Challenge(_))));
|
|
|
|
let msg = Message {
|
|
ciphertext: vec![1, 2, 3].into(),
|
|
nonce: vec![0u8; 12].into(),
|
|
peer: vec![0u8; 32].into(),
|
|
live: true,
|
|
};
|
|
let framed = RelayFrame {
|
|
frame: Some(Frame::Message(msg)),
|
|
};
|
|
assert!(matches!(framed.frame, Some(Frame::Message(_))));
|
|
}
|
|
}
|