diff --git a/tss-esapi/src/constants/command_code.rs b/tss-esapi/src/constants/command_code.rs index 41c11bf1..fb2b072b 100644 --- a/tss-esapi/src/constants/command_code.rs +++ b/tss-esapi/src/constants/command_code.rs @@ -158,23 +158,6 @@ impl From for TPM2_CC { impl Marshall for CommandCode { const BUFFER_SIZE: usize = std::mem::size_of::(); - /// Produce a marshalled [TPM2_CC] - fn marshall(&self) -> Result> { - let mut buffer = vec![0; Self::BUFFER_SIZE]; - let mut offset = 0; - - self.marshall_offset(&mut buffer, &mut offset)?; - - let checked_offset = usize::try_from(offset).map_err(|e| { - error!("Failed to parse offset as usize: {}", e); - Error::local_error(WrapperErrorKind::InvalidParam) - })?; - - buffer.truncate(checked_offset); - - Ok(buffer) - } - fn marshall_offset( &self, marshalled_data: &mut [u8], @@ -201,11 +184,6 @@ impl Marshall for CommandCode { } impl UnMarshall for CommandCode { - /// Unmarshall the structure from [`TPM2_CC`] - fn unmarshall(marshalled_data: &[u8]) -> Result { - CommandCode::unmarshall_offset(marshalled_data, &mut 0) - } - fn unmarshall_offset( marshalled_data: &[u8], offset: &mut std::os::raw::c_ulong, diff --git a/tss-esapi/src/interface_types/structure_tags.rs b/tss-esapi/src/interface_types/structure_tags.rs index 5553c34c..0f28d587 100644 --- a/tss-esapi/src/interface_types/structure_tags.rs +++ b/tss-esapi/src/interface_types/structure_tags.rs @@ -78,23 +78,6 @@ impl TryFrom for AttestationType { impl Marshall for AttestationType { const BUFFER_SIZE: usize = std::mem::size_of::(); - /// Produce a marshalled [`TPMI_ST_ATTEST`] - fn marshall(&self) -> Result> { - let mut buffer = vec![0; Self::BUFFER_SIZE]; - let mut offset = 0; - - self.marshall_offset(&mut buffer, &mut offset)?; - - let checked_offset = usize::try_from(offset).map_err(|e| { - error!("Failed to parse offset as usize: {}", e); - Error::local_error(WrapperErrorKind::InvalidParam) - })?; - - buffer.truncate(checked_offset); - - Ok(buffer) - } - fn marshall_offset( &self, marshalled_data: &mut [u8], @@ -122,11 +105,6 @@ impl Marshall for AttestationType { } impl UnMarshall for AttestationType { - /// Unmarshall the structure from [`TPMI_ST_ATTEST`] - fn unmarshall(marshalled_data: &[u8]) -> Result { - AttestationType::unmarshall_offset(marshalled_data, &mut 0) - } - fn unmarshall_offset( marshalled_data: &[u8], offset: &mut std::os::raw::c_ulong, @@ -200,23 +178,6 @@ impl TryFrom for CommandTag { impl Marshall for CommandTag { const BUFFER_SIZE: usize = std::mem::size_of::(); - /// Produce a marshalled [`TPMI_ST_COMMAND_TAG`] - fn marshall(&self) -> Result> { - let mut buffer = vec![0; Self::BUFFER_SIZE]; - let mut offset = 0; - - self.marshall_offset(&mut buffer, &mut offset)?; - - let checked_offset = usize::try_from(offset).map_err(|e| { - error!("Failed to parse offset as usize: {}", e); - Error::local_error(WrapperErrorKind::InvalidParam) - })?; - - buffer.truncate(checked_offset); - - Ok(buffer) - } - fn marshall_offset( &self, marshalled_data: &mut [u8], @@ -244,11 +205,6 @@ impl Marshall for CommandTag { } impl UnMarshall for CommandTag { - /// Unmarshall the structure from [`TPMI_ST_COMMAND_TAG`] - fn unmarshall(marshalled_data: &[u8]) -> Result { - CommandTag::unmarshall_offset(marshalled_data, &mut 0) - } - fn unmarshall_offset( marshalled_data: &[u8], offset: &mut std::os::raw::c_ulong, diff --git a/tss-esapi/src/traits.rs b/tss-esapi/src/traits.rs index 7c877917..1e5b4a04 100644 --- a/tss-esapi/src/traits.rs +++ b/tss-esapi/src/traits.rs @@ -12,7 +12,21 @@ use crate::{Error, Result, ReturnCode, WrapperErrorKind}; pub trait Marshall: Sized { const BUFFER_SIZE: usize; /// Returns the type in the form of marshalled data - fn marshall(&self) -> Result>; + fn marshall(&self) -> Result> { + let mut buffer = vec![0; Self::BUFFER_SIZE]; + let mut offset = 0; + + self.marshall_offset(&mut buffer, &mut offset)?; + + let checked_offset = usize::try_from(offset).map_err(|e| { + error!("Failed to parse offset as usize: {}", e); + Error::local_error(WrapperErrorKind::InvalidParam) + })?; + + buffer.truncate(checked_offset); + + Ok(buffer) + } /// Writes the type in the form of marshalled data to `marshalled_data`, /// and modifies the `offset` to point to the first byte in the buffer @@ -30,7 +44,9 @@ pub trait Marshall: Sized { /// TPM marshalled data. pub trait UnMarshall: Sized { /// Creates the type from marshalled data. - fn unmarshall(marshalled_data: &[u8]) -> Result; + fn unmarshall(marshalled_data: &[u8]) -> Result { + Self::unmarshall_offset(marshalled_data, &mut 0) + } /// Creates the type from the marshalled data, and modifies /// the `offset` to point to the first byte in the `marshalled_data` @@ -46,23 +62,6 @@ pub trait UnMarshall: Sized { impl Marshall for u32 { const BUFFER_SIZE: usize = std::mem::size_of::(); - /// Produce a marshalled [UINT32] - fn marshall(&self) -> Result> { - let mut buffer = vec![0; Self::BUFFER_SIZE]; - let mut offset = 0; - - self.marshall_offset(&mut buffer, &mut offset)?; - - let checked_offset = usize::try_from(offset).map_err(|e| { - error!("Failed to parse offset as usize: {}", e); - Error::local_error(WrapperErrorKind::InvalidParam) - })?; - - buffer.truncate(checked_offset); - - Ok(buffer) - } - fn marshall_offset( &self, marshalled_data: &mut [u8], @@ -90,10 +89,6 @@ impl Marshall for u32 { } impl UnMarshall for u32 { - fn unmarshall(marshalled_data: &[u8]) -> Result { - u32::unmarshall_offset(marshalled_data, &mut 0) - } - fn unmarshall_offset( marshalled_data: &[u8], offset: &mut std::os::raw::c_ulong,