Skip to content

Commit

Permalink
testing suits for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Jan 5, 2025
1 parent a0e6f18 commit a112526
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,25 @@ jobs:
path: target
key: target-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }}
- run: cargo test --features vendored
- run: cargo test --features vendored

build_n_test_ios:
strategy:
fail-fast: false
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Install cargo lipo and rust compiler for ios target
if: ${{ !cancelled() }}
run: |
cargo install --locked cargo-lipo
rustup target add x86_64-apple-ios aarch64-apple-ios
- name: clippy
if: ${{ !cancelled() }}
run: cargo clippy --target x86_64-apple-ios --all-features -- -D warnings
- name: Build
if: ${{ !cancelled() }}
run: |
cargo lipo --verbose --all-features
- name: Abort on error
if: ${{ failure() }}
run: echo "iOS build job failed" && false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.VSCodeCounter/
target
Cargo.lock
.idea
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ rust-version = "1.53.0"
features = ["alpn"]
rustdoc-args = ["--cfg", "docsrs"]

[lib]
crate-type = ["staticlib", "rlib"]

[features]
vendored = ["openssl/vendored"]
alpn = ["security-framework/alpn"]
Expand Down
2 changes: 1 addition & 1 deletion src/imp/openssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::fmt;
use std::io;
use std::sync::Once;

use {Protocol, TlsAcceptorBuilder, TlsConnectorBuilder};
use crate::{Protocol, TlsAcceptorBuilder, TlsConnectorBuilder};

#[cfg(have_min_max_version)]
fn supported_protocols(
Expand Down
21 changes: 17 additions & 4 deletions src/imp/security_framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use std::error;
use std::fmt;
use std::io;
use std::str;
use std::sync::Mutex;
use std::sync::Once;

#[cfg(not(any(
Expand Down Expand Up @@ -58,6 +57,7 @@ use self::security_framework::os::macos::keychain::{self, KeychainSettings, SecK

use {Protocol, TlsAcceptorBuilder, TlsConnectorBuilder};

#[allow(dead_code)]
static SET_AT_EXIT: Once = Once::new();

#[cfg(not(any(
Expand All @@ -66,7 +66,8 @@ static SET_AT_EXIT: Once = Once::new();
target_os = "tvos",
target_os = "visionos"
)))]
static TEMP_KEYCHAIN: Mutex<Option<(SecKeychain, tempfile::TempDir)>> = Mutex::new(None);
static TEMP_KEYCHAIN: std::sync::Mutex<Option<(SecKeychain, tempfile::TempDir)>> =
std::sync::Mutex::new(None);

fn convert_protocol(protocol: Protocol) -> SslProtocol {
match protocol {
Expand Down Expand Up @@ -233,6 +234,7 @@ impl Identity {
}
}

#[allow(dead_code)]
fn random_password() -> Result<String, Error> {
use std::fmt::Write;
let mut bytes = [0_u8; 10];
Expand Down Expand Up @@ -479,6 +481,7 @@ impl TlsAcceptor {

pub struct TlsStream<S> {
stream: secure_transport::SslStream<S>,
#[allow(dead_code)]
cert: Option<SecCertificate>,
}

Expand Down Expand Up @@ -641,6 +644,7 @@ impl<S: io::Read + io::Write> io::Write for TlsStream<S> {
}
}

#[allow(dead_code)]
enum Digest {
Sha224,
Sha256,
Expand All @@ -649,9 +653,10 @@ enum Digest {
}

impl Digest {
#[allow(dead_code)]
fn hash(&self, data: &[u8]) -> Vec<u8> {
unsafe {
assert!(data.len() <= CC_LONG::max_value() as usize);
assert!(data.len() <= CC_LONG::MAX as usize);
match *self {
Digest::Sha224 => {
let mut buf = [0; CC_SHA224_DIGEST_LENGTH];
Expand Down Expand Up @@ -679,16 +684,24 @@ impl Digest {
}

// FIXME ideally we'd pull these in from elsewhere
#[allow(dead_code)]
const CC_SHA224_DIGEST_LENGTH: usize = 28;
#[allow(dead_code)]
const CC_SHA256_DIGEST_LENGTH: usize = 32;
#[allow(dead_code)]
const CC_SHA384_DIGEST_LENGTH: usize = 48;
#[allow(dead_code)]
const CC_SHA512_DIGEST_LENGTH: usize = 64;
#[allow(non_camel_case_types)]
#[allow(non_camel_case_types, dead_code)]
type CC_LONG = u32;

extern "C" {
#[allow(dead_code)]
fn CC_SHA224(data: *const u8, len: CC_LONG, md: *mut u8) -> *mut u8;
#[allow(dead_code)]
fn CC_SHA256(data: *const u8, len: CC_LONG, md: *mut u8) -> *mut u8;
#[allow(dead_code)]
fn CC_SHA384(data: *const u8, len: CC_LONG, md: *mut u8) -> *mut u8;
#[allow(dead_code)]
fn CC_SHA512(data: *const u8, len: CC_LONG, md: *mut u8) -> *mut u8;
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ use std::result;
#[cfg(not(any(target_os = "windows", target_vendor = "apple",)))]
#[macro_use]
extern crate log;
#[cfg(any(target_vendor = "apple",))]
#[cfg(target_vendor = "apple")]
#[path = "imp/security_framework.rs"]
mod imp;
#[cfg(target_os = "windows")]
Expand Down

0 comments on commit a112526

Please sign in to comment.