Skip to content

Commit 38e80bc

Browse files
committed
refactor: make TLS policy input monomorphic
1 parent d921c77 commit 38e80bc

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

‎crates/originweave-tls/src/policy.rs‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl TlsClientPolicy {
4646
pub fn new(
4747
trusted_time: UnixTime,
4848
handshake_timeout: Duration,
49-
alpn_protocols: impl IntoIterator<Item = Vec<u8>>,
49+
alpn_protocols: Vec<Vec<u8>>,
5050
alpn_requirement: AlpnRequirement,
5151
) -> Result<Self, TlsError> {
5252
if handshake_timeout.is_zero() || handshake_timeout > MAX_TLS_HANDSHAKE_TIMEOUT {
@@ -55,22 +55,19 @@ impl TlsClientPolicy {
5555
maximum_timeout: MAX_TLS_HANDSHAKE_TIMEOUT,
5656
});
5757
}
58-
let protocols: Vec<Vec<u8>> = alpn_protocols
59-
.into_iter()
60-
.take(MAX_ALPN_PROTOCOL_COUNT + 1)
61-
.collect();
62-
if protocols.len() > MAX_ALPN_PROTOCOL_COUNT
63-
|| (protocols.is_empty() && alpn_requirement == AlpnRequirement::Required)
58+
let protocol_count = alpn_protocols.len();
59+
if protocol_count > MAX_ALPN_PROTOCOL_COUNT
60+
|| (alpn_protocols.is_empty() && alpn_requirement == AlpnRequirement::Required)
6461
{
6562
return Err(TlsError::InvalidAlpnCount {
66-
protocol_count: protocols.len(),
63+
protocol_count,
6764
maximum_count: MAX_ALPN_PROTOCOL_COUNT,
6865
});
6966
}
7067

7168
let mut seen = BTreeSet::new();
7269
let mut total_bytes = 0_usize;
73-
for (protocol_index, protocol) in protocols.iter().enumerate() {
70+
for (protocol_index, protocol) in alpn_protocols.iter().enumerate() {
7471
if protocol.is_empty() || protocol.len() > MAX_ALPN_PROTOCOL_LENGTH {
7572
return Err(TlsError::InvalidAlpnIdentifier {
7673
protocol_index,
@@ -93,7 +90,7 @@ impl TlsClientPolicy {
9390
Ok(Self {
9491
trusted_time,
9592
handshake_timeout,
96-
alpn_protocols: protocols,
93+
alpn_protocols,
9794
alpn_requirement,
9895
})
9996
}

0 commit comments

Comments
 (0)