From 9d2678a0cca7c9d7347a0ae6efdca25942be61ca Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Wed, 20 Oct 2021 11:00:17 +0200 Subject: [PATCH] Add infallible conversion for Name and CreationData Signed-off-by: Wiktor Kwapisiewicz --- tss-esapi/src/structures/creation.rs | 13 ++++++------- tss-esapi/src/structures/names/name.rs | 6 ++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tss-esapi/src/structures/creation.rs b/tss-esapi/src/structures/creation.rs index 981cf1f2..8aa1f637 100644 --- a/tss-esapi/src/structures/creation.rs +++ b/tss-esapi/src/structures/creation.rs @@ -46,10 +46,9 @@ impl TryFrom for CreationData { } } -impl TryFrom for TPMS_CREATION_DATA { - type Error = Error; - fn try_from(creation_data: CreationData) -> Result { - Ok(TPMS_CREATION_DATA { +impl From for TPMS_CREATION_DATA { + fn from(creation_data: CreationData) -> Self { + TPMS_CREATION_DATA { pcrSelect: creation_data.pcr_select.into(), pcrDigest: creation_data.pcr_digest.into(), locality: creation_data.locality, @@ -57,9 +56,9 @@ impl TryFrom for TPMS_CREATION_DATA { None => AlgorithmIdentifier::Null.into(), Some(alg) => alg.into(), }, - parentName: *creation_data.parent_name.as_ref(), - parentQualifiedName: *creation_data.parent_qualified_name.as_ref(), + parentName: creation_data.parent_name.into(), + parentQualifiedName: creation_data.parent_qualified_name.into(), outsideInfo: creation_data.outside_info.into(), - }) + } } } diff --git a/tss-esapi/src/structures/names/name.rs b/tss-esapi/src/structures/names/name.rs index 5fcc18bf..54d05276 100644 --- a/tss-esapi/src/structures/names/name.rs +++ b/tss-esapi/src/structures/names/name.rs @@ -54,6 +54,12 @@ impl TryFrom for Name { } } +impl From for TPM2B_NAME { + fn from(name: Name) -> Self { + name.value + } +} + impl AsRef for Name { fn as_ref(&self) -> &TPM2B_NAME { &self.value