Skip to content

Commit

Permalink
Remove DpeInstance::new_for_test and use DpeInstance::New
Browse files Browse the repository at this point in the history
  • Loading branch information
willyzha committed Aug 8, 2023
1 parent e964ab5 commit 3098b97
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 36 deletions.
4 changes: 2 additions & 2 deletions dpe/src/commands/certify_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(
let mut dpe = DpeInstance::new(
&mut env,
Support {
x509: true,
Expand Down Expand Up @@ -244,7 +244,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(
let mut dpe = DpeInstance::new(
&mut env,
Support {
x509: true,
Expand Down
12 changes: 6 additions & 6 deletions dpe/src/commands/derive_child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(&mut env, Support::default()).unwrap();
let mut dpe = DpeInstance::new(&mut env, Support::default()).unwrap();

InitCtxCmd::new_use_default()
.execute(&mut dpe, &mut env, 0)
Expand All @@ -229,7 +229,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(
let mut dpe = DpeInstance::new(
&mut env,
Support {
auto_init: true,
Expand Down Expand Up @@ -271,7 +271,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(
let mut dpe = DpeInstance::new(
&mut env,
Support {
auto_init: true,
Expand Down Expand Up @@ -312,7 +312,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(
let mut dpe = DpeInstance::new(
&mut env,
Support {
auto_init: true,
Expand Down Expand Up @@ -346,7 +346,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(
let mut dpe = DpeInstance::new(
&mut env,
Support {
auto_init: true,
Expand Down Expand Up @@ -396,7 +396,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(
let mut dpe = DpeInstance::new(
&mut env,
Support {
auto_init: true,
Expand Down
2 changes: 1 addition & 1 deletion dpe/src/commands/extend_tci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(&mut env, Support::default()).unwrap();
let mut dpe = DpeInstance::new(&mut env, Support::default()).unwrap();
// Make sure it returns an error if the command is marked unsupported.
assert_eq!(
Err(DpeErrorCode::InvalidCommand),
Expand Down
2 changes: 1 addition & 1 deletion dpe/src/commands/get_certificate_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(&mut env, SUPPORT).unwrap();
let mut dpe = DpeInstance::new(&mut env, SUPPORT).unwrap();

assert_eq!(
Err(DpeErrorCode::InvalidArgument),
Expand Down
4 changes: 2 additions & 2 deletions dpe/src/commands/initialize_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(&mut env, Support::default()).unwrap();
let mut dpe = DpeInstance::new(&mut env, Support::default()).unwrap();

let handle = match InitCtxCmd::new_use_default()
.execute(&mut dpe, &mut env, TEST_LOCALITIES[0])
Expand Down Expand Up @@ -151,7 +151,7 @@ mod tests {
);

// Change to support simulation.
let mut dpe = DpeInstance::new_for_test(
let mut dpe = DpeInstance::new(
&mut env,
Support {
simulation: true,
Expand Down
4 changes: 2 additions & 2 deletions dpe/src/commands/rotate_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(&mut env, Support::default()).unwrap();
let mut dpe = DpeInstance::new(&mut env, Support::default()).unwrap();
// Make sure it returns an error if the command is marked unsupported.
assert_eq!(
Err(DpeErrorCode::InvalidCommand),
Expand All @@ -106,7 +106,7 @@ mod tests {
);

// Make a new instance that supports RotateContext.
let mut dpe = DpeInstance::new_for_test(
let mut dpe = DpeInstance::new(
&mut env,
Support {
rotate_context: true,
Expand Down
6 changes: 3 additions & 3 deletions dpe/src/commands/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(&mut env, SUPPORT).unwrap();
let mut dpe = DpeInstance::new(&mut env, SUPPORT).unwrap();

// Bad argument
assert_eq!(
Expand Down Expand Up @@ -247,7 +247,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(&mut env, SUPPORT).unwrap();
let mut dpe = DpeInstance::new(&mut env, SUPPORT).unwrap();

for i in 0..3 {
DeriveChildCmd {
Expand Down Expand Up @@ -306,7 +306,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(
let mut dpe = DpeInstance::new(
&mut env,
Support {
auto_init: true,
Expand Down
4 changes: 2 additions & 2 deletions dpe/src/commands/tag_tci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(&mut env, Support::default()).unwrap();
let mut dpe = DpeInstance::new(&mut env, Support::default()).unwrap();
// Make sure it returns an error if the command is marked unsupported.
assert_eq!(
Err(DpeErrorCode::InvalidCommand),
Expand All @@ -96,7 +96,7 @@ mod tests {
);

// Make a new instance that supports tagging.
let mut dpe = DpeInstance::new_for_test(
let mut dpe = DpeInstance::new(
&mut env,
Support {
tagging: true,
Expand Down
23 changes: 8 additions & 15 deletions dpe/src/dpe_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ impl DpeInstance {
Ok(dpe)
}

pub fn new_for_test(
env: &mut DpeEnv<impl DpeTypes>,
support: Support,
) -> Result<DpeInstance, DpeErrorCode> {
Self::new(env, support)
}

pub fn get_profile(
&self,
platform: &mut impl Platform,
Expand Down Expand Up @@ -424,7 +417,7 @@ pub mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(&mut env, SUPPORT).unwrap();
let mut dpe = DpeInstance::new(&mut env, SUPPORT).unwrap();

assert_eq!(
Response::GetProfile(GetProfileResp::new(
Expand Down Expand Up @@ -462,7 +455,7 @@ pub mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let dpe = DpeInstance::new_for_test(&mut env, SUPPORT).unwrap();
let dpe = DpeInstance::new(&mut env, SUPPORT).unwrap();
let profile = dpe.get_profile(&mut env.platform).unwrap();
assert_eq!(profile.major_version, CURRENT_PROFILE_MAJOR_VERSION);
assert_eq!(profile.flags, SUPPORT.get_flags());
Expand All @@ -474,7 +467,7 @@ pub mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(&mut env, Support::default()).unwrap();
let mut dpe = DpeInstance::new(&mut env, Support::default()).unwrap();
let expected_index = 7;
dpe.contexts[expected_index].handle = SIMULATION_HANDLE;

Expand Down Expand Up @@ -512,7 +505,7 @@ pub mod tests {
platform: DefaultPlatform,
};

let mut dpe = DpeInstance::new_for_test(
let mut dpe = DpeInstance::new(
&mut env,
Support {
auto_init: true,
Expand Down Expand Up @@ -569,7 +562,7 @@ pub mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(&mut env, Support::default()).unwrap();
let mut dpe = DpeInstance::new(&mut env, Support::default()).unwrap();
let root = 7;
let child_1 = 3;
let child_1_1 = 0;
Expand Down Expand Up @@ -624,7 +617,7 @@ pub mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(&mut env, SUPPORT).unwrap();
let mut dpe = DpeInstance::new(&mut env, SUPPORT).unwrap();

let mut last_cdi = vec![];

Expand Down Expand Up @@ -679,7 +672,7 @@ pub mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(
let mut dpe = DpeInstance::new(
&mut env,
Support {
internal_info: true,
Expand Down Expand Up @@ -736,7 +729,7 @@ pub mod tests {
crypto: OpensslCrypto::new(),
platform: DefaultPlatform,
};
let mut dpe = DpeInstance::new_for_test(
let mut dpe = DpeInstance::new(
&mut env,
Support {
internal_dice: true,
Expand Down
2 changes: 1 addition & 1 deletion simulator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn main() -> std::io::Result<()> {
platform: DefaultPlatform,
};

let mut dpe = DpeInstance::new_for_test(&mut env, support).map_err(|err| {
let mut dpe = DpeInstance::new(&mut env, support).map_err(|err| {
Error::new(
ErrorKind::Other,
format!("{err:?} while creating new DPE instance"),
Expand Down
2 changes: 1 addition & 1 deletion tools/src/sample_dpe_cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn main() {
der = fs::read(file).unwrap();
DpeInstance::new(&mut env, support, &der).unwrap()
}
None => DpeInstance::new_for_test(&mut env, support).unwrap(),
None => DpeInstance::new(&mut env, support).unwrap(),
};

let certify_key_cmd: CertifyKeyCmd = commands::CertifyKeyCmd {
Expand Down

0 comments on commit 3098b97

Please sign in to comment.