From ab1db2a021bc1df8434535b8d266f3e24469881e Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 28 Jun 2024 18:56:05 +0200 Subject: [PATCH] refactor: name error more precisely --- src/tpm2.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tpm2.rs b/src/tpm2.rs index 993f027..ef79bef 100644 --- a/src/tpm2.rs +++ b/src/tpm2.rs @@ -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 { 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); } }