refactor: name error more precisely
This commit is contained in:
parent
15af895a04
commit
ab1db2a021
|
@ -5,7 +5,7 @@ pub use crate::common::{PacketType, PACKET_END_BYTE};
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum Tpm2Error {
|
pub enum Tpm2Error {
|
||||||
InvalidPacket,
|
PayloadTooLarge,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Packet<'a> {
|
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> {
|
pub fn with_payload(packet_type: PacketType, payload: &'a [u8]) -> Result<Self, Tpm2Error> {
|
||||||
if payload.len() > u16::MAX.into() {
|
if payload.len() > u16::MAX.into() {
|
||||||
return Err(Tpm2Error::InvalidPacket);
|
return Err(Tpm2Error::PayloadTooLarge);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Packet {
|
Ok(Packet {
|
||||||
|
@ -63,6 +63,6 @@ mod tests {
|
||||||
let payload = [0u8; u16::MAX as usize + 1];
|
let payload = [0u8; u16::MAX as usize + 1];
|
||||||
let result = Packet::with_payload(PacketType::Response, &payload);
|
let result = Packet::with_payload(PacketType::Response, &payload);
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
assert!(result.err().unwrap() == Tpm2Error::InvalidPacket);
|
assert!(result.err().unwrap() == Tpm2Error::PayloadTooLarge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue