diff --git a/src/protocol/src/report_status/command.rs b/src/protocol/src/report_status/command.rs index fe72420..655decc 100644 --- a/src/protocol/src/report_status/command.rs +++ b/src/protocol/src/report_status/command.rs @@ -21,7 +21,7 @@ pub(crate) mod field { pub const COMMAND: usize = 1; pub const OPERATION: usize = 2; pub const STATUS: usize = 3; - pub const TDVM_ID: Field = 4..20; + pub const TPM_ID: Field = 4..20; pub const DATA: Rest = 20..; } @@ -54,9 +54,9 @@ impl + AsMut<[u8]>> Packet { let buf = self.buffer.as_mut(); buf[field::STATUS] = value; } - pub fn set_tdvm_id(&mut self, vtpm_id: u128) { + pub fn set_tpm_id(&mut self, vtpm_id: u128) { let buf = self.buffer.as_mut(); - LittleEndian::write_u128(&mut buf[field::TDVM_ID], vtpm_id); + LittleEndian::write_u128(&mut buf[field::TPM_ID], vtpm_id); } pub fn set_data(&mut self, data: &[u8]) -> VtpmResult { let buf = self.buffer.as_mut(); @@ -107,7 +107,7 @@ pub fn build_command( packet.set_version(DEFAULT_VERSION); packet.set_command(COMMAND_REPORT_STATUS); packet.set_status(status); - packet.set_tdvm_id(vtpm_id); + packet.set_tpm_id(vtpm_id); packet.set_operation(operation); let mut data_len = 0; if data_buffer_len != 0 { @@ -137,7 +137,7 @@ mod test { packet.set_version(version); packet.set_command(command); packet.set_status(status); - packet.set_tdvm_id(vtpm_id); + packet.set_tpm_id(vtpm_id); packet.set_operation(operation); let data_len = packet.set_data(&data); assert_eq!(data_len.unwrap(), data.len()); @@ -153,10 +153,7 @@ mod test { let invalid_data = [1u8; INVALID_DATA_SIZE]; let res = packet.set_data(&invalid_data); assert!(res.is_err()); - assert_eq!( - LittleEndian::read_u128(&mut buffer[field::TDVM_ID]), - vtpm_id - ); + assert_eq!(LittleEndian::read_u128(&mut buffer[field::TPM_ID]), vtpm_id); } #[test] @@ -170,10 +167,7 @@ mod test { assert_eq!(res.unwrap(), data.len() + HEADER_LEN); assert_eq!(buffer[field::STATUS], status); assert_eq!(buffer[field::OPERATION], operation); - assert_eq!( - LittleEndian::read_u128(&mut buffer[field::TDVM_ID]), - vtpm_id - ); + assert_eq!(LittleEndian::read_u128(&mut buffer[field::TPM_ID]), vtpm_id); assert_eq!(buffer[field::DATA][0..data.len()], data); } diff --git a/src/protocol/src/report_status/response.rs b/src/protocol/src/report_status/response.rs index 9a4ad18..b947872 100644 --- a/src/protocol/src/report_status/response.rs +++ b/src/protocol/src/report_status/response.rs @@ -22,7 +22,7 @@ pub(crate) mod field { pub const RESERVED: Field = 2..4; } -// pub const HEADER_LEN: usize = field::TDVM_ID.end; +// pub const HEADER_LEN: usize = field::TPM_ID.end; pub const HEADER_LEN: usize = field::RESERVED.end; /// Packet manage a buffer for protocol. diff --git a/src/protocol/src/wait_for_request/command.rs b/src/protocol/src/wait_for_request/command.rs index 9ff2112..4574acf 100644 --- a/src/protocol/src/wait_for_request/command.rs +++ b/src/protocol/src/wait_for_request/command.rs @@ -19,10 +19,10 @@ pub(crate) mod field { pub const VERSION: usize = 0; pub const COMMAND: usize = 1; pub const RESERVED: Field = 2..4; - pub const TDVM_ID: Field = 4..20; + pub const TPM_ID: Field = 4..20; } -pub const HEADER_LEN: usize = field::TDVM_ID.end; +pub const HEADER_LEN: usize = field::TPM_ID.end; /// Packet manage a buffer for protocol. pub struct Packet> { buffer: T, @@ -43,9 +43,9 @@ impl + AsMut<[u8]>> Packet { let buf = self.buffer.as_mut(); buf[field::COMMAND] = value; } - pub fn set_tdvm_id(&mut self, vtpm_id: u128) { + pub fn set_tpm_id(&mut self, vtpm_id: u128) { let buf = self.buffer.as_mut(); - LittleEndian::write_u128(&mut buf[field::TDVM_ID], vtpm_id); + LittleEndian::write_u128(&mut buf[field::TPM_ID], vtpm_id); } } @@ -77,7 +77,7 @@ pub fn build_command_header(data_buffer: &mut [u8], vtpm_id: u128) -> VtpmResult let mut packet = Packet::new_unchecked(data_buffer); packet.set_version(DEFAULT_VERSION); packet.set_command(COMMAND_WAIT_FOR_REQUEST); - packet.set_tdvm_id(vtpm_id); + packet.set_tpm_id(vtpm_id); Ok(HEADER_LEN) } @@ -98,14 +98,14 @@ mod test { let mut packet = Packet::new_unchecked(&mut data_buffer); packet.set_version(version); packet.set_command(command); - packet.set_tdvm_id(vtpm_id); + packet.set_tpm_id(vtpm_id); assert_eq!(packet.as_ref()[field::VERSION], version); let version_2 = 1; packet.as_mut()[field::VERSION] = version_2; assert_eq!(version_2, packet.as_ref()[field::VERSION]); assert_eq!(data_buffer[field::COMMAND], command); assert_eq!( - LittleEndian::read_u128(&data_buffer[field::TDVM_ID]), + LittleEndian::read_u128(&data_buffer[field::TPM_ID]), vtpm_id ); } @@ -116,10 +116,7 @@ mod test { let vtpmid = 101 as u128; let res = build_command_header(&mut data_buffer, vtpmid); assert_eq!(res.unwrap(), HEADER_LEN); - assert_eq!( - LittleEndian::read_u128(&data_buffer[field::TDVM_ID]), - vtpmid - ); + assert_eq!(LittleEndian::read_u128(&data_buffer[field::TPM_ID]), vtpmid); } #[test] diff --git a/src/protocol/src/wait_for_request/response.rs b/src/protocol/src/wait_for_request/response.rs index 6022b68..1a3872c 100644 --- a/src/protocol/src/wait_for_request/response.rs +++ b/src/protocol/src/wait_for_request/response.rs @@ -21,7 +21,7 @@ pub(crate) mod field { pub const COMMAND: usize = 1; pub const OPERATION: usize = 2; pub const RESERVED: usize = 3; - pub const TDVM_ID: Field = 4..20; + pub const TPM_ID: Field = 4..20; pub const DATA: Rest = 20..; } @@ -38,7 +38,7 @@ impl> Packet { } pub fn vtpm_id(&self) -> u128 { let buf = self.as_ref(); - LittleEndian::read_u128(&buf[field::TDVM_ID]) + LittleEndian::read_u128(&buf[field::TPM_ID]) } pub fn version(&self) -> u8 { let buf = self.buffer.as_ref(); @@ -68,9 +68,9 @@ impl + AsMut<[u8]>> Packet { let buf = self.buffer.as_mut(); buf[field::COMMAND] = value; } - pub fn set_tdvm_id(&mut self, vtpm_id: u128) { + pub fn set_tpm_id(&mut self, vtpm_id: u128) { let buf = self.buffer.as_mut(); - LittleEndian::write_u128(&mut buf[field::TDVM_ID], vtpm_id); + LittleEndian::write_u128(&mut buf[field::TPM_ID], vtpm_id); } } @@ -106,7 +106,7 @@ pub fn build_response_header(data_buffer: &mut [u8], vtpm_id: u128) -> VtpmResul let mut packet = Packet::new_unchecked(data_buffer); packet.set_version(DEFAULT_VERSION); packet.set_command(COMMAND_WAIT_FOR_REQUEST); - packet.set_tdvm_id(vtpm_id); + packet.set_tpm_id(vtpm_id); Ok(data_buffer_len) } @@ -125,7 +125,7 @@ mod test { let mut packet = Packet::new_unchecked(&mut data_buffer); packet.set_version(version); packet.set_command(command); - packet.set_tdvm_id(vtpm_id); + packet.set_tpm_id(vtpm_id); assert_eq!(packet.version(), version); packet.as_mut()[field::VERSION] = 1; assert_eq!(packet.as_ref()[field::VERSION], 1); @@ -146,10 +146,7 @@ mod test { let vtpmid = 101 as u128; let res = build_response_header(&mut data_buffer, vtpmid); assert_eq!(res.unwrap(), data_buffer.len()); - assert_eq!( - LittleEndian::read_u128(&data_buffer[field::TDVM_ID]), - vtpmid - ); + assert_eq!(LittleEndian::read_u128(&data_buffer[field::TPM_ID]), vtpmid); } #[test] diff --git a/src/tdtunnel/src/td_tunnel.rs b/src/tdtunnel/src/td_tunnel.rs index 7553eb6..99aea72 100644 --- a/src/tdtunnel/src/td_tunnel.rs +++ b/src/tdtunnel/src/td_tunnel.rs @@ -191,7 +191,7 @@ impl TdVtpmEvent { self.operation } - pub fn get_tdvm_id(self) -> u128 { + pub fn get_tpm_id(self) -> u128 { self.vtpm_id } }