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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use crate::error::Error;
#[cfg(feature = "logging")]
use crate::log::warn;
use crate::msgs::enums::{ContentType, HandshakeType};
use crate::msgs::message::MessagePayload;
macro_rules! require_handshake_msg(
( $m:expr, $handshake_type:path, $payload_type:path ) => (
match &$m.payload {
MessagePayload::Handshake { parsed: $crate::msgs::handshake::HandshakeMessagePayload {
payload: $payload_type(hm),
..
}, .. } => Ok(hm),
payload => Err($crate::check::inappropriate_handshake_message(
payload,
&[$crate::msgs::enums::ContentType::Handshake],
&[$handshake_type]))
}
)
);
#[cfg(feature = "tls12")]
macro_rules! require_handshake_msg_move(
( $m:expr, $handshake_type:path, $payload_type:path ) => (
match $m.payload {
MessagePayload::Handshake { parsed: $crate::msgs::handshake::HandshakeMessagePayload {
payload: $payload_type(hm),
..
}, .. } => Ok(hm),
payload =>
Err($crate::check::inappropriate_handshake_message(
&payload,
&[$crate::msgs::enums::ContentType::Handshake],
&[$handshake_type]))
}
)
);
pub(crate) fn inappropriate_message(
payload: &MessagePayload,
content_types: &[ContentType],
) -> Error {
warn!(
"Received a {:?} message while expecting {:?}",
payload.content_type(),
content_types
);
Error::InappropriateMessage {
expect_types: content_types.to_vec(),
got_type: payload.content_type(),
}
}
pub(crate) fn inappropriate_handshake_message(
payload: &MessagePayload,
content_types: &[ContentType],
handshake_types: &[HandshakeType],
) -> Error {
match payload {
MessagePayload::Handshake { parsed, .. } => {
warn!(
"Received a {:?} handshake message while expecting {:?}",
parsed.typ, handshake_types
);
Error::InappropriateHandshakeMessage {
expect_types: handshake_types.to_vec(),
got_type: parsed.typ,
}
}
payload => inappropriate_message(payload, content_types),
}
}