round trip ControlMessage auth test

This commit is contained in:
Evan Feenstra
2022-09-08 14:47:58 -07:00
parent 21ed9f97ea
commit de68957cdf
11 changed files with 65 additions and 33 deletions

View File

@@ -38,8 +38,8 @@ impl Controller {
}
pub fn build_msg(&mut self, msg: ControlMessage) -> anyhow::Result<Vec<u8>> {
let data = rmp_serde::to_vec(&msg)?;
let ret = nonce::build_msg(&data, &self.0, self.2)?;
self.2 = self.2 + 1;
let ret = nonce::build_msg(&data, &self.0, self.2)?;
Ok(ret)
}
pub fn build_response(&self, msg: ControlResponse) -> anyhow::Result<Vec<u8>> {
@@ -54,4 +54,12 @@ impl Controller {
pub fn parse_response(&self, input: &[u8]) -> anyhow::Result<ControlResponse> {
Ok(rmp_serde::from_slice(input)?)
}
pub fn handle(&mut self, input: &[u8]) -> anyhow::Result<Vec<u8>> {
let msg = self.parse_msg(input)?;
let res = match msg {
ControlMessage::Nonce => ControlResponse::Nonce(self.2),
_ => ControlResponse::Nonce(self.2),
};
Ok(self.build_response(res)?)
}
}