Branch data Line data Source code
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 : 27700 : { 23 [ + + ][ + - ]: 27700 : RESULT_ENSURE_REF(conn); 24 : 27699 : conn->handshake.handshake_type |= flag; 25 : 27699 : return S2N_RESULT_OK; 26 : 27700 : } 27 : : 28 : : bool s2n_handshake_type_check_flag(struct s2n_connection *conn, s2n_handshake_type_flag flag) 29 : 3315823 : { 30 [ + + ][ + + ]: 3315823 : return conn && (conn->handshake.handshake_type & flag); 31 : 3315823 : } 32 : : 33 : : S2N_RESULT s2n_handshake_type_set_tls12_flag(struct s2n_connection *conn, s2n_tls12_handshake_type_flag flag) 34 : 1801 : { 35 [ + - ][ + + ]: 1801 : RESULT_ENSURE_REF(conn); 36 [ + + ][ + - ]: 1800 : RESULT_ENSURE(s2n_connection_get_protocol_version(conn) < S2N_TLS13, S2N_ERR_HANDSHAKE_STATE); 37 : 1751 : conn->handshake.handshake_type |= flag; 38 [ - + ]: 1751 : RESULT_GUARD(s2n_conn_choose_state_machine(conn, S2N_TLS12)); 39 : 1751 : return S2N_RESULT_OK; 40 : 1751 : } 41 : : 42 : : S2N_RESULT s2n_handshake_type_unset_tls12_flag(struct s2n_connection *conn, s2n_tls12_handshake_type_flag flag) 43 : 24 : { 44 [ - + ][ # # ]: 24 : RESULT_ENSURE_REF(conn); 45 [ - + ][ # # ]: 24 : RESULT_ENSURE(s2n_connection_get_protocol_version(conn) < S2N_TLS13, S2N_ERR_HANDSHAKE_STATE); 46 : 24 : conn->handshake.handshake_type &= ~(flag); 47 : 24 : return S2N_RESULT_OK; 48 : 24 : } 49 : : 50 : : bool s2n_handshake_type_check_tls12_flag(struct s2n_connection *conn, s2n_tls12_handshake_type_flag flag) 51 : 331 : { 52 [ + + ][ + + ]: 331 : return conn && s2n_connection_get_protocol_version(conn) < S2N_TLS13 53 [ + + ]: 331 : && (conn->handshake.handshake_type & flag); 54 : 331 : } 55 : : 56 : : S2N_RESULT s2n_handshake_type_set_tls13_flag(struct s2n_connection *conn, s2n_tls13_handshake_type_flag flag) 57 : 14119 : { 58 [ + + ][ + - ]: 14119 : RESULT_ENSURE_REF(conn); 59 [ + - ][ + + ]: 14118 : RESULT_ENSURE(s2n_connection_get_protocol_version(conn) >= S2N_TLS13, S2N_ERR_HANDSHAKE_STATE); 60 : 14005 : conn->handshake.handshake_type |= flag; 61 [ - + ]: 14005 : RESULT_GUARD(s2n_conn_choose_state_machine(conn, S2N_TLS13)); 62 : 14005 : return S2N_RESULT_OK; 63 : 14005 : } 64 : : 65 : : bool s2n_handshake_type_check_tls13_flag(struct s2n_connection *conn, s2n_tls13_handshake_type_flag flag) 66 : 104465 : { 67 [ + + ]: 104465 : return s2n_connection_get_protocol_version(conn) >= S2N_TLS13 68 [ + + ]: 104465 : && (conn->handshake.handshake_type & flag); 69 : 104465 : } 70 : : 71 : : S2N_RESULT s2n_handshake_type_reset(struct s2n_connection *conn) 72 : 4780 : { 73 [ - + ][ # # ]: 4780 : RESULT_ENSURE_REF(conn); 74 : 4780 : conn->handshake.handshake_type = 0; 75 : 4780 : return S2N_RESULT_OK; 76 : 4780 : }