Skip to content

Commit

Permalink
Chase through cfg(feature = "tls12") gates
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed Oct 19, 2023
1 parent 7b456d9 commit 1fbb608
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
14 changes: 13 additions & 1 deletion rustls/src/msgs/handshake.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![allow(non_camel_case_types)]

use crate::crypto::{ActiveKeyExchange, CryptoProvider};
#[cfg(feature = "tls12")]
use crate::crypto::ActiveKeyExchange;
use crate::crypto::CryptoProvider;
use crate::dns_name::{DnsName, DnsNameRef};
use crate::enums::{CipherSuite, HandshakeType, ProtocolVersion, SignatureScheme};
use crate::error::InvalidMessage;
Expand Down Expand Up @@ -175,6 +177,7 @@ impl SessionId {
}
}

#[cfg(feature = "tls12")]
pub(crate) fn is_empty(&self) -> bool {
self.len == 0
}
Expand Down Expand Up @@ -784,6 +787,7 @@ impl ServerExtension {
Self::Protocols(Vec::from_slices(proto))
}

#[cfg(feature = "tls12")]
pub(crate) fn make_empty_renegotiation_info() -> Self {
let empty = Vec::new();
Self::RenegotiationInfo(PayloadU8::new(empty))
Expand Down Expand Up @@ -895,6 +899,7 @@ impl ClientHelloPayload {
}
}

#[cfg(feature = "tls12")]
pub(crate) fn get_ecpoints_extension(&self) -> Option<&[ECPointFormat]> {
let ext = self.find_extension(ExtensionType::ECPointFormats)?;
match *ext {
Expand Down Expand Up @@ -923,6 +928,7 @@ impl ClientHelloPayload {
}
}

#[cfg(feature = "tls12")]
pub(crate) fn get_ticket_extension(&self) -> Option<&ClientExtension> {
self.find_extension(ExtensionType::SessionTicket)
}
Expand Down Expand Up @@ -994,6 +1000,7 @@ impl ClientHelloPayload {
}
}

#[cfg(feature = "tls12")]
pub(crate) fn ems_support_offered(&self) -> bool {
self.find_extension(ExtensionType::ExtendedMasterSecret)
.is_some()
Expand Down Expand Up @@ -1234,6 +1241,7 @@ impl ServerHelloPayload {
}
}

#[cfg(feature = "tls12")]
pub(crate) fn ems_support_acked(&self) -> bool {
self.find_extension(ExtensionType::ExtendedMasterSecret)
.is_some()
Expand Down Expand Up @@ -1508,6 +1516,7 @@ pub(crate) struct ServerEcdhParams {
}

impl ServerEcdhParams {
#[cfg(feature = "tls12")]
pub(crate) fn new(kx: &dyn ActiveKeyExchange) -> Self {
Self {
curve_params: EcParameters {
Expand Down Expand Up @@ -1578,6 +1587,7 @@ impl Codec for ServerKeyExchangePayload {
}

impl ServerKeyExchangePayload {
#[cfg(feature = "tls12")]
pub(crate) fn unwrap_given_kxa(
&self,
kxa: KeyExchangeAlgorithm,
Expand Down Expand Up @@ -1847,6 +1857,7 @@ pub struct NewSessionTicketPayload {
}

impl NewSessionTicketPayload {
#[cfg(feature = "tls12")]
pub(crate) fn new(lifetime_hint: u32, ticket: Vec<u8>) -> Self {
Self {
lifetime_hint,
Expand Down Expand Up @@ -2027,6 +2038,7 @@ impl CertificateStatus {
}
}

#[cfg(feature = "tls12")]
pub(crate) fn into_inner(self) -> Vec<u8> {
self.ocsp_response.0
}
Expand Down
5 changes: 5 additions & 0 deletions rustls/src/msgs/handshake_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ fn accepts_short_sessionid() {
let sess = SessionId::read(&mut rd).unwrap();
println!("{:?}", sess);

#[cfg(feature = "tls12")]
assert!(!sess.is_empty());
assert_ne!(sess, SessionId::empty());
assert!(!rd.any_left());
}

Expand All @@ -85,7 +87,9 @@ fn accepts_empty_sessionid() {
let sess = SessionId::read(&mut rd).unwrap();
println!("{:?}", sess);

#[cfg(feature = "tls12")]
assert!(sess.is_empty());
assert_eq!(sess, SessionId::empty());
assert!(!rd.any_left());
}

Expand Down Expand Up @@ -520,6 +524,7 @@ fn client_get_namedgroups_extension() {
});
}

#[cfg(feature = "tls12")]
#[test]
fn client_get_ecpoints_extension() {
test_client_extension_getter(ExtensionType::ECPointFormats, |chp| {
Expand Down
2 changes: 2 additions & 0 deletions rustls/src/msgs/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::error::InvalidMessage;
use crate::msgs::base::{PayloadU16, PayloadU8};
use crate::msgs::codec::{Codec, Reader};
use crate::msgs::handshake::CertificatePayload;
#[cfg(feature = "tls12")]
use crate::msgs::handshake::SessionId;
#[cfg(feature = "tls12")]
use crate::tls12::Tls12CipherSuite;
Expand Down Expand Up @@ -375,6 +376,7 @@ impl ServerSessionValue {
}
}

#[cfg(feature = "tls12")]
pub(crate) fn set_extended_ms_used(&mut self) {
self.extended_ms = true;
}
Expand Down

0 comments on commit 1fbb608

Please sign in to comment.