Debian Codegraph @

crt/s2n/bindings/rust/standard/benchmarks/src/test_utilities.rs

raw symbols SCIP
1 // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 // SPDX-License-Identifier: Apache-2.0
3
4 use std::io::ErrorKind;
5
6 use tls_harness::{harness::TlsInfo, SigType, TlsConnection};
7
8 use crate::{new_bench_pair, CipherSuite, CryptoConfig, HandshakeType, KXGroup, TlsBenchConfig};
9 use strum::IntoEnumIterator;
10
11 /// Transfer a large amount of application data
12 pub fn transfer<T>()
13 where
14 T: TlsConnection,
15 T::Config: TlsBenchConfig,
16 {
17 // use a large buffer to test across TLS record boundaries
18 let mut buf = [0x56u8; 1000000];
19 for cipher_suite in CipherSuite::iter() {
20 let crypto_config = CryptoConfig::new(cipher_suite, KXGroup::default(), SigType::default());
21 let mut conn_pair =
22 new_bench_pair::<T, T>(crypto_config, HandshakeType::default()).unwrap();
23 conn_pair.handshake().unwrap();
24 conn_pair.round_trip_transfer(&mut buf).unwrap();
25 conn_pair.shutdown().unwrap();
26 }
27 }
28
29 /// Perform all of the different handshake types across a permutation of ciphers,
30 /// key exchange groups, and certificate types.
31 pub fn all_handshakes<T>()
32 where
33 T: TlsConnection + TlsInfo,
34 T::Config: TlsBenchConfig,
35 {
36 for handshake_type in HandshakeType::iter() {
37 for cipher_suite in CipherSuite::iter() {
38 for kx_group in KXGroup::iter() {
39 for sig_type in SigType::iter() {
40 let crypto_config = CryptoConfig::new(cipher_suite, kx_group, sig_type);
41 let mut conn_pair =
42 new_bench_pair::<T, T>(crypto_config, handshake_type).unwrap();
43
44 assert!(!conn_pair.handshake_completed());
45 conn_pair.handshake().unwrap();
46 assert!(conn_pair.handshake_completed());
47
48 assert!(conn_pair.negotiated_tls13());
49 assert_eq!(
50 format!("{cipher_suite:?}"),
51 conn_pair.get_negotiated_cipher_suite()
52 );
53 match handshake_type {
54 HandshakeType::ServerAuth => {
55 assert!(!conn_pair.server.mutual_auth());
56 assert!(!conn_pair.server.resumed_connection());
57 }
58 HandshakeType::MutualAuth => {
59 assert!(conn_pair.server.mutual_auth());
60 assert!(!conn_pair.server.resumed_connection());
61 }
62 HandshakeType::Resumption => {
63 assert!(!conn_pair.server.mutual_auth());
64 assert!(conn_pair.server.resumed_connection());
65 }
66 }
67
68 // read in "application data" handshake messages.
69 // "NewSessionTicket" in the case of resumption
70 let err = conn_pair.client_mut().recv(&mut [0]).unwrap_err();
71 assert_eq!(err.kind(), ErrorKind::WouldBlock);
72
73 conn_pair.shutdown().unwrap();
74 }
75 }
76 }
77 }
78 }