From 59ee30545e0851bb26f2b00305cb5c672113dbde Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Fri, 1 May 2020 12:34:22 -0700 Subject: [PATCH] Format quic --- rustls/src/quic.rs | 69 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/rustls/src/quic.rs b/rustls/src/quic.rs index d2dcbdf0..2bdfdb7d 100644 --- a/rustls/src/quic.rs +++ b/rustls/src/quic.rs @@ -1,15 +1,16 @@ /// This module contains optional APIs for implementing QUIC TLS. use crate::client::{ClientConfig, ClientSession, ClientSessionImpl}; -use crate::msgs::enums::{ContentType, ProtocolVersion, AlertDescription}; +use crate::error::TLSError; +use crate::key_schedule::hkdf_expand; +use crate::msgs::enums::{AlertDescription, ContentType, ProtocolVersion}; use crate::msgs::handshake::{ClientExtension, ServerExtension}; use crate::msgs::message::{Message, MessagePayload}; use crate::server::{ServerConfig, ServerSession, ServerSessionImpl}; -use crate::error::TLSError; -use crate::key_schedule::hkdf_expand; -use crate::session::{SessionCommon, Protocol}; +use crate::session::{Protocol, SessionCommon}; use crate::suites::{BulkAlgorithm, SupportedCipherSuite, TLS13_AES_128_GCM_SHA256}; use std::sync::Arc; + use ring::{aead, hkdf}; use webpki; @@ -77,9 +78,14 @@ impl QuicExt for ClientSession { read_hs(&mut self.imp.common, plaintext)?; self.imp.process_new_handshake_messages() } - fn write_hs(&mut self, buf: &mut Vec) -> Option { write_hs(&mut self.imp.common, buf) } - fn get_alert(&self) -> Option { self.imp.common.quic.alert } + fn write_hs(&mut self, buf: &mut Vec) -> Option { + write_hs(&mut self.imp.common, buf) + } + + fn get_alert(&self) -> Option { + self.imp.common.quic.alert + } fn next_1rtt_keys(&mut self) -> PacketKeySet { next_1rtt_keys(&mut self.imp.common) @@ -102,9 +108,13 @@ impl QuicExt for ServerSession { read_hs(&mut self.imp.common, plaintext)?; self.imp.process_new_handshake_messages() } - fn write_hs(&mut self, buf: &mut Vec) -> Option { write_hs(&mut self.imp.common, buf) } + fn write_hs(&mut self, buf: &mut Vec) -> Option { + write_hs(&mut self.imp.common, buf) + } - fn get_alert(&self) -> Option { self.imp.common.quic.alert } + fn get_alert(&self) -> Option { + self.imp.common.quic.alert + } fn next_1rtt_keys(&mut self) -> PacketKeySet { next_1rtt_keys(&mut self.imp.common) @@ -237,7 +247,8 @@ fn read_hs(this: &mut SessionCommon, plaintext: &[u8]) -> Result<(), TLSError> { typ: ContentType::Handshake, version: ProtocolVersion::TLSv1_3, payload: MessagePayload::new_opaque(plaintext.into()), - }).is_none() + }) + .is_none() { this.quic.alert = Some(AlertDescription::DecodeError); return Err(TLSError::CorruptMessage); @@ -299,14 +310,24 @@ pub trait ClientQuicExt { /// Make a new QUIC ClientSession. This differs from `ClientSession::new()` /// in that it takes an extra argument, `params`, which contains the /// TLS-encoded transport parameters to send. - fn new_quic(config: &Arc, hostname: webpki::DNSNameRef, params: Vec) - -> ClientSession { - assert!(config.versions.iter().all(|x| x.get_u16() >= ProtocolVersion::TLSv1_3.get_u16()), "QUIC requires TLS version >= 1.3"); + fn new_quic( + config: &Arc, + hostname: webpki::DNSNameRef, + params: Vec, + ) -> ClientSession { + assert!( + config + .versions + .iter() + .all(|x| x.get_u16() >= ProtocolVersion::TLSv1_3.get_u16()), + "QUIC requires TLS version >= 1.3" + ); let mut imp = ClientSessionImpl::new(config); imp.common.protocol = Protocol::Quic; - imp.start_handshake(hostname.into(), vec![ - ClientExtension::TransportParameters(params), - ]); + imp.start_handshake( + hostname.into(), + vec![ClientExtension::TransportParameters(params)], + ); ClientSession { imp } } } @@ -319,11 +340,19 @@ pub trait ServerQuicExt { /// in that it takes an extra argument, `params`, which contains the /// TLS-encoded transport parameters to send. fn new_quic(config: &Arc, params: Vec) -> ServerSession { - assert!(config.versions.iter().all(|x| x.get_u16() >= ProtocolVersion::TLSv1_3.get_u16()), "QUIC requires TLS version >= 1.3"); - assert!(config.max_early_data_size == 0 || config.max_early_data_size == 0xffff_ffff, "QUIC sessions must set a max early data of 0 or 2^32-1"); - let mut imp = ServerSessionImpl::new(config, vec![ - ServerExtension::TransportParameters(params), - ]); + assert!( + config + .versions + .iter() + .all(|x| x.get_u16() >= ProtocolVersion::TLSv1_3.get_u16()), + "QUIC requires TLS version >= 1.3" + ); + assert!( + config.max_early_data_size == 0 || config.max_early_data_size == 0xffff_ffff, + "QUIC sessions must set a max early data of 0 or 2^32-1" + ); + let mut imp = + ServerSessionImpl::new(config, vec![ServerExtension::TransportParameters(params)]); imp.common.protocol = Protocol::Quic; ServerSession { imp } }