From e2dae292be70a4138e8bae6290c4022562ce1740 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 25 May 2021 20:58:01 +0200 Subject: [PATCH] Rename CanThisReallyOccur to InvalidSliceLength The CanThisReallyOccur error variant can really occur, namely if the slice length is invalid, i. e. either the encoded data length Lc is wrong, or the length values Lc and Le are not encoded properly. Therefore, this patch renames the CanThisReallyOccur variant to a more informative name. --- src/command.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/command.rs b/src/command.rs index ed99864..bde3bd1 100644 --- a/src/command.rs +++ b/src/command.rs @@ -74,7 +74,7 @@ pub enum FromSliceError { TooShort, InvalidClass, InvalidFirstBodyByteForExtended, - CanThisReallyOccur, + InvalidSliceLength, } impl From for FromSliceError { @@ -216,7 +216,11 @@ fn parse_lengths(body: &[u8]) -> Result { return Ok(parsed); } - Err(FromSliceError::CanThisReallyOccur) + // If we haven’t returned yet, the slice has an invalid length: Either the encoded lc value is + // wrong, or the lc and le lengths are not encoded properly (one byte per value for simple + // APDU, two bytes per value for extended APDU). + + Err(FromSliceError::InvalidSliceLength) } #[cfg(test)]