tor-cell: Implement rendezvous1 and rendezvous2.
This commit is contained in:
parent
841905948f
commit
c302246e57
|
@ -163,11 +163,26 @@ pub struct Rendezvous1 {
|
|||
|
||||
impl Body for Rendezvous1 {
|
||||
fn decode_from_reader(r: &mut Reader<'_>) -> Result<Self> {
|
||||
todo!()
|
||||
let cookie = r.extract()?;
|
||||
let message = r.take_rest().into();
|
||||
Ok(Self { cookie, message })
|
||||
}
|
||||
|
||||
fn encode_onto<W: Writer + ?Sized>(self, w: &mut W) -> EncodeResult<()> {
|
||||
todo!()
|
||||
w.write(&self.cookie)?;
|
||||
w.write_all(&self.message[..]);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Rendezvous1 {
|
||||
/// Create a new Rendezvous1 message, to handshake with a client identified
|
||||
/// by a given RendCookie, and send it a given message.
|
||||
pub fn new(cookie: RendCookie, message: impl Into<Vec<u8>>) -> Self {
|
||||
Self {
|
||||
cookie,
|
||||
message: message.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,13 +194,32 @@ pub struct Rendezvous2 {
|
|||
message: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Rendezvous2 {
|
||||
/// Construct a new Rendezvous2 cell containing a given message.
|
||||
pub fn new(message: impl Into<Vec<u8>>) -> Self {
|
||||
Self {
|
||||
message: message.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Rendezvous1> for Rendezvous2 {
|
||||
fn from(value: Rendezvous1) -> Self {
|
||||
Self {
|
||||
message: value.message,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Body for Rendezvous2 {
|
||||
fn decode_from_reader(r: &mut Reader<'_>) -> Result<Self> {
|
||||
todo!()
|
||||
let message = r.take_rest().into();
|
||||
Ok(Self { message })
|
||||
}
|
||||
|
||||
fn encode_onto<W: Writer + ?Sized>(self, w: &mut W) -> EncodeResult<()> {
|
||||
todo!()
|
||||
w.write_all(&self.message[..]);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -771,3 +771,25 @@ fn test_introduce() {
|
|||
// TODO: need to add tests for:
|
||||
// - unrecognized
|
||||
// - data
|
||||
|
||||
#[test]
|
||||
fn test_rendezvous() {
|
||||
use tor_cell::relaycell::hs::{Rendezvous1, Rendezvous2};
|
||||
use tor_hscrypto::RendCookie;
|
||||
|
||||
let cmd1 = RelayCmd::RENDEZVOUS1;
|
||||
let cmd2 = RelayCmd::RENDEZVOUS2;
|
||||
|
||||
let cookie = RendCookie::from([0; 20]);
|
||||
// Introduce1 with no extension
|
||||
let rend1 = Rendezvous1::new(cookie, hex!("123456"));
|
||||
msg(
|
||||
cmd1,
|
||||
"0000000000000000000000000000000000000000
|
||||
123456",
|
||||
&rend1.clone().into(),
|
||||
);
|
||||
|
||||
let rend2: Rendezvous2 = rend1.into();
|
||||
msg(cmd2, "123456", &rend2.into());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue