Skip to content

Commit 0b69ce6

Browse files
authored
Merge pull request #285 from simlay/add-tvos-and-watchos-target-flags
Add tvOS and watchOS support
2 parents 5db1b77 + 6e462d6 commit 0b69ce6

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- uses: actions/checkout@v2
3636
- uses: sfackler/actions/rustup@master
3737
with:
38-
version: 1.63.0
38+
version: 1.65.0
3939
- run: echo "::set-output name=version::$(rustc --version)"
4040
id: rust-version
4141
- uses: actions/cache@v1

Cargo.toml

Lines changed: 2 additions & 2 deletions
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"))'.dependencies]
19+
[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos", target_os = "tvos"))'.dependencies]
2020
security-framework = "2.0.0"
2121
security-framework-sys = "2.0.0"
2222
libc = "0.2"
@@ -25,7 +25,7 @@ tempfile = "3.1.0"
2525
[target.'cfg(target_os = "windows")'.dependencies]
2626
schannel = "0.1.17"
2727

28-
[target.'cfg(not(any(target_os = "windows", target_os = "macos", target_os = "ios")))'.dependencies]
28+
[target.'cfg(not(any(target_os = "windows", target_os = "macos", target_os = "ios", target_os = "watchos", target_os = "tvos")))'.dependencies]
2929
log = "0.4.5"
3030
openssl = "0.10.29"
3131
openssl-sys = "0.9.55"

src/imp/security_framework.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ use std::str;
2020
use std::sync::Mutex;
2121
use std::sync::Once;
2222

23-
#[cfg(not(target_os = "ios"))]
23+
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
2424
use self::security_framework::os::macos::certificate::{PropertyType, SecCertificateExt};
25-
#[cfg(not(target_os = "ios"))]
25+
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
2626
use self::security_framework::os::macos::certificate_oids::CertificateOid;
27-
#[cfg(not(target_os = "ios"))]
27+
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
2828
use self::security_framework::os::macos::identity::SecIdentityExt;
29-
#[cfg(not(target_os = "ios"))]
29+
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
3030
use self::security_framework::os::macos::import_export::{
3131
ImportOptions, Pkcs12ImportOptionsExt, SecItems,
3232
};
33-
#[cfg(not(target_os = "ios"))]
33+
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
3434
use self::security_framework::os::macos::keychain::{self, KeychainSettings, SecKeychain};
3535

3636
use {Protocol, TlsAcceptorBuilder, TlsConnectorBuilder};
3737

3838
static SET_AT_EXIT: Once = Once::new();
3939

40-
#[cfg(not(target_os = "ios"))]
40+
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
4141
static TEMP_KEYCHAIN: Mutex<Option<(SecKeychain, TempDir)>> = Mutex::new(None);
4242

4343
fn convert_protocol(protocol: Protocol) -> SslProtocol {
@@ -82,12 +82,12 @@ pub struct Identity {
8282
}
8383

8484
impl Identity {
85-
#[cfg(target_os = "ios")]
85+
#[cfg(any(target_os = "ios", target_os = "watchos", target_os = "tvos"))]
8686
pub fn from_pkcs8(_: &[u8], _: &[u8]) -> Result<Identity, Error> {
8787
panic!("Not implemented on iOS");
8888
}
8989

90-
#[cfg(not(target_os = "ios"))]
90+
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
9191
pub fn from_pkcs8(pem: &[u8], key: &[u8]) -> Result<Identity, Error> {
9292
if !key.starts_with(b"-----BEGIN PRIVATE KEY-----") {
9393
return Err(Error(base::Error::from(errSecParam)));
@@ -145,7 +145,7 @@ impl Identity {
145145
})
146146
}
147147

148-
#[cfg(not(target_os = "ios"))]
148+
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
149149
fn import_options(buf: &[u8], pass: &str) -> Result<Vec<ImportedIdentity>, Error> {
150150
SET_AT_EXIT.call_once(|| {
151151
extern "C" fn atexit() {
@@ -177,7 +177,7 @@ impl Identity {
177177
Ok(imports)
178178
}
179179

180-
#[cfg(target_os = "ios")]
180+
#[cfg(any(target_os = "ios", target_os = "watchos", target_os = "tvos"))]
181181
fn import_options(buf: &[u8], pass: &str) -> Result<Vec<ImportedIdentity>, Error> {
182182
let imports = Pkcs12ImportOptions::new().passphrase(pass).import(buf)?;
183183
Ok(imports)
@@ -206,7 +206,7 @@ impl Certificate {
206206
Ok(Certificate(cert))
207207
}
208208

209-
#[cfg(not(target_os = "ios"))]
209+
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
210210
pub fn from_pem(buf: &[u8]) -> Result<Certificate, Error> {
211211
let mut items = SecItems::default();
212212
ImportOptions::new().items(&mut items).import(buf)?;
@@ -217,9 +217,9 @@ impl Certificate {
217217
}
218218
}
219219

220-
#[cfg(target_os = "ios")]
220+
#[cfg(any(target_os = "ios", target_os = "watchos", target_os = "tvos"))]
221221
pub fn from_pem(_: &[u8]) -> Result<Certificate, Error> {
222-
panic!("Not implemented on iOS");
222+
panic!("Not implemented on iOS, tvOS or watchOS");
223223
}
224224

225225
pub fn to_der(&self) -> Result<Vec<u8>, Error> {
@@ -476,12 +476,12 @@ impl<S: io::Read + io::Write> TlsStream<S> {
476476
}
477477
}
478478

479-
#[cfg(target_os = "ios")]
479+
#[cfg(any(target_os = "ios", target_os = "watchos", target_os = "tvos"))]
480480
pub fn tls_server_end_point(&self) -> Result<Option<Vec<u8>>, Error> {
481481
Ok(None)
482482
}
483483

484-
#[cfg(not(target_os = "ios"))]
484+
#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
485485
pub fn tls_server_end_point(&self) -> Result<Option<Vec<u8>>, Error> {
486486
let cert = match self.cert {
487487
Some(ref cert) => cert.clone(),

src/lib.rs

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

107-
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
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+
)))]
108114
#[macro_use]
109115
extern crate log;
110-
#[cfg(any(target_os = "macos", target_os = "ios"))]
116+
#[cfg(any(
117+
target_os = "macos",
118+
target_os = "ios",
119+
target_os = "watchos",
120+
target_os = "tvos"
121+
))]
111122
#[path = "imp/security_framework.rs"]
112123
mod imp;
113124
#[cfg(target_os = "windows")]
114125
#[path = "imp/schannel.rs"]
115126
mod imp;
116-
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
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+
)))]
117134
#[path = "imp/openssl.rs"]
118135
mod imp;
119136

0 commit comments

Comments
 (0)