Skip to content

Commit

Permalink
Fix MacOS and Windows compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
heavenboy8 authored and ThibsG committed Mar 8, 2024
1 parent 0e15b31 commit d7d58ca
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 86 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ on: [push, pull_request]
name: test
jobs:
sw-openssl:
name: sw openssl ${{ matrix.toolchain }} ${{ matrix.profile.name }} ${{ matrix.features }}
runs-on: ubuntu-latest
name: sw openssl ${{ matrix.runner }} ${{ matrix.toolchain }} ${{ matrix.profile.name }} ${{ matrix.features }}
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -14,6 +14,9 @@ jobs:
strategy:
fail-fast: false
matrix:
runner:
- ubuntu-latest
- macos-12
toolchain:
- 1.70.0
- stable
Expand All @@ -25,8 +28,8 @@ jobs:
- openssl

sw-crypto_nossl:
name: sw crypto_nossl ${{ matrix.toolchain }} ${{ matrix.profile.name }} ${{ matrix.features }}
runs-on: ubuntu-latest
name: sw crypto_nossl ${{ matrix.runner }} ${{ matrix.toolchain }} ${{ matrix.profile.name }} ${{ matrix.features }}
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -36,6 +39,10 @@ jobs:
strategy:
fail-fast: false
matrix:
runner:
- ubuntu-latest
- macos-12
- windows-latest
toolchain:
- 1.70.0
- stable
Expand Down
73 changes: 37 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ x509-cert = { version = "0.2.5", optional = true }
byteorder = "1.4.3"
base64 = "0.22.0"

[dev-dependencies]
[target.'cfg(target_os = "linux")'.dev-dependencies]
kvm-ioctls = ">=0.12"

[dev-dependencies]
kvm-bindings = ">=0.6"
serial_test = "3.0"
7 changes: 6 additions & 1 deletion src/firmware/host/types/snp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ pub use crate::firmware::linux::host::types::RawData;

pub(crate) use crate::firmware::linux::host as FFI;

use crate::{firmware::host::CertError, Version};
use crate::Version;

#[cfg(target_os = "linux")]
use crate::error::CertError;

use std::{
convert::{TryFrom, TryInto},
Expand Down Expand Up @@ -172,11 +175,13 @@ impl CertTableEntry {
}

/// Builds a Kernel formatted CertTable for sending the certificate content to the PSP.
#[cfg(target_os = "linux")]
pub fn cert_table_to_vec_bytes(table: &[Self]) -> Result<Vec<u8>, CertError> {
FFI::types::CertTableEntry::uapi_to_vec_bytes(table)
}

/// Takes in bytes in kernel CertTable format and returns in user API CertTable format.
#[cfg(target_os = "linux")]
pub fn vec_bytes_to_cert_table(bytes: &mut [u8]) -> Result<Vec<Self>, CertError> {
let cert_bytes_ptr: *mut FFI::types::CertTableEntry =
bytes.as_mut_ptr() as *mut FFI::types::CertTableEntry;
Expand Down
6 changes: 6 additions & 0 deletions src/firmware/linux/host/types/snp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::error::CertError;

use crate::firmware::host as UAPI;

#[cfg(target_os = "linux")]
use uuid::Uuid;

/// Raw certificate bytes (by pointer or Vec<u8>).
Expand Down Expand Up @@ -163,6 +164,7 @@ impl CertTableEntry {
/// };
/// ```
///
#[cfg(target_os = "linux")]
pub unsafe fn parse_table(
mut data: *mut CertTableEntry,
) -> Result<Vec<UAPI::CertTableEntry>, uuid::Error> {
Expand Down Expand Up @@ -308,6 +310,7 @@ mod test {
mod cert_table_entry {

use crate::firmware::host as UAPI;
#[cfg(target_os = "linux")]
use crate::firmware::linux::host::types::CertTableEntry;
use uuid::Uuid;

Expand All @@ -326,6 +329,7 @@ mod test {
}

#[test]
#[cfg(target_os = "linux")]
fn test_uapi_to_vec_bytes() {
let expected: Vec<u8> = vec![
192, 180, 6, 164, 168, 3, 73, 82, 151, 67, 63, 182, 1, 76, 208, 174, 120, 0, 0, 0,
Expand All @@ -344,6 +348,7 @@ mod test {
}

#[test]
#[cfg(target_os = "linux")]
fn test_parse_table_regular() {
let mut cert_bytes: Vec<u8> = vec![
192, 180, 6, 164, 168, 3, 73, 82, 151, 67, 63, 182, 1, 76, 208, 174, 120, 0, 0, 0,
Expand All @@ -369,6 +374,7 @@ mod test {
}

#[test]
#[cfg(target_os = "linux")]
#[should_panic]
fn test_parse_table_offset_short() {
let mut cert_bytes: Vec<u8> = vec![
Expand Down
Loading

0 comments on commit d7d58ca

Please sign in to comment.