refactor: name error more precisely

This commit is contained in:
Luca 2024-06-28 18:56:05 +02:00
parent 15af895a04
commit ab1db2a021
1 changed files with 3 additions and 3 deletions

View File

@ -5,7 +5,7 @@ pub use crate::common::{PacketType, PACKET_END_BYTE};
#[derive(PartialEq)]
#[non_exhaustive]
pub enum Tpm2Error {
InvalidPacket,
PayloadTooLarge,
}
pub struct Packet<'a> {
@ -23,7 +23,7 @@ impl<'a> Packet<'a> {
pub fn with_payload(packet_type: PacketType, payload: &'a [u8]) -> Result<Self, Tpm2Error> {
if payload.len() > u16::MAX.into() {
return Err(Tpm2Error::InvalidPacket);
return Err(Tpm2Error::PayloadTooLarge);
}
Ok(Packet {
@ -63,6 +63,6 @@ mod tests {
let payload = [0u8; u16::MAX as usize + 1];
let result = Packet::with_payload(PacketType::Response, &payload);
assert!(result.is_err());
assert!(result.err().unwrap() == Tpm2Error::InvalidPacket);
assert!(result.err().unwrap() == Tpm2Error::PayloadTooLarge);
}
}