CodeSampleX

示例

hyper-rustls 0.27.9: hyper_rustls::HttpsConnector

已验证示例 — cargo hyper-rustls 0.27.9: hyper_rustls::HttpsConnector. contract 在 rust 1 · linux alpine/x64 · docker 上运行并通过: HttpsConnector::<T>::builder()…

sha256:acf22dfb6af31ffb2cba1fa4795bb34ea38cbeb7b3627917011864f48579144c

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 linux · alpine · musl x64 cargo

验证运行环境

环境 契约 阶段 运行日期
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-11-23

案例

HOW
目标
verify hyper_rustls::HttpsConnector in pkg:cargo/hyper-rustls@0.27.9
包
符号
  • hyper_rustls::HttpsConnector
创建时间
2026-11-23T18:18:56Z

契约

  1. HttpsConnector::<T>::builder() (requiring a turbofish for T, or HttpsConnectorBuilder::new()) builds an HttpsConnector<HttpConnector> and panics if ClientConfig::alpn_protocols is pre-populated
  2. HttpsConnector rejects non-HTTPS schemes with 'unsupported scheme <scheme>' when https_only is enabled and rejects schemeless URIs with 'missing scheme'
  3. HttpsConnector::from((inner, tls_config)) allows HTTP pass-through as MaybeHttpsStream::Http until enforce_https() is called
  4. HttpsConnector with enable_http1().enable_http2().wrap_connector() performs TLS handshakes returning MaybeHttpsStream::Https with h2 ALPN reflected in connected().is_negotiated_h2()
  5. HttpsConnector::new() with FixedServerNameResolver overrides the URI hostname for TLS SNI and server certificate verification

文件

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.rs

下载源代码构件 (tar.gz)

源代码

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "atomic-waker"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"

[[package]]
name = "bytes"
version = "1.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "776dfebd015e2d8732c684a2c71003674ccb49457b539b9e82151ba38e96dd7c"

[[package]]
name = "cc"
version = "1.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02f0e023adb368345ce0ca6cdfc0f24a06554468d0e8503e14a0841de79bfa69"
dependencies = [
 "find-msvc-tools",
 "shlex",
]

[[package]]
name = "cfg-if"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"

[[package]]
name = "deranged"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e"

[[package]]
name = "equivalent"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"

[[package]]
name = "find-msvc-tools"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"

[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"

[[package]]
name = "futures-channel"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4"
dependencies = [
 "futures-core",
]

[[package]]
name = "futures-core"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"

[[package]]
name = "futures-sink"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d"

[[package]]
name = "futures-task"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd"

[[package]]
name = "futures-util"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
dependencies = [
 "futures-core",
 "futures-task",
 "pin-project-lite",
]

[[package]]
name = "getrandom"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
dependencies = [
 "cfg-if",
 "libc",
 "wasi",
]

[[package]]
name = "h2"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d29020232d6aa3fb1daca64c1127cf662cf97f254ae16c18c05b8ab635fc118"
dependencies = [
 "atomic-waker",
 "bytes",
 "fnv",
 "futures-core",
 "futures-sink",
 "http",
 "indexmap",
 "slab",
 "tokio",
 "tokio-util",
 "tracing",
]

[[package]]
name = "hashbrown"
version = "0.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "735eaa21a6a5ffb2e84362faaeb90c05ba8e19797ca30428478cb6ea3a4921bc"

[[package]]
name = "http"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0"
dependencies = [
 "bytes",
 "itoa",
]

[[package]]
name = "http-body"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c"
dependencies = [
 "bytes",
 "http",
]

[[package]]
name = "httparse"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"

[[package]]
name = "hyper"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c3e324da4c95177d6291d4c8730197c0d1822f8a9766814a4a44fa5ab797c9c"
dependencies = [
 "atomic-waker",
 "bytes",
 "futures-channel",
 "futures-core",
 "h2",
 "http",
 "http-body",
 "httparse",
 "itoa",
 "pin-project-lite",
 "smallvec",
 "tokio",
 "want",
]

[[package]]
name = "hyper-rustls"
version = "0.27.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f"
dependencies = [
 "http",
 "hyper",
 "hyper-util",
 "rustls",
 "tokio",
 "tokio-rustls",
 "tower-service",
 "webpki-roots",
]

[[package]]
name = "hyper-util"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddc03d96684f9226b8a787cdb71488417b53ab5ea8fdb1dac946cb9431cc8bff"
dependencies = [
 "bytes",
 "futures-channel",
 "futures-util",
 "http",
 "http-body",
 "httparse",
 "hyper",
 "libc",
 "pin-project-lite",
 "socket2",
 "tokio",
 "tower-service",
 "tracing",
]

[[package]]
name = "indexmap"
version = "2.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
dependencies = [
 "equivalent",
 "hashbrown",
]

[[package]]
name = "itoa"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"

[[package]]
name = "libc"
version = "0.2.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"

[[package]]
name = "mio"
version = "1.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20521a903f02b0a573cd6840e9d0a5a0cc043d361fe924092cd70f8556cc9c4a"
dependencies = [
 "libc",
 "wasi",
 "windows-sys 0.61.2",
]

[[package]]
name = "num-conv"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441"

[[package]]
name = "once_cell"
version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"

[[package]]
name = "pin-project-lite"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c938015719552d665fd0553b90d96cd7ff58e83e4c061ca99e6bb78865a72752"

[[package]]
name = "powerfmt"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a6394b9e965e73d0a289ee54f589087e2c676aedf60885baf52c76b771e4958"

[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
 "unicode-ident",
]

[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
 "proc-macro2",
]

[[package]]
name = "rcgen"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75e669e5202259b5314d1ea5397316ad400819437857b90861765f24c4cf80a2"
dependencies = [
 "ring",
 "rustls-pki-types",
 "time",
 "yasna",
]

[[package]]
name = "ring"
version = "0.17.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
dependencies = [
 "cc",
 "cfg-if",
 "getrandom",
 "libc",
 "untrusted",
 "windows-sys 0.52.0",
]

[[package]]
name = "rustls"
version = "0.23.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf"
dependencies = [
 "once_cell",
 "ring",
 "rustls-pki-types",
 "rustls-webpki",
 "subtle",
 "zeroize",
]

[[package]]
name = "rustls-pki-types"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "102f35f7de7b06d8c61f1cff6592f5253e0dea431c74867aad5dfd70f44663fb"
dependencies = [
 "zeroize",
]

[[package]]
name = "rustls-webpki"
version = "0.103.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3a0760a887c14823fca5a1c970b01d47c328c696c0c64829d1df50e8f853fd5"
dependencies = [
 "ring",
 "rustls-pki-types",
 "untrusted",
]

[[package]]
name = "sample-hyper-rustls-https-connector"
version = "1.0.0"
dependencies = [
 "http",
 "hyper",
 "hyper-rustls",
 "hyper-util",
 "rcgen",
 "rustls",
 "tokio",
 "tokio-rustls",
 "tower-service",
]

[[package]]
name = "serde_core"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
dependencies = [
 "serde_derive",
]

[[package]]
name = "serde_derive"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
]

[[package]]
name = "shlex"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"

[[package]]
name = "slab"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"

[[package]]
name = "smallvec"
version = "1.16.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3244542535d5de959d90ec55d1b5ff0fd2bb7b1310223907d5f11932847f7b59"

[[package]]
name = "socket2"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
dependencies = [
 "libc",
 "windows-sys 0.61.2",
]

[[package]]
name = "subtle"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"

[[package]]
name = "syn"
version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-ident",
]

[[package]]
name = "time"
version = "0.3.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134"
dependencies = [
 "deranged",
 "num-conv",
 "powerfmt",
 "serde_core",
 "time-core",
]

[[package]]
name = "time-core"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109"

[[package]]
name = "tokio"
version = "1.54.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3"
dependencies = [
 "bytes",
 "libc",
 "mio",
 "pin-project-lite",
 "socket2",
 "tokio-macros",
 "windows-sys 0.61.2",
]

[[package]]
name = "tokio-macros"
version = "2.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
]

[[package]]
name = "tokio-rustls"
version = "0.26.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9cc2678c2cdd569ef8215e2afd7954ada2ae20b4fdd2c5fe6139a3b02d105db"
dependencies = [
 "rustls",
 "tokio",
]

[[package]]
name = "tokio-util"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e464cf451ba96ebfc6f9b6542f17ee8b8956e33f1e40d9690624e59d7a7f8a4b"
dependencies = [
 "bytes",
 "futures-core",
 "futures-sink",
 "libc",
 "pin-project-lite",
 "tokio",
]

[[package]]
name = "tower-service"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"

[[package]]
name = "tracing"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
dependencies = [
 "pin-project-lite",
 "tracing-core",
]

[[package]]
name = "tracing-core"
version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
dependencies = [
 "once_cell",
]

[[package]]
name = "try-lock"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"

[[package]]
name = "unicode-ident"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"

[[package]]
name = "untrusted"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"

[[package]]
name = "want"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec4cdd0dd910afe868b7ef477227d8d538b46b3075031afee8a9f2acb0a2ed0b"
dependencies = [
 "try-lock",
]

[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"

[[package]]
name = "webpki-roots"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7265c9301c16a8711c992c2d8da90ee77ef54b1ed51482d6dfeb00dc756b1297"
dependencies = [
 "rustls-pki-types",
]

[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"

[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
 "windows-targets",
]

[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
 "windows-link",
]

[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
 "windows_aarch64_gnullvm",
 "windows_aarch64_msvc",
 "windows_i686_gnu",
 "windows_i686_gnullvm",
 "windows_i686_msvc",
 "windows_x86_64_gnu",
 "windows_x86_64_gnullvm",
 "windows_x86_64_msvc",
]

[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"

[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"

[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"

[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"

[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"

[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"

[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"

[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

[[package]]
name = "yasna"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e17bb3549cc1321ae1296b9cdc2698e2b6cb1992adfa19a8c72e5b7a738f44cd"
dependencies = [
 "time",
]

[[package]]
name = "zeroize"
version = "1.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85ccff8a4805aba1eaa4cd4afcd49f7557dd2cf5fd79ffc37f8959466effc5aa"
Cargo.toml
[package]
name = "sample-hyper-rustls-https-connector"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
http = "1"
hyper = { version = "1", default-features = false }
hyper-rustls = { version = "=0.27.9", default-features = false, features = ["http1", "http2", "ring", "tls12", "webpki-tokio"] }
hyper-util = { version = "0.1", default-features = false, features = ["client-legacy", "http1", "http2", "tokio"] }
rcgen = { version = "0.13", default-features = false, features = ["crypto", "ring"] }
rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12"] }
tokio = { version = "1", features = ["io-util", "macros", "net", "rt"] }
tokio-rustls = { version = "0.26", default-features = false, features = ["ring", "tls12"] }
tower-service = "0.3"

[[bin]]
name = "contract"
path = "test/contract.rs"
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify hyper_rustls::HttpsConnector in pkg:cargo/hyper-rustls@0.27.9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/hyper-rustls@0.27.9
Demonstrate these symbols/APIs:
  - hyper_rustls::HttpsConnector

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:f323679a90f59972b8a4d50af270588b115789afed76241cad46049b62085817","contract":["HttpsConnector::\u003cT\u003e::builder() (requiring a turbofish for T, or HttpsConnectorBuilder::new()) builds an HttpsConnector\u003cHttpConnector\u003e and panics if ClientConfig::alpn_protocols is pre-populated","HttpsConnector rejects non-HTTPS schemes with 'unsupported scheme \u003cscheme\u003e' when https_only is enabled and rejects schemeless URIs with 'missing scheme'","HttpsConnector::from((inner, tls_config)) allows HTTP pass-through as MaybeHttpsStream::Http until enforce_https() is called","HttpsConnector with enable_http1().enable_http2().wrap_connector() performs TLS handshakes returning MaybeHttpsStream::Https with h2 ALPN reflected in connected().is_negotiated_h2()","HttpsConnector::new() with FixedServerNameResolver overrides the URI hostname for TLS SNI and server certificate verification"],"goal":"verify hyper_rustls::HttpsConnector in pkg:cargo/hyper-rustls@0.27.9","kind":"HOW","packages":["pkg:cargo/hyper-rustls@0.27.9"],"schemaVersion":1,"symbols":["hyper_rustls::HttpsConnector"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/hyper-rustls@0.27.9"],"schemaVersion":1,"subject":"pkg:cargo/hyper-rustls@0.27.9","symbols":["hyper_rustls::HttpsConnector"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify hyper_rustls::HttpsConnector in pkg:cargo/hyper-rustls@0.27.9",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/hyper-rustls@0.27.9"
  ],
  "symbols": [
    "hyper_rustls::HttpsConnector"
  ]
}
src/lib.rs
//! Clean-room verification sample for `hyper_rustls::HttpsConnector`.

pub use hyper_rustls::{
    DefaultServerNameResolver, FixedServerNameResolver, HttpsConnector, HttpsConnectorBuilder,
    MaybeHttpsStream, ResolveServerName,
};
test/contract.rs
use std::future::{poll_fn, Future};
use std::io;
use std::net::SocketAddr;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};

use http::Uri;
use hyper_rustls::{
    FixedServerNameResolver, HttpsConnector, HttpsConnectorBuilder, MaybeHttpsStream,
};
use hyper_util::client::legacy::connect::{Connection, HttpConnector};
use hyper_util::rt::TokioIo;
use rcgen::generate_simple_self_signed;
use rustls::pki_types::{CertificateDer, PrivateKeyDer, ServerName};
use rustls::{ClientConfig, RootCertStore, ServerConfig};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, TcpStream};
use tokio_rustls::TlsAcceptor;
use tower_service::Service;

/// Minimal offline connector that always dials a local loopback address,
/// allowing `HttpsConnector` to perform real TLS handshakes for `example.com`
/// without any external network or DNS access.
#[derive(Clone)]
struct LoopbackConnector {
    addr: SocketAddr,
}

impl Service<Uri> for LoopbackConnector {
    type Response = TokioIo<TcpStream>;
    type Error = io::Error;
    type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;

    fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
        Poll::Ready(Ok(()))
    }

    fn call(&mut self, _req: Uri) -> Self::Future {
        let addr = self.addr;
        Box::pin(async move {
            let stream = TcpStream::connect(addr).await?;
            Ok(TokioIo::new(stream))
        })
    }
}

fn make_tls_pair(
    san: &str,
    server_alpn: Vec<Vec<u8>>,
) -> (ClientConfig, Arc<ServerConfig>) {
    let provider = Arc::new(rustls::crypto::ring::default_provider());
    let cert = generate_simple_self_signed(vec![san.to_string()]).expect("generate cert");
    let cert_der: CertificateDer<'static> = cert.cert.der().clone();
    let key_der = PrivateKeyDer::try_from(cert.key_pair.serialize_der()).expect("key der");

    let mut roots = RootCertStore::empty();
    roots.add(cert_der.clone()).expect("add root cert");

    let client_cfg = ClientConfig::builder_with_provider(provider.clone())
        .with_safe_default_protocol_versions()
        .expect("client protocol versions")
        .with_root_certificates(roots)
        .with_no_client_auth();

    let mut server_cfg = ServerConfig::builder_with_provider(provider)
        .with_safe_default_protocol_versions()
        .expect("server protocol versions")
        .with_no_client_auth()
        .with_single_cert(vec![cert_der], key_der)
        .expect("server cert");
    server_cfg.alpn_protocols = server_alpn;

    (client_cfg, Arc::new(server_cfg))
}

async fn spawn_tls_echo(server_cfg: Arc<ServerConfig>) -> (SocketAddr, tokio::task::JoinHandle<()>) {
    let listener = TcpListener::bind("127.0.0.1:0").await.expect("bind tls");
    let addr = listener.local_addr().expect("tls local_addr");
    let acceptor = TlsAcceptor::from(server_cfg);

    let handle = tokio::spawn(async move {
        let (tcp, _) = listener.accept().await.expect("accept tls");
        let mut tls = acceptor.accept(tcp).await.expect("tls handshake");
        let mut buf = [0u8; 4];
        tls.read_exact(&mut buf).await.expect("server read");
        assert_eq!(&buf, b"ping");
        tls.write_all(b"pong").await.expect("server write");
        tls.shutdown().await.expect("server shutdown");
    });

    (addr, handle)
}

async fn spawn_plain_echo() -> (SocketAddr, tokio::task::JoinHandle<()>) {
    let listener = TcpListener::bind("127.0.0.1:0").await.expect("bind plain");
    let addr = listener.local_addr().expect("plain local_addr");

    let handle = tokio::spawn(async move {
        let (mut tcp, _) = listener.accept().await.expect("accept plain");
        let mut buf = [0u8; 5];
        tcp.read_exact(&mut buf).await.expect("plain read");
        assert_eq!(&buf, b"hello");
        tcp.write_all(b"plain").await.expect("plain write");
        tcp.shutdown().await.expect("plain shutdown");
    });

    (addr, handle)
}

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let _ = rustls::crypto::ring::default_provider().install_default();

    // 1. HttpsConnector::<HttpConnector>::builder() (turbofish required because
    //    `builder()` is in `impl<T> HttpsConnector<T>`) constructs HttpsConnector<HttpConnector>
    //    and rejects pre-defined ALPN protocols in ClientConfig.
    let (base_client_cfg, _) = make_tls_pair("example.com", vec![]);
    let mut default_https: HttpsConnector<HttpConnector> =
        HttpsConnector::<HttpConnector>::builder()
            .with_tls_config(base_client_cfg.clone())
            .https_only()
            .enable_http1()
            .build();
    assert!(format!("{default_https:?}").contains("force_https: true"));

    let mut cfg_with_alpn = base_client_cfg.clone();
    cfg_with_alpn.alpn_protocols = vec![b"h2".to_vec()];
    let alpn_panic = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
        let _ = HttpsConnectorBuilder::new().with_tls_config(cfg_with_alpn);
    }));
    assert!(alpn_panic.is_err(), "pre-defined ALPN must panic");

    // 2. Scheme enforcement: https_only rejects http, ftp, and schemeless URIs.
    poll_fn(|cx| default_https.poll_ready(cx))
        .await
        .expect("default connector ready");

    let http_err = default_https
        .call(Uri::from_static("http://localhost/"))
        .await
        .unwrap_err()
        .to_string();
    assert_eq!(http_err, "unsupported scheme http");

    let ftp_err = default_https
        .call(Uri::from_static("ftp://example.com/"))
        .await
        .unwrap_err()
        .to_string();
    assert_eq!(ftp_err, "unsupported scheme ftp");

    let no_scheme_err = default_https
        .call(Uri::from_static("/relative/path"))
        .await
        .unwrap_err()
        .to_string();
    assert_eq!(no_scheme_err, "missing scheme");

    // 3. https_or_http() allows plain HTTP pass-through as MaybeHttpsStream::Http
    //    and enforce_https() switches an existing connector to reject HTTP.
    let (plain_addr, plain_task) = spawn_plain_echo().await;
    let mut dual_conn = HttpsConnector::from((
        LoopbackConnector { addr: plain_addr },
        base_client_cfg.clone(),
    ));
    assert!(format!("{dual_conn:?}").contains("force_https: false"));

    poll_fn(|cx| dual_conn.poll_ready(cx))
        .await
        .expect("dual connector ready");
    let plain_stream = dual_conn
        .call(Uri::from_static("http://example.com/"))
        .await
        .expect("http pass-through");
    assert!(matches!(plain_stream, MaybeHttpsStream::Http(_)));

    let mut io_plain = TokioIo::new(plain_stream);
    io_plain.write_all(b"hello").await.expect("write plain");
    let mut reply = [0u8; 5];
    io_plain.read_exact(&mut reply).await.expect("read plain");
    assert_eq!(&reply, b"plain");
    plain_task.await.expect("plain server join");

    dual_conn.enforce_https();
    assert!(format!("{dual_conn:?}").contains("force_https: true"));
    let enforced_err = dual_conn
        .call(Uri::from_static("http://example.com/"))
        .await
        .unwrap_err()
        .to_string();
    assert_eq!(enforced_err, "unsupported scheme http");

    // 4. Real offline TLS handshake over loopback with DefaultServerNameResolver
    //    and ALPN h2 negotiation via enable_http1().enable_http2().
    let (tls_client_cfg, tls_server_cfg) =
        make_tls_pair("example.com", vec![b"h2".to_vec(), b"http/1.1".to_vec()]);
    let (tls_addr, tls_task) = spawn_tls_echo(tls_server_cfg).await;

    let mut h2_conn = HttpsConnector::<LoopbackConnector>::builder()
        .with_tls_config(tls_client_cfg)
        .https_only()
        .enable_http1()
        .enable_http2()
        .wrap_connector(LoopbackConnector { addr: tls_addr });

    poll_fn(|cx| h2_conn.poll_ready(cx))
        .await
        .expect("h2 connector ready");
    let tls_stream = h2_conn
        .call(Uri::from_static("https://example.com/"))
        .await
        .expect("https handshake");
    assert!(matches!(tls_stream, MaybeHttpsStream::Https(_)));
    assert!(
        tls_stream.connected().is_negotiated_h2(),
        "ALPN should negotiate h2"
    );

    let mut io_tls = TokioIo::new(tls_stream);
    io_tls.write_all(b"ping").await.expect("write tls");
    let mut tls_reply = [0u8; 4];
    io_tls.read_exact(&mut tls_reply).await.expect("read tls");
    assert_eq!(&tls_reply, b"pong");
    tls_task.await.expect("tls server join");

    // 5. HttpsConnector::new() with FixedServerNameResolver overrides the URI hostname
    //    for TLS SNI and certificate verification.
    let (override_client_cfg, override_server_cfg) =
        make_tls_pair("alt.example.com", vec![b"http/1.1".to_vec()]);
    let (override_addr, override_task) = spawn_tls_echo(override_server_cfg).await;

    let resolver = Arc::new(FixedServerNameResolver::new(
        ServerName::try_from("alt.example.com").expect("valid server name"),
    ));
    let mut override_conn = HttpsConnector::new(
        LoopbackConnector { addr: override_addr },
        override_client_cfg,
        true,
        resolver,
    );

    poll_fn(|cx| override_conn.poll_ready(cx))
        .await
        .expect("override connector ready");
    let override_stream = override_conn
        .call(Uri::from_static("https://localhost/"))
        .await
        .expect("https handshake with overridden SNI");
    assert!(matches!(override_stream, MaybeHttpsStream::Https(_)));
    assert!(
        !override_stream.connected().is_negotiated_h2(),
        "http/1.1 ALPN should not report h2"
    );

    let mut io_override = TokioIo::new(override_stream);
    io_override.write_all(b"ping").await.expect("write override");
    let mut override_reply = [0u8; 4];
    io_override
        .read_exact(&mut override_reply)
        .await
        .expect("read override");
    assert_eq!(&override_reply, b"pong");
    override_task.await.expect("override server join");

    println!("All hyper_rustls::HttpsConnector contract assertions passed.");
}

原始种子者

匿名