/rust/registry/src/index.crates.io-1949cf8c6b5b557f/rustls-0.23.42/src/check.rs
Line | Count | Source |
1 | | use crate::enums::{ContentType, HandshakeType}; |
2 | | use crate::error::Error; |
3 | | use crate::log::warn; |
4 | | use crate::msgs::message::MessagePayload; |
5 | | |
6 | | /// For a Message $m, and a HandshakePayload enum member $payload_type, |
7 | | /// return Ok(payload) if $m is both a handshake message and one that |
8 | | /// has the given $payload_type. If not, return Err(rustls::Error) quoting |
9 | | /// $handshake_type as the expected handshake type. |
10 | | macro_rules! require_handshake_msg( |
11 | | ( $m:expr, $handshake_type:path, $payload_type:path ) => ( |
12 | | match &$m.payload { |
13 | | MessagePayload::Handshake { parsed: $crate::msgs::handshake::HandshakeMessagePayload( |
14 | | $payload_type(hm), |
15 | | ), .. } => Ok(hm), |
16 | | payload => Err($crate::check::inappropriate_handshake_message( |
17 | | payload, |
18 | | &[$crate::ContentType::Handshake], |
19 | | &[$handshake_type])) |
20 | | } |
21 | | ) |
22 | | ); |
23 | | |
24 | | /// Like require_handshake_msg, but moves the payload out of $m. |
25 | | macro_rules! require_handshake_msg_move( |
26 | | ( $m:expr, $handshake_type:path, $payload_type:path ) => ( |
27 | | match $m.payload { |
28 | | MessagePayload::Handshake { parsed: $crate::msgs::handshake::HandshakeMessagePayload( |
29 | | $payload_type(hm), |
30 | | ), .. } => Ok(hm), |
31 | | payload => |
32 | | Err($crate::check::inappropriate_handshake_message( |
33 | | &payload, |
34 | | &[$crate::ContentType::Handshake], |
35 | | &[$handshake_type])) |
36 | | } |
37 | | ) |
38 | | ); |
39 | | |
40 | 0 | pub(crate) fn inappropriate_message( |
41 | 0 | payload: &MessagePayload<'_>, |
42 | 0 | content_types: &[ContentType], |
43 | 0 | ) -> Error { |
44 | 0 | warn!( |
45 | | "Received a {:?} message while expecting {content_types:?}", |
46 | | payload.content_type(), |
47 | | ); |
48 | 0 | Error::InappropriateMessage { |
49 | 0 | expect_types: content_types.to_vec(), |
50 | 0 | got_type: payload.content_type(), |
51 | 0 | } |
52 | 0 | } Unexecuted instantiation: rustls::check::inappropriate_message Unexecuted instantiation: rustls::check::inappropriate_message |
53 | | |
54 | 0 | pub(crate) fn inappropriate_handshake_message( |
55 | 0 | payload: &MessagePayload<'_>, |
56 | 0 | content_types: &[ContentType], |
57 | 0 | handshake_types: &[HandshakeType], |
58 | 0 | ) -> Error { |
59 | 0 | match payload { |
60 | 0 | MessagePayload::Handshake { parsed, .. } => { |
61 | 0 | let got_type = parsed.0.handshake_type(); |
62 | 0 | warn!("Received a {got_type:?} handshake message while expecting {handshake_types:?}",); |
63 | 0 | Error::InappropriateHandshakeMessage { |
64 | 0 | expect_types: handshake_types.to_vec(), |
65 | 0 | got_type, |
66 | 0 | } |
67 | | } |
68 | 0 | payload => inappropriate_message(payload, content_types), |
69 | | } |
70 | 0 | } Unexecuted instantiation: rustls::check::inappropriate_handshake_message Unexecuted instantiation: rustls::check::inappropriate_handshake_message |