s2n_quic_core/frame/
path_response.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::frame::Tag;
5use s2n_codec::{decoder_parameterized_value, Encoder, EncoderValue};
6
7//= https://www.rfc-editor.org/rfc/rfc9000#section-19.18
8//# A PATH_RESPONSE frame (type=0x1b) is sent in response to a
9//# PATH_CHALLENGE frame.
10
11macro_rules! path_response_tag {
12    () => {
13        0x1bu8
14    };
15}
16use crate::frame::path_challenge::{PathChallenge, DATA_LEN};
17
18//= https://www.rfc-editor.org/rfc/rfc9000#section-19.18
19//# PATH_RESPONSE Frame {
20//#   Type (i) = 0x1b,
21//#   Data (64),
22//# }
23
24#[derive(Debug, PartialEq, Eq)]
25pub struct PathResponse<'a> {
26    /// This 8-byte field contains arbitrary data.
27    pub data: &'a [u8; DATA_LEN],
28}
29
30impl PathResponse<'_> {
31    pub const fn tag(&self) -> u8 {
32        path_response_tag!()
33    }
34}
35
36impl<'a> From<PathChallenge<'a>> for PathResponse<'a> {
37    fn from(path_challenge: PathChallenge<'a>) -> Self {
38        Self {
39            data: path_challenge.data,
40        }
41    }
42}
43
44decoder_parameterized_value!(
45    impl<'a> PathResponse<'a> {
46        fn decode(_tag: Tag, buffer: Buffer) -> Result<Self> {
47            let (path_challenge, buffer) =
48                buffer.decode_parameterized::<PathChallenge>(path_challenge_tag!())?;
49            Ok((path_challenge.into(), buffer))
50        }
51    }
52);
53
54impl EncoderValue for PathResponse<'_> {
55    fn encode<E: Encoder>(&self, buffer: &mut E) {
56        buffer.encode(&self.tag());
57        buffer.encode(&self.data.as_ref());
58    }
59}