Debian Codegraph @

crt/s2n/tls/s2n_handshake_type.c

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #include "tls/s2n_handshake_type.h"
17
18 #include "tls/s2n_connection.h"
19 #include "utils/s2n_safety.h"
20
21 S2N_RESULT s2n_handshake_type_set_flag(struct s2n_connection *conn, s2n_handshake_type_flag flag)
22 {
23 RESULT_ENSURE_REF(conn);
24 conn->handshake.handshake_type |= flag;
25 return S2N_RESULT_OK;
26 }
27
28 bool s2n_handshake_type_check_flag(struct s2n_connection *conn, s2n_handshake_type_flag flag)
29 {
30 return conn && (conn->handshake.handshake_type & flag);
31 }
32
33 S2N_RESULT s2n_handshake_type_set_tls12_flag(struct s2n_connection *conn, s2n_tls12_handshake_type_flag flag)
34 {
35 RESULT_ENSURE_REF(conn);
36 RESULT_ENSURE(s2n_connection_get_protocol_version(conn) < S2N_TLS13, S2N_ERR_HANDSHAKE_STATE);
37 conn->handshake.handshake_type |= flag;
38 RESULT_GUARD(s2n_conn_choose_state_machine(conn, S2N_TLS12));
39 return S2N_RESULT_OK;
40 }
41
42 S2N_RESULT s2n_handshake_type_unset_tls12_flag(struct s2n_connection *conn, s2n_tls12_handshake_type_flag flag)
43 {
44 RESULT_ENSURE_REF(conn);
45 RESULT_ENSURE(s2n_connection_get_protocol_version(conn) < S2N_TLS13, S2N_ERR_HANDSHAKE_STATE);
46 conn->handshake.handshake_type &= ~(flag);
47 return S2N_RESULT_OK;
48 }
49
50 bool s2n_handshake_type_check_tls12_flag(struct s2n_connection *conn, s2n_tls12_handshake_type_flag flag)
51 {
52 return conn && s2n_connection_get_protocol_version(conn) < S2N_TLS13
53 && (conn->handshake.handshake_type & flag);
54 }
55
56 S2N_RESULT s2n_handshake_type_set_tls13_flag(struct s2n_connection *conn, s2n_tls13_handshake_type_flag flag)
57 {
58 RESULT_ENSURE_REF(conn);
59 RESULT_ENSURE(s2n_connection_get_protocol_version(conn) >= S2N_TLS13, S2N_ERR_HANDSHAKE_STATE);
60 conn->handshake.handshake_type |= flag;
61 RESULT_GUARD(s2n_conn_choose_state_machine(conn, S2N_TLS13));
62 return S2N_RESULT_OK;
63 }
64
65 bool s2n_handshake_type_check_tls13_flag(struct s2n_connection *conn, s2n_tls13_handshake_type_flag flag)
66 {
67 return s2n_connection_get_protocol_version(conn) >= S2N_TLS13
68 && (conn->handshake.handshake_type & flag);
69 }
70
71 S2N_RESULT s2n_handshake_type_reset(struct s2n_connection *conn)
72 {
73 RESULT_ENSURE_REF(conn);
74 conn->handshake.handshake_type = 0;
75 return S2N_RESULT_OK;
76 }