From 4547118bac407aa5d0942bf4b9c8c73952dcdb46 Mon Sep 17 00:00:00 2001 From: Marshall Pierce Date: Thu, 24 Sep 2020 16:11:30 -0600 Subject: [PATCH] Add a note for InvalidLength explaining that trailing whitespace is a common cause --- src/decode.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/decode.rs b/src/decode.rs index 716fce73..20848a02 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -29,6 +29,7 @@ pub enum DecodeError { /// An invalid byte was found in the input. The offset and offending byte are provided. InvalidByte(usize, u8), /// The length of the input is invalid. + /// A typical cause of this is stray trailing whitespace or other separator bytes. InvalidLength, /// The last non-padding input symbol's encoded 6 bits have nonzero bits that will be discarded. /// This is indicative of corrupted or truncated Base64. @@ -43,7 +44,7 @@ impl fmt::Display for DecodeError { DecodeError::InvalidByte(index, byte) => { write!(f, "Invalid byte {}, offset {}.", byte, index) } - DecodeError::InvalidLength => write!(f, "Encoded text cannot have a 6-bit remainder."), + DecodeError::InvalidLength => write!(f, "Encoded text cannot have a 6-bit remainder. Trailing whitespace or other bytes?"), DecodeError::InvalidLastSymbol(index, byte) => { write!(f, "Invalid last symbol {}, offset {}.", byte, index) }