1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::frame::Tag;
use s2n_codec::{decoder_parameterized_value, Encoder, EncoderValue};
macro_rules! path_response_tag {
() => {
0x1bu8
};
}
use crate::frame::path_challenge::{PathChallenge, DATA_LEN};
#[derive(Debug, PartialEq, Eq)]
pub struct PathResponse<'a> {
pub data: &'a [u8; DATA_LEN],
}
impl<'a> PathResponse<'a> {
pub const fn tag(&self) -> u8 {
path_response_tag!()
}
}
impl<'a> From<PathChallenge<'a>> for PathResponse<'a> {
fn from(path_challenge: PathChallenge<'a>) -> Self {
Self {
data: path_challenge.data,
}
}
}
decoder_parameterized_value!(
impl<'a> PathResponse<'a> {
fn decode(_tag: Tag, buffer: Buffer) -> Result<Self> {
let (path_challenge, buffer) =
buffer.decode_parameterized::<PathChallenge>(path_challenge_tag!())?;
Ok((path_challenge.into(), buffer))
}
}
);
impl<'a> EncoderValue for PathResponse<'a> {
fn encode<E: Encoder>(&self, buffer: &mut E) {
buffer.encode(&self.tag());
buffer.encode(&self.data.as_ref());
}
}