Skip to content

Commit 06e0af7

Browse files
committed
Implement feedback
1 parent d10e051 commit 06e0af7

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- /usr/local/cargo/registry/index
2222
- restore_cache:
2323
key: deps-<< parameters.image >>-{{ checksum "Cargo.lock" }}
24-
- run: cargo test
24+
- run: cargo test --features alpn
2525
- run: rustdoc --test README.md -L target/debug/deps -L target/debug
2626
- save_cache:
2727
key: deps-<< parameters.image >>-{{ checksum "Cargo.lock" }}
@@ -51,7 +51,7 @@ jobs:
5151
- ~/.cargo/registry/index
5252
- restore_cache:
5353
key: macos-deps-<< parameters.version >>
54-
- run: cargo test
54+
- run: cargo test --features alpn
5555
- save_cache:
5656
key: macos-deps-<< parameters.version >>
5757
paths:

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ readme = "README.md"
1010
[features]
1111
vendored = ["openssl/vendored"]
1212

13+
# Switch for MacOS to keep support for older versions, Windows targets and openssl target will have alpn regardless
14+
alpn = ["security-framework/alpn"]
15+
1316
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
14-
security-framework = {version = "2.0.0", features = ["alpn"]}
17+
security-framework = "2.0.0"
1518
security-framework-sys = "2.0.0"
1619
lazy_static = "1.4.0"
1720
libc = "0.2"

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,11 @@ impl<S: io::Read + io::Write> TlsStream<S> {
656656

657657
/// Returns the negotiated ALPN protocols
658658
pub fn negotiated_alpn(&self) -> Result<Option<String>> {
659-
Ok(self
659+
let protocol = self
660660
.0
661661
.negotiated_alpn()?
662-
.map(|bytes| String::from_utf8(bytes).unwrap())) //negotiated_alpn always returns valid utf-8
662+
.map(|bytes| String::from_utf8_lossy(&bytes).into_owned());
663+
Ok(protocol)
663664
}
664665

665666
/// Shuts down the TLS session.

src/test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ mod tests {
420420
}
421421

422422
#[test]
423+
#[cfg_attr(not(feature = "alpn"), ignore)]
423424
fn alpn_google_h2() {
424425
let builder = p!(TlsConnector::builder().request_alpns(&["h2"]).build());
425426
let s = p!(TcpStream::connect("google.com:443"));
@@ -434,6 +435,7 @@ mod tests {
434435
}
435436

436437
#[test]
438+
#[cfg_attr(not(feature = "alpn"), ignore)]
437439
fn alpn_google_invalid() {
438440
let builder = p!(TlsConnector::builder().request_alpns(&["h2c"]).build());
439441
let s = p!(TcpStream::connect("google.com:443"));
@@ -448,6 +450,7 @@ mod tests {
448450
}
449451

450452
#[test]
453+
#[cfg_attr(not(feature = "alpn"), ignore)]
451454
fn alpn_google_none() {
452455
let builder = p!(TlsConnector::new());
453456
let s = p!(TcpStream::connect("google.com:443"));

0 commit comments

Comments
 (0)