Skip to content

Commit

Permalink
Fix cargo test when abstraction feature is not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
tmfink committed Aug 7, 2024
1 parent f4c3137 commit cb605c1
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 35 deletions.
1 change: 1 addition & 0 deletions tss-esapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub mod tcti_ldr;
pub mod traits;
pub mod utils;

#[cfg(feature = "abstraction")]
pub use abstraction::transient::TransientKeyContext;
pub use context::Context;
pub use error::{Error, Result, ReturnCode, WrapperErrorKind};
Expand Down
4 changes: 4 additions & 0 deletions tss-esapi/tests/integration_tests/abstraction_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
#[cfg(feature = "abstraction")]
mod ak_tests;
mod ek_tests;
#[cfg(feature = "abstraction")]
mod nv_tests;
#[cfg(feature = "abstraction")]
mod pcr_data_tests;
mod pcr_tests;
mod public_tests;
#[cfg(feature = "abstraction")]
mod transient_key_context_tests;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use tss_esapi::{
structures::{PcrSelectionListBuilder, PcrSlot},
};

#[cfg(feature = "abstraction")]
#[test]
fn test_pcr_read_all() {
let mut context = create_ctx_without_session();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2022 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0

#[cfg(feature = "abstraction")]
mod public_rsa_test {
use picky_asn1::wrapper::IntegerAsn1;
use picky_asn1_x509::{AlgorithmIdentifier, PublicKey, SubjectPublicKeyInfo};
Expand Down Expand Up @@ -102,6 +103,7 @@ mod public_rsa_test {
}
}

#[cfg(feature = "abstraction")]
mod public_ecc_test {
use picky_asn1::bit_string::BitString;
use picky_asn1_x509::{AlgorithmIdentifier, EcParameters, PublicKey, SubjectPublicKeyInfo};
Expand Down
21 changes: 13 additions & 8 deletions tss-esapi/tests/integration_tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::{
};

use tss_esapi::{
abstraction::{cipher::Cipher, pcr::PcrData},
attributes::ObjectAttributes,
attributes::{NvIndexAttributesBuilder, ObjectAttributesBuilder, SessionAttributesBuilder},
constants::SessionType,
Expand All @@ -18,21 +17,25 @@ use tss_esapi::{
algorithm::{HashingAlgorithm, PublicAlgorithm, RsaSchemeAlgorithm},
key_bits::RsaKeyBits,
key_bits::{AesKeyBits, Sm4KeyBits},
reserved_handles::{Hierarchy, NvAuth, Provision},
session_handles::PolicySession,
reserved_handles::{NvAuth, Provision},
},
structures::{
Digest, EccParameter, EccPoint, EccScheme, EccSignature, HashAgile, HashScheme, HmacScheme,
KeyDerivationFunctionScheme, KeyedHashScheme, MaxBuffer, MaxNvBuffer, NvPublicBuilder,
PcrSelectionListBuilder, PcrSlot, Public, PublicBuilder, PublicEccParameters, PublicKeyRsa,
PublicKeyedHashParameters, PublicRsaParameters, RsaExponent, RsaScheme, RsaSignature,
Sensitive, Signature, SymmetricCipherParameters, SymmetricDefinition,
SymmetricDefinitionObject,
KeyDerivationFunctionScheme, KeyedHashScheme, MaxNvBuffer, NvPublicBuilder, Public,
PublicBuilder, PublicEccParameters, PublicKeyRsa, PublicKeyedHashParameters,
PublicRsaParameters, RsaExponent, RsaScheme, RsaSignature, Sensitive, Signature,
SymmetricCipherParameters, SymmetricDefinition, SymmetricDefinitionObject,
},
tcti_ldr::TctiNameConf,
utils, Context,
};

#[cfg(feature = "abstraction")]
use tss_esapi::{
abstraction::{cipher::Cipher, pcr::PcrData},
interface_types::{reserved_handles::Hierarchy, session_handles::PolicySession},
};

mod marshall;
#[cfg(feature = "serde")]
mod serde;
Expand Down Expand Up @@ -231,6 +234,7 @@ pub fn create_ctx_with_session() -> Context {
ctx
}

#[cfg(feature = "abstraction")]
#[allow(dead_code)]
pub fn decryption_key_pub() -> Public {
utils::create_restricted_decryption_rsa_public(
Expand Down Expand Up @@ -263,6 +267,7 @@ pub fn signing_key_pub() -> Public {
.expect("Failed to create an unrestricted signing rsa public structure")
}

#[cfg(feature = "abstraction")]
#[allow(dead_code)]
pub fn get_pcr_policy_digest(
context: &mut Context,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
use crate::common::{create_ctx_with_session, create_ctx_without_session, decryption_key_pub};
use crate::common::create_ctx_without_session;

#[cfg(feature = "abstraction")]
use crate::common::{create_ctx_with_session, decryption_key_pub};

use tss_esapi::{
attributes::NvIndexAttributesBuilder,
constants::{tss::TPM2_NV_INDEX_FIRST, CapabilityType},
handles::{NvIndexHandle, NvIndexTpmHandle, ObjectHandle, PersistentTpmHandle, TpmHandle},
handles::{NvIndexHandle, NvIndexTpmHandle, ObjectHandle},
interface_types::{
algorithm::HashingAlgorithm,
data_handles::Persistent,
reserved_handles::{Hierarchy, NvAuth, Provision},
reserved_handles::{NvAuth, Provision},
session_handles::AuthSession,
},
structures::{Auth, CapabilityData, MaxNvBuffer, NvPublicBuilder},
tss2_esys::TPM2_HANDLE,
Context, Error,
Context,
};

#[cfg(feature = "abstraction")]
use tss_esapi::{
handles::{PersistentTpmHandle, TpmHandle},
interface_types::{data_handles::Persistent, reserved_handles::Hierarchy},
structures::{Auth, CapabilityData, MaxNvBuffer, NvPublicBuilder},
tss2_esys::TPM2_HANDLE,
Error,
};

use std::convert::TryFrom;
Expand Down Expand Up @@ -449,6 +461,7 @@ mod test_tr_from_tpm_public {
}
}

#[cfg(feature = "abstraction")]
mod test_tr_serialize_tr_deserialize {
use super::*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
mod test_quote {
use crate::common::{create_ctx_with_session, decryption_key_pub, signing_key_pub};
use crate::common::{create_ctx_with_session, signing_key_pub};

#[cfg(feature = "abstraction")]
use crate::common::decryption_key_pub;

use std::convert::TryFrom;
use tss_esapi::{
constants::StructureTag,
handles::KeyHandle,
interface_types::{
algorithm::{HashingAlgorithm, SignatureSchemeAlgorithm},
reserved_handles::Hierarchy,
session_handles::AuthSession,
algorithm::HashingAlgorithm, reserved_handles::Hierarchy,
structure_tags::AttestationType,
},
structures::{
AttestInfo, Data, HashScheme, MaxBuffer, PcrSelectionListBuilder, PcrSlot,
SignatureScheme, Ticket,
},
structures::{AttestInfo, Data, PcrSelectionListBuilder, PcrSlot, SignatureScheme},
};

#[cfg(feature = "abstraction")]
use tss_esapi::{
constants::StructureTag,
handles::KeyHandle,
interface_types::{algorithm::SignatureSchemeAlgorithm, session_handles::AuthSession},
structures::{HashScheme, MaxBuffer, Ticket},
traits::Marshall,
};

Expand Down Expand Up @@ -65,6 +70,7 @@ mod test_quote {
}
}

#[cfg(feature = "abstraction")]
#[test]
fn certify() {
let mut context = create_ctx_with_session();
Expand Down Expand Up @@ -126,6 +132,7 @@ mod test_quote {
assert_eq!(attest.extra_data().as_bytes(), qualifying_data);
}

#[cfg(feature = "abstraction")]
#[test]
fn certify_null() {
let mut context = create_ctx_with_session();
Expand Down Expand Up @@ -167,6 +174,7 @@ mod test_quote {
assert_eq!(signature.algorithm(), SignatureSchemeAlgorithm::Null);
}

#[cfg(feature = "abstraction")]
#[test]
fn certify_creation() {
let mut context = create_ctx_with_session();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
mod test_ctx_save {
use crate::common::{create_ctx_with_session, decryption_key_pub, signing_key_pub};
use crate::common::{create_ctx_with_session, signing_key_pub};

#[cfg(feature = "abstraction")]
use crate::common::decryption_key_pub;

use tss_esapi::{interface_types::reserved_handles::Hierarchy, structures::Auth};

#[test]
Expand All @@ -25,6 +29,7 @@ mod test_ctx_save {
let _ = context.context_save(key_handle.into()).unwrap();
}

#[cfg(feature = "abstraction")]
#[test]
fn test_ctx_save_leaf() {
let mut context = create_ctx_with_session();
Expand Down Expand Up @@ -63,6 +68,7 @@ mod test_ctx_save {
}
}

#[cfg(feature = "abstraction")]
mod test_ctx_load {
use crate::common::{create_ctx_with_session, decryption_key_pub, signing_key_pub};
use tss_esapi::{
Expand Down Expand Up @@ -109,7 +115,11 @@ mod test_ctx_load {
}

mod test_flush_context {
use crate::common::{create_ctx_with_session, decryption_key_pub, signing_key_pub};
use crate::common::{create_ctx_with_session, signing_key_pub};

#[cfg(feature = "abstraction")]
use crate::common::decryption_key_pub;

use tss_esapi::{interface_types::reserved_handles::Hierarchy, structures::Auth};

#[test]
Expand All @@ -134,6 +144,7 @@ mod test_flush_context {
assert!(context.read_public(key_handle).is_err());
}

#[cfg(feature = "abstraction")]
#[test]
fn test_flush_parent_ctx() {
let mut context = create_ctx_with_session();
Expand Down Expand Up @@ -172,6 +183,7 @@ mod test_flush_context {
}
}

#[cfg(feature = "abstraction")]
mod test_evict_control {
use crate::common::{create_ctx_without_session, decryption_key_pub};
use std::convert::TryFrom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ mod test_policy_secret {
}
}

#[cfg(feature = "abstraction")]
mod test_policy_or {
use crate::common::{create_ctx_without_session, get_pcr_policy_digest};
use std::convert::TryFrom;
Expand Down Expand Up @@ -190,6 +191,7 @@ mod test_policy_or {
}
}

#[cfg(feature = "abstraction")]
mod test_policy_pcr {
use crate::common::create_ctx_without_session;
use std::convert::TryFrom;
Expand Down Expand Up @@ -525,6 +527,7 @@ mod test_policy_name_hash {
}
}

#[cfg(feature = "abstraction")]
mod test_policy_authorize {
use crate::common::{create_ctx_with_session, get_pcr_policy_digest, signing_key_pub};
use std::convert::TryFrom;
Expand Down Expand Up @@ -675,6 +678,7 @@ mod test_policy_password {
}
}

#[cfg(feature = "abstraction")]
mod test_policy_get_digest {
use crate::common::create_ctx_without_session;
use std::convert::TryFrom;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
#[cfg(feature = "abstraction")]
mod test_create_primary {
use crate::common::{create_ctx_with_session, decryption_key_pub};
use tss_esapi::{
Expand Down Expand Up @@ -56,13 +57,16 @@ mod test_clear_control {
}

mod test_change_auth {
use crate::common::{create_ctx_with_session, decryption_key_pub};
use tss_esapi::{
handles::AuthHandle, interface_types::reserved_handles::Hierarchy, structures::Auth,
};
use crate::common::create_ctx_with_session;

use tss_esapi::{handles::AuthHandle, structures::Auth};

#[cfg(feature = "abstraction")]
#[test]
fn test_object_change_auth() {
use crate::common::decryption_key_pub;
use tss_esapi::interface_types::reserved_handles::Hierarchy;

let mut context = create_ctx_with_session();

let prim_key_handle = context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
#[cfg(feature = "abstraction")]
mod test_pcr_extend_reset {
use crate::common::create_ctx_with_session;
use std::convert::TryFrom;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
#[cfg(feature = "abstraction")]
mod test_create {
use crate::common::{create_ctx_with_session, decryption_key_pub};
use tss_esapi::{interface_types::reserved_handles::Hierarchy, structures::Auth};
Expand Down Expand Up @@ -36,6 +37,7 @@ mod test_create {
}
}

#[cfg(feature = "abstraction")]
mod test_load {
use crate::common::{create_ctx_with_session, decryption_key_pub, signing_key_pub};
use tss_esapi::{interface_types::reserved_handles::Hierarchy, structures::Auth};
Expand Down Expand Up @@ -256,6 +258,7 @@ mod test_read_public {
}
}

#[cfg(feature = "abstraction")]
mod test_make_credential {
use crate::common::{create_ctx_with_session, decryption_key_pub};
use std::convert::TryInto;
Expand Down Expand Up @@ -289,6 +292,7 @@ mod test_make_credential {
}
}

#[cfg(feature = "abstraction")]
mod test_activate_credential {
use crate::common::{create_ctx_with_session, decryption_key_pub};
use std::convert::{TryFrom, TryInto};
Expand Down Expand Up @@ -374,6 +378,7 @@ mod test_activate_credential {
}
}

#[cfg(feature = "abstraction")]
mod test_unseal {
use crate::common::{create_ctx_with_session, create_public_sealed_object, decryption_key_pub};
use std::convert::TryFrom;
Expand Down
Loading

0 comments on commit cb605c1

Please sign in to comment.