Skip to content

Commit 9a5d8ce

Browse files
committed
Added visionos target support
1 parent 6ba3cf1 commit 9a5d8ce

File tree

3 files changed

+90
-37
lines changed

3 files changed

+90
-37
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rustdoc-args = ["--cfg", "docsrs"]
1616
vendored = ["openssl/vendored"]
1717
alpn = ["security-framework/alpn"]
1818

19-
[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos", target_os = "tvos"))'.dependencies]
19+
[target.'cfg(target_vendor = "apple")'.dependencies]
2020
security-framework = "2.0.0"
2121
security-framework-sys = "2.0.0"
2222
libc = "0.2"
@@ -27,7 +27,7 @@ tempfile = "3.1.0"
2727
[target.'cfg(target_os = "windows")'.dependencies]
2828
schannel = "0.1.17"
2929

30-
[target.'cfg(not(any(target_os = "windows", target_os = "macos", target_os = "ios", target_os = "watchos", target_os = "tvos")))'.dependencies]
30+
[target.'cfg(not(any(target_os = "windows", target_vendor = "apple")))'.dependencies]
3131
log = "0.4.5"
3232
openssl = "0.10.29"
3333
openssl-sys = "0.9.55"

src/imp/security_framework.rs

+85-15
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,54 @@ use std::str;
1818
use std::sync::Mutex;
1919
use std::sync::Once;
2020

21-
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
21+
#[cfg(not(any(
22+
target_os = "ios",
23+
target_os = "watchos",
24+
target_os = "tvos",
25+
target_os = "visionos"
26+
)))]
2227
use self::security_framework::os::macos::certificate::{PropertyType, SecCertificateExt};
23-
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
28+
#[cfg(not(any(
29+
target_os = "ios",
30+
target_os = "watchos",
31+
target_os = "tvos",
32+
target_os = "visionos"
33+
)))]
2434
use self::security_framework::os::macos::certificate_oids::CertificateOid;
25-
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
35+
#[cfg(not(any(
36+
target_os = "ios",
37+
target_os = "watchos",
38+
target_os = "tvos",
39+
target_os = "visionos"
40+
)))]
2641
use self::security_framework::os::macos::identity::SecIdentityExt;
27-
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
42+
#[cfg(not(any(
43+
target_os = "ios",
44+
target_os = "watchos",
45+
target_os = "tvos",
46+
target_os = "visionos"
47+
)))]
2848
use self::security_framework::os::macos::import_export::{
2949
ImportOptions, Pkcs12ImportOptionsExt, SecItems,
3050
};
31-
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
51+
#[cfg(not(any(
52+
target_os = "ios",
53+
target_os = "watchos",
54+
target_os = "tvos",
55+
target_os = "visionos"
56+
)))]
3257
use self::security_framework::os::macos::keychain::{self, KeychainSettings, SecKeychain};
3358

3459
use {Protocol, TlsAcceptorBuilder, TlsConnectorBuilder};
3560

3661
static SET_AT_EXIT: Once = Once::new();
3762

38-
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
63+
#[cfg(not(any(
64+
target_os = "ios",
65+
target_os = "watchos",
66+
target_os = "tvos",
67+
target_os = "visionos"
68+
)))]
3969
static TEMP_KEYCHAIN: Mutex<Option<(SecKeychain, tempfile::TempDir)>> = Mutex::new(None);
4070

4171
fn convert_protocol(protocol: Protocol) -> SslProtocol {
@@ -80,12 +110,22 @@ pub struct Identity {
80110
}
81111

82112
impl Identity {
83-
#[cfg(any(target_os = "ios", target_os = "watchos", target_os = "tvos"))]
113+
#[cfg(any(
114+
target_os = "ios",
115+
target_os = "watchos",
116+
target_os = "tvos",
117+
target_os = "visionos"
118+
))]
84119
pub fn from_pkcs8(_: &[u8], _: &[u8]) -> Result<Identity, Error> {
85120
panic!("Not implemented on iOS");
86121
}
87122

88-
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
123+
#[cfg(not(any(
124+
target_os = "ios",
125+
target_os = "watchos",
126+
target_os = "tvos",
127+
target_os = "visionos"
128+
)))]
89129
pub fn from_pkcs8(pem: &[u8], key: &[u8]) -> Result<Identity, Error> {
90130
if !key.starts_with(b"-----BEGIN PRIVATE KEY-----") {
91131
return Err(Error(base::Error::from(errSecParam)));
@@ -143,7 +183,12 @@ impl Identity {
143183
})
144184
}
145185

146-
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
186+
#[cfg(not(any(
187+
target_os = "ios",
188+
target_os = "watchos",
189+
target_os = "tvos",
190+
target_os = "visionos"
191+
)))]
147192
fn import_options(buf: &[u8], pass: &str) -> Result<Vec<ImportedIdentity>, Error> {
148193
SET_AT_EXIT.call_once(|| {
149194
extern "C" fn atexit() {
@@ -176,7 +221,12 @@ impl Identity {
176221
Ok(imports)
177222
}
178223

179-
#[cfg(any(target_os = "ios", target_os = "watchos", target_os = "tvos"))]
224+
#[cfg(any(
225+
target_os = "ios",
226+
target_os = "watchos",
227+
target_os = "tvos",
228+
target_os = "visionos"
229+
))]
180230
fn import_options(buf: &[u8], pass: &str) -> Result<Vec<ImportedIdentity>, Error> {
181231
let imports = Pkcs12ImportOptions::new().passphrase(pass).import(buf)?;
182232
Ok(imports)
@@ -205,7 +255,12 @@ impl Certificate {
205255
Ok(Certificate(cert))
206256
}
207257

208-
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
258+
#[cfg(not(any(
259+
target_os = "ios",
260+
target_os = "watchos",
261+
target_os = "tvos",
262+
target_os = "visionos"
263+
)))]
209264
pub fn from_pem(buf: &[u8]) -> Result<Certificate, Error> {
210265
let mut items = SecItems::default();
211266
ImportOptions::new().items(&mut items).import(buf)?;
@@ -216,9 +271,14 @@ impl Certificate {
216271
}
217272
}
218273

219-
#[cfg(any(target_os = "ios", target_os = "watchos", target_os = "tvos"))]
274+
#[cfg(any(
275+
target_os = "ios",
276+
target_os = "watchos",
277+
target_os = "tvos",
278+
target_os = "visionos"
279+
))]
220280
pub fn from_pem(_: &[u8]) -> Result<Certificate, Error> {
221-
panic!("Not implemented on iOS, tvOS or watchOS");
281+
panic!("Not implemented on iOS, tvOS, watchOS or visionOS");
222282
}
223283

224284
pub fn to_der(&self) -> Result<Vec<u8>, Error> {
@@ -475,12 +535,22 @@ impl<S: io::Read + io::Write> TlsStream<S> {
475535
}
476536
}
477537

478-
#[cfg(any(target_os = "ios", target_os = "watchos", target_os = "tvos"))]
538+
#[cfg(any(
539+
target_os = "ios",
540+
target_os = "watchos",
541+
target_os = "tvos",
542+
target_os = "visionos"
543+
))]
479544
pub fn tls_server_end_point(&self) -> Result<Option<Vec<u8>>, Error> {
480545
Ok(None)
481546
}
482547

483-
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
548+
#[cfg(not(any(
549+
target_os = "ios",
550+
target_os = "watchos",
551+
target_os = "tvos",
552+
target_os = "visionos"
553+
)))]
484554
pub fn tls_server_end_point(&self) -> Result<Option<Vec<u8>>, Error> {
485555
let cert = match self.cert {
486556
Some(ref cert) => cert.clone(),

src/lib.rs

+3-20
Original file line numberDiff line numberDiff line change
@@ -104,33 +104,16 @@ use std::fmt;
104104
use std::io;
105105
use std::result;
106106

107-
#[cfg(not(any(
108-
target_os = "macos",
109-
target_os = "windows",
110-
target_os = "ios",
111-
target_os = "watchos",
112-
target_os = "tvos"
113-
)))]
107+
#[cfg(not(any(target_os = "windows", target_vendor = "apple",)))]
114108
#[macro_use]
115109
extern crate log;
116-
#[cfg(any(
117-
target_os = "macos",
118-
target_os = "ios",
119-
target_os = "watchos",
120-
target_os = "tvos"
121-
))]
110+
#[cfg(any(target_vendor = "apple",))]
122111
#[path = "imp/security_framework.rs"]
123112
mod imp;
124113
#[cfg(target_os = "windows")]
125114
#[path = "imp/schannel.rs"]
126115
mod imp;
127-
#[cfg(not(any(
128-
target_os = "macos",
129-
target_os = "windows",
130-
target_os = "ios",
131-
target_os = "watchos",
132-
target_os = "tvos"
133-
)))]
116+
#[cfg(not(any(target_vendor = "apple", target_os = "windows",)))]
134117
#[path = "imp/openssl.rs"]
135118
mod imp;
136119

0 commit comments

Comments
 (0)