Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Firstyear committed Apr 3, 2024
1 parent 4970426 commit 2d859d9
Showing 1 changed file with 11 additions and 64 deletions.
75 changes: 11 additions & 64 deletions tss-esapi/examples/duplication.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Contributors to the Parsec project.
// Copyright 2024 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0

/*
Expand Down Expand Up @@ -58,7 +58,7 @@ use tss_esapi::{
algorithm::{HashingAlgorithm, PublicAlgorithm},
ecc::EccCurve,
key_bits::RsaKeyBits,
resource_handles::Hierarchy,
reserved_handles::Hierarchy,
session_handles::PolicySession,
},
structures::{
Expand Down Expand Up @@ -148,21 +148,16 @@ fn main() {
let policy_session = PolicySession::try_from(trial_session)
.expect("Failed to convert auth session into policy session");

ctx.policy_auth_value(policy_session)
.expect("Policy auth value");

ctx.policy_command_code(policy_session, CommandCode::Duplicate)
.expect("Policy command code");

/*
ctx.policy_duplication_select(
policy_session,
Vec::<u8>::new().try_into().unwrap(),
target_parent_name.clone(),
false,
)
.expect("Policy duplication select");
*/

ctx.policy_get_digest(policy_session)
})
Expand All @@ -181,25 +176,6 @@ fn main() {
.build()
.expect("Attributes to be valid");

/*
let storage_public = PublicBuilder::new()
.with_public_algorithm(PublicAlgorithm::Rsa)
.with_name_hashing_algorithm(HashingAlgorithm::Sha256)
.with_object_attributes(object_attributes)
.with_rsa_parameters(
PublicRsaParametersBuilder::new_restricted_decryption_key(
SymmetricDefinitionObject::AES_128_CFB,
RsaKeyBits::Rsa2048,
RsaExponent::default(),
)
.build()
.expect("Params to be valid"),
)
.with_rsa_unique_identifier(PublicKeyRsa::default())
.build()
.expect("public to be valid");
*/

let storage_public = PublicBuilder::new()
.with_public_algorithm(PublicAlgorithm::Ecc)
.with_name_hashing_algorithm(HashingAlgorithm::Sha256)
Expand Down Expand Up @@ -335,22 +311,16 @@ fn main() {
let policy_session = PolicySession::try_from(policy_auth_session)
.expect("Failed to convert auth session into policy session");

ctx.policy_auth_value(policy_session)
.expect("Policy auth value");

ctx.policy_command_code(policy_session, CommandCode::Duplicate)
.expect("Policy command code");
//.map(|_| policy_auth_session)

/*
ctx.policy_duplication_select(
policy_session,
object_to_duplicate_name,
target_parent_name,
false,
)
.map(|_| policy_auth_session)
*/
.expect("Policy duplication select");

ctx.set_sessions((Some(policy_auth_session), None, None));

Expand Down Expand Up @@ -404,27 +374,23 @@ fn main() {

let hmac2 = context_2
.execute_with_nullauth_session(|ctx| {
let loaded_hmackey = ctx.load(
loaded_storage_key_2,
hmac_key.out_private.clone(),
hmac_key.out_public.clone(),
).unwrap();
let loaded_hmackey = ctx
.load(
loaded_storage_key_2,
hmac_key.out_private.clone(),
hmac_key.out_public.clone(),
)
.unwrap();

ctx.execute_with_temporary_object(loaded_hmackey.into(), |ctx, handle| {
ctx.hmac(
handle.into(),
input_data.clone(),
HashingAlgorithm::Sha256,
)
ctx.hmac(handle.into(), input_data.clone(), HashingAlgorithm::Sha256)
})
})
.unwrap();

assert_eq!(hmac1, hmac2);
}

// TODO: Is there a way to add entropy or randomness here so that the created primary keys
// are not the same?
fn create_primary_key(context: &mut Context) -> CreatePrimaryKeyResult {
context
.execute_with_nullauth_session(|ctx| {
Expand All @@ -440,25 +406,6 @@ fn create_primary_key(context: &mut Context) -> CreatePrimaryKeyResult {
.build()
.expect("Attributes to be valid");

/*
let public = PublicBuilder::new()
.with_public_algorithm(PublicAlgorithm::Rsa)
.with_name_hashing_algorithm(HashingAlgorithm::Sha256)
.with_object_attributes(object_attributes)
.with_rsa_parameters(
PublicRsaParametersBuilder::new_restricted_decryption_key(
SymmetricDefinitionObject::AES_128_CFB,
RsaKeyBits::Rsa2048,
RsaExponent::default(),
)
.build()
.expect("Params to be valid"),
)
.with_rsa_unique_identifier(PublicKeyRsa::default())
.build()
.expect("public to be valid");
*/

let public = PublicBuilder::new()
.with_public_algorithm(PublicAlgorithm::Ecc)
.with_name_hashing_algorithm(HashingAlgorithm::Sha256)
Expand Down

0 comments on commit 2d859d9

Please sign in to comment.