Skip to content

Commit

Permalink
rename TDVM_ID to TPM_ID
Browse files Browse the repository at this point in the history
Signed-off-by: Ceping Sun <cepingx.sun@intel.com>
  • Loading branch information
sunceping committed Sep 20, 2023
1 parent a2bd89a commit 9ca7d2b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 36 deletions.
20 changes: 7 additions & 13 deletions src/protocol/src/report_status/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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..;
}

Expand Down Expand Up @@ -54,9 +54,9 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T> {
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<usize> {
let buf = self.buffer.as_mut();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand All @@ -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]
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/protocol/src/report_status/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 8 additions & 11 deletions src/protocol/src/wait_for_request/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: AsRef<[u8]>> {
buffer: T,
Expand All @@ -43,9 +43,9 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T> {
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);
}
}

Expand Down Expand Up @@ -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)
}

Expand All @@ -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
);
}
Expand All @@ -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]
Expand Down
17 changes: 7 additions & 10 deletions src/protocol/src/wait_for_request/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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..;
}

Expand All @@ -38,7 +38,7 @@ impl<T: AsRef<[u8]>> Packet<T> {
}
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();
Expand Down Expand Up @@ -68,9 +68,9 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T> {
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);
}
}

Expand Down Expand Up @@ -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)
}

Expand All @@ -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);
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/tdtunnel/src/td_tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 9ca7d2b

Please sign in to comment.